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

Print this page
rev 611 : Merge
   1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)collectorPolicy.hpp  1.41 07/05/29 09:44:14 JVM"
   3 #endif
   4 /*
   5  * Copyright 2001-2006 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 // This class (or more correctly, subtypes of this class)
  29 // are used to define global garbage collector attributes.
  30 // This includes initialization of generations and any other
  31 // shared resources they may need. 
  32 //
  33 // In general, all flag adjustment and validation should be
  34 // done in initialize_flags(), which is called prior to
  35 // initialize_size_info().
  36 //
  37 // This class is not fully developed yet. As more collector(s)
  38 // are added, it is expected that we will come across further
  39 // behavior that requires global attention. The correct place
  40 // to deal with those issues is this class. 
  41 
  42 // Forward declarations.
  43 class GenCollectorPolicy;
  44 class TwoGenerationCollectorPolicy;

  45 #ifndef SERIALGC
  46 class ConcurrentMarkSweepPolicy;

  47 #endif // SERIALGC
  48 class AdaptiveSizePolicy;
  49 class GCPolicyCounters;
  50 class PermanentGenerationSpec;
  51 class MarkSweepPolicy;
  52 
  53 class CollectorPolicy : public CHeapObj {
  54  protected:
  55   PermanentGenerationSpec *_permanent_generation;
  56   GCPolicyCounters* _gc_policy_counters;
  57 
  58   // Requires that the concrete subclass sets the alignment constraints
  59   // before calling.
  60   virtual void initialize_flags();
  61   virtual void initialize_size_info() = 0;
  62   // Initialize "_permanent_generation" to a spec for the given kind of
  63   // Perm Gen.
  64   void initialize_perm_generation(PermGen::Name pgnm);
  65 
  66   size_t _initial_heap_byte_size;
  67   size_t _max_heap_byte_size;
  68   size_t _min_heap_byte_size;
  69 
  70   size_t _min_alignment;
  71   size_t _max_alignment;
  72 
  73   CollectorPolicy() :
  74     _min_alignment(1),
  75     _max_alignment(1),
  76     _initial_heap_byte_size(0),
  77     _max_heap_byte_size(0),
  78     _min_heap_byte_size(0)
  79   {}
  80 
  81  public:
  82   void set_min_alignment(size_t align)         { _min_alignment = align; }
  83   size_t min_alignment()                       { return _min_alignment; }
  84   void set_max_alignment(size_t align)         { _max_alignment = align; }
  85   size_t max_alignment()                       { return _max_alignment; }
  86 
  87   size_t initial_heap_byte_size() { return _initial_heap_byte_size; }

  88   size_t max_heap_byte_size()     { return _max_heap_byte_size; }

  89   size_t min_heap_byte_size()     { return _min_heap_byte_size; }

  90 
  91   enum Name {
  92     CollectorPolicyKind,
  93     TwoGenerationCollectorPolicyKind,
  94     TrainPolicyKind,
  95     ConcurrentMarkSweepPolicyKind,
  96     ASConcurrentMarkSweepPolicyKind

  97   };
  98 
  99   // Identification methods.
 100   virtual GenCollectorPolicy*           as_generation_policy()          { return NULL; }
 101   virtual TwoGenerationCollectorPolicy* as_two_generation_policy()        { return NULL; }
 102   virtual MarkSweepPolicy*              as_mark_sweep_policy()            { return NULL; }
 103 #ifndef SERIALGC
 104   virtual ConcurrentMarkSweepPolicy*    as_concurrent_mark_sweep_policy() { return NULL; }

 105 #endif // SERIALGC 
 106   // Note that these are not virtual.
 107   bool is_generation_policy()            { return as_generation_policy() != NULL; }
 108   bool is_two_generation_policy()        { return as_two_generation_policy() != NULL; }
 109   bool is_mark_sweep_policy()            { return as_mark_sweep_policy() != NULL; }
 110 #ifndef SERIALGC
 111   bool is_concurrent_mark_sweep_policy() { return as_concurrent_mark_sweep_policy() != NULL; }

 112 #else  // SERIALGC
 113   bool is_concurrent_mark_sweep_policy() { return false; }

 114 #endif // SERIALGC
 115 

 116   virtual PermanentGenerationSpec *permanent_generation() {
 117     assert(_permanent_generation != NULL, "Sanity check");
 118     return _permanent_generation;
 119   }
 120 
 121   virtual BarrierSet::Name barrier_set_name() = 0;
 122   virtual GenRemSet::Name  rem_set_name() = 0;
 123 
 124   // Create the remembered set (to cover the given reserved region,
 125   // allowing breaking up into at most "max_covered_regions").
 126   virtual GenRemSet* create_rem_set(MemRegion reserved,
 127                                     int max_covered_regions);
 128 
 129   // This method controls how a collector satisfies a request
 130   // for a block of memory.  "gc_time_limit_was_exceeded" will
 131   // be set to true if the adaptive size policy determine that
 132   // an excessive amount of time is being spent doing collections
 133   // and caused a NULL to be returned.  If a NULL is not returned,
 134   // "gc_time_limit_was_exceeded" has an undefined meaning.
 135   virtual HeapWord* mem_allocate_work(size_t size,


 168   GenerationSpec **_generations;
 169 
 170   // The sizing of the different generations in the heap are controlled
 171   // by a sizing policy.
 172   AdaptiveSizePolicy* _size_policy;
 173 
 174   // Return true if an allocation should be attempted in the older
 175   // generation if it fails in the younger generation.  Return
 176   // false, otherwise.
 177   virtual bool should_try_older_generation_allocation(size_t word_size) const;
 178 
 179   void initialize_flags();
 180   void initialize_size_info();
 181 
 182   // Try to allocate space by expanding the heap.
 183   virtual HeapWord* expand_heap_and_allocate(size_t size, bool is_tlab);
 184     
 185   // compute max heap alignment
 186   size_t compute_max_alignment();
 187 








 188 
 189  public:








 190   virtual int number_of_generations() = 0;
 191 
 192   virtual GenerationSpec **generations()       {
 193     assert(_generations != NULL, "Sanity check");
 194     return _generations;
 195   }
 196 
 197   virtual GenCollectorPolicy* as_generation_policy() { return this; }
 198 
 199   virtual void initialize_generations() = 0;
 200 
 201   virtual void initialize_all() {
 202     initialize_flags();
 203     initialize_size_info();
 204     initialize_generations();
 205   }
 206 
 207   HeapWord* mem_allocate_work(size_t size,
 208                               bool is_tlab,
 209                               bool* gc_overhead_limit_was_exceeded);


 222 };
 223 
 224 
 225 // All of hotspot's current collectors are subtypes of this
 226 // class. Currently, these collectors all use the same gen[0],
 227 // but have different gen[1] types. If we add another subtype
 228 // of CollectorPolicy, this class should be broken out into
 229 // its own file.
 230 
 231 class TwoGenerationCollectorPolicy : public GenCollectorPolicy {
 232  protected:
 233   size_t _min_gen1_size;
 234   size_t _initial_gen1_size;
 235   size_t _max_gen1_size;
 236 
 237   void initialize_flags();
 238   void initialize_size_info();
 239   void initialize_generations()                { ShouldNotReachHere(); }
 240 
 241  public:








 242   // Inherited methods
 243   TwoGenerationCollectorPolicy* as_two_generation_policy() { return this; }
 244 
 245   int number_of_generations()                  { return 2; }
 246   BarrierSet::Name barrier_set_name()          { return BarrierSet::CardTableModRef; }
 247   GenRemSet::Name rem_set_name()               { return GenRemSet::CardTable; }
 248 
 249   virtual CollectorPolicy::Name kind() { 
 250     return CollectorPolicy::TwoGenerationCollectorPolicyKind; 
 251   }




 252 };
 253 
 254 class MarkSweepPolicy : public TwoGenerationCollectorPolicy {
 255  protected:
 256   void initialize_generations();
 257 
 258  public:
 259   MarkSweepPolicy();
 260 
 261   MarkSweepPolicy* as_mark_sweep_policy() { return this; }
 262 
 263   void initialize_gc_policy_counters();
 264 };
 265 
   1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)collectorPolicy.hpp  1.41 07/05/29 09:44:14 JVM"
   3 #endif
   4 /*
   5  * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 // This class (or more correctly, subtypes of this class)
  29 // are used to define global garbage collector attributes.
  30 // This includes initialization of generations and any other
  31 // shared resources they may need. 
  32 //
  33 // In general, all flag adjustment and validation should be
  34 // done in initialize_flags(), which is called prior to
  35 // initialize_size_info().
  36 //
  37 // This class is not fully developed yet. As more collector(s)
  38 // are added, it is expected that we will come across further
  39 // behavior that requires global attention. The correct place
  40 // to deal with those issues is this class. 
  41 
  42 // Forward declarations.
  43 class GenCollectorPolicy;
  44 class TwoGenerationCollectorPolicy;
  45 class AdaptiveSizePolicy;
  46 #ifndef SERIALGC
  47 class ConcurrentMarkSweepPolicy;
  48 class G1CollectorPolicy;
  49 #endif // SERIALGC
  50 
  51 class GCPolicyCounters;
  52 class PermanentGenerationSpec;
  53 class MarkSweepPolicy;
  54 
  55 class CollectorPolicy : public CHeapObj {
  56  protected:
  57   PermanentGenerationSpec *_permanent_generation;
  58   GCPolicyCounters* _gc_policy_counters;
  59 
  60   // Requires that the concrete subclass sets the alignment constraints
  61   // before calling.
  62   virtual void initialize_flags();
  63   virtual void initialize_size_info();
  64   // Initialize "_permanent_generation" to a spec for the given kind of
  65   // Perm Gen.
  66   void initialize_perm_generation(PermGen::Name pgnm);
  67 
  68   size_t _initial_heap_byte_size;
  69   size_t _max_heap_byte_size;
  70   size_t _min_heap_byte_size;
  71 
  72   size_t _min_alignment;
  73   size_t _max_alignment;
  74 
  75   CollectorPolicy() :
  76     _min_alignment(1),
  77     _max_alignment(1),
  78     _initial_heap_byte_size(0),
  79     _max_heap_byte_size(0),
  80     _min_heap_byte_size(0)
  81   {}
  82 
  83  public:
  84   void set_min_alignment(size_t align)         { _min_alignment = align; }
  85   size_t min_alignment()                       { return _min_alignment; }
  86   void set_max_alignment(size_t align)         { _max_alignment = align; }
  87   size_t max_alignment()                       { return _max_alignment; }
  88 
  89   size_t initial_heap_byte_size() { return _initial_heap_byte_size; }
  90   void set_initial_heap_byte_size(size_t v) { _initial_heap_byte_size = v; }
  91   size_t max_heap_byte_size()     { return _max_heap_byte_size; }
  92   void set_max_heap_byte_size(size_t v) { _max_heap_byte_size = v; }
  93   size_t min_heap_byte_size()     { return _min_heap_byte_size; }
  94   void set_min_heap_byte_size(size_t v) { _min_heap_byte_size = v; }
  95 
  96   enum Name {
  97     CollectorPolicyKind,
  98     TwoGenerationCollectorPolicyKind,

  99     ConcurrentMarkSweepPolicyKind,
 100     ASConcurrentMarkSweepPolicyKind,
 101     G1CollectorPolicyKind
 102   };
 103 
 104   // Identification methods.
 105   virtual GenCollectorPolicy*           as_generation_policy()            { return NULL; }
 106   virtual TwoGenerationCollectorPolicy* as_two_generation_policy()        { return NULL; }
 107   virtual MarkSweepPolicy*              as_mark_sweep_policy()            { return NULL; }
 108 #ifndef SERIALGC
 109   virtual ConcurrentMarkSweepPolicy*    as_concurrent_mark_sweep_policy() { return NULL; }
 110   virtual G1CollectorPolicy*            as_g1_policy()                    { return NULL; }
 111 #endif // SERIALGC
 112   // Note that these are not virtual.
 113   bool is_generation_policy()            { return as_generation_policy() != NULL; }
 114   bool is_two_generation_policy()        { return as_two_generation_policy() != NULL; }
 115   bool is_mark_sweep_policy()            { return as_mark_sweep_policy() != NULL; }
 116 #ifndef SERIALGC
 117   bool is_concurrent_mark_sweep_policy() { return as_concurrent_mark_sweep_policy() != NULL; }
 118   bool is_g1_policy()                    { return as_g1_policy() != NULL; }
 119 #else  // SERIALGC
 120   bool is_concurrent_mark_sweep_policy() { return false; }
 121   bool is_g1_policy()                    { return false; }
 122 #endif // SERIALGC
 123 
 124 
 125   virtual PermanentGenerationSpec *permanent_generation() {
 126     assert(_permanent_generation != NULL, "Sanity check");
 127     return _permanent_generation;
 128   }
 129 
 130   virtual BarrierSet::Name barrier_set_name() = 0;
 131   virtual GenRemSet::Name  rem_set_name() = 0;
 132 
 133   // Create the remembered set (to cover the given reserved region,
 134   // allowing breaking up into at most "max_covered_regions").
 135   virtual GenRemSet* create_rem_set(MemRegion reserved,
 136                                     int max_covered_regions);
 137 
 138   // This method controls how a collector satisfies a request
 139   // for a block of memory.  "gc_time_limit_was_exceeded" will
 140   // be set to true if the adaptive size policy determine that
 141   // an excessive amount of time is being spent doing collections
 142   // and caused a NULL to be returned.  If a NULL is not returned,
 143   // "gc_time_limit_was_exceeded" has an undefined meaning.
 144   virtual HeapWord* mem_allocate_work(size_t size,


 177   GenerationSpec **_generations;
 178 
 179   // The sizing of the different generations in the heap are controlled
 180   // by a sizing policy.
 181   AdaptiveSizePolicy* _size_policy;
 182 
 183   // Return true if an allocation should be attempted in the older
 184   // generation if it fails in the younger generation.  Return
 185   // false, otherwise.
 186   virtual bool should_try_older_generation_allocation(size_t word_size) const;
 187 
 188   void initialize_flags();
 189   void initialize_size_info();
 190 
 191   // Try to allocate space by expanding the heap.
 192   virtual HeapWord* expand_heap_and_allocate(size_t size, bool is_tlab);
 193     
 194   // compute max heap alignment
 195   size_t compute_max_alignment();
 196 
 197  // Scale the base_size by NewRation according to
 198  //     result = base_size / (NewRatio + 1)
 199  // and align by min_alignment()
 200  size_t scale_by_NewRatio_aligned(size_t base_size);
 201 
 202  // Bound the value by the given maximum minus the
 203  // min_alignment.
 204  size_t bound_minus_alignment(size_t desired_size, size_t maximum_size);
 205 
 206  public:
 207   // Accessors
 208   size_t min_gen0_size() { return _min_gen0_size; }
 209   void set_min_gen0_size(size_t v) { _min_gen0_size = v; }
 210   size_t initial_gen0_size() { return _initial_gen0_size; }
 211   void set_initial_gen0_size(size_t v) { _initial_gen0_size = v; }
 212   size_t max_gen0_size() { return _max_gen0_size; }
 213   void set_max_gen0_size(size_t v) { _max_gen0_size = v; }
 214 
 215   virtual int number_of_generations() = 0;
 216 
 217   virtual GenerationSpec **generations()       {
 218     assert(_generations != NULL, "Sanity check");
 219     return _generations;
 220   }
 221 
 222   virtual GenCollectorPolicy* as_generation_policy() { return this; }
 223 
 224   virtual void initialize_generations() = 0;
 225 
 226   virtual void initialize_all() {
 227     initialize_flags();
 228     initialize_size_info();
 229     initialize_generations();
 230   }
 231 
 232   HeapWord* mem_allocate_work(size_t size,
 233                               bool is_tlab,
 234                               bool* gc_overhead_limit_was_exceeded);


 247 };
 248 
 249 
 250 // All of hotspot's current collectors are subtypes of this
 251 // class. Currently, these collectors all use the same gen[0],
 252 // but have different gen[1] types. If we add another subtype
 253 // of CollectorPolicy, this class should be broken out into
 254 // its own file.
 255 
 256 class TwoGenerationCollectorPolicy : public GenCollectorPolicy {
 257  protected:
 258   size_t _min_gen1_size;
 259   size_t _initial_gen1_size;
 260   size_t _max_gen1_size;
 261 
 262   void initialize_flags();
 263   void initialize_size_info();
 264   void initialize_generations()                { ShouldNotReachHere(); }
 265 
 266  public:
 267   // Accessors
 268   size_t min_gen1_size() { return _min_gen1_size; }
 269   void set_min_gen1_size(size_t v) { _min_gen1_size = v; }
 270   size_t initial_gen1_size() { return _initial_gen1_size; }
 271   void set_initial_gen1_size(size_t v) { _initial_gen1_size = v; }
 272   size_t max_gen1_size() { return _max_gen1_size; }
 273   void set_max_gen1_size(size_t v) { _max_gen1_size = v; }
 274 
 275   // Inherited methods
 276   TwoGenerationCollectorPolicy* as_two_generation_policy() { return this; }
 277 
 278   int number_of_generations()                  { return 2; }
 279   BarrierSet::Name barrier_set_name()          { return BarrierSet::CardTableModRef; }
 280   GenRemSet::Name rem_set_name()               { return GenRemSet::CardTable; }
 281 
 282   virtual CollectorPolicy::Name kind() { 
 283     return CollectorPolicy::TwoGenerationCollectorPolicyKind; 
 284   }
 285 
 286   // Returns true is gen0 sizes were adjusted
 287   bool adjust_gen0_sizes(size_t* gen0_size_ptr, size_t* gen1_size_ptr,
 288                                size_t heap_size, size_t min_gen1_size);
 289 };
 290 
 291 class MarkSweepPolicy : public TwoGenerationCollectorPolicy {
 292  protected:
 293   void initialize_generations();
 294 
 295  public:
 296   MarkSweepPolicy();
 297 
 298   MarkSweepPolicy* as_mark_sweep_policy() { return this; }
 299 
 300   void initialize_gc_policy_counters();
 301 };
 302