src/share/vm/memory/collectorPolicy.hpp

Thu, 05 Jun 2008 15:57:56 -0700

author
ysr
date
Thu, 05 Jun 2008 15:57:56 -0700
changeset 777
37f87013dfd8
parent 448
183f41cf8bfe
child 791
1ee8caae33af
permissions
-rw-r--r--

6711316: Open source the Garbage-First garbage collector
Summary: First mercurial integration of the code for the Garbage-First garbage collector.
Reviewed-by: apetrusenko, iveresov, jmasa, sgoldman, tonyp, ysr

duke@435 1 /*
duke@435 2 * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // This class (or more correctly, subtypes of this class)
duke@435 26 // are used to define global garbage collector attributes.
duke@435 27 // This includes initialization of generations and any other
duke@435 28 // shared resources they may need.
duke@435 29 //
duke@435 30 // In general, all flag adjustment and validation should be
duke@435 31 // done in initialize_flags(), which is called prior to
duke@435 32 // initialize_size_info().
duke@435 33 //
duke@435 34 // This class is not fully developed yet. As more collector(s)
duke@435 35 // are added, it is expected that we will come across further
duke@435 36 // behavior that requires global attention. The correct place
duke@435 37 // to deal with those issues is this class.
duke@435 38
duke@435 39 // Forward declarations.
duke@435 40 class GenCollectorPolicy;
duke@435 41 class TwoGenerationCollectorPolicy;
ysr@777 42 class AdaptiveSizePolicy;
duke@435 43 #ifndef SERIALGC
duke@435 44 class ConcurrentMarkSweepPolicy;
ysr@777 45 class G1CollectorPolicy;
duke@435 46 #endif // SERIALGC
ysr@777 47
duke@435 48 class GCPolicyCounters;
duke@435 49 class PermanentGenerationSpec;
duke@435 50 class MarkSweepPolicy;
duke@435 51
duke@435 52 class CollectorPolicy : public CHeapObj {
duke@435 53 protected:
duke@435 54 PermanentGenerationSpec *_permanent_generation;
duke@435 55 GCPolicyCounters* _gc_policy_counters;
duke@435 56
duke@435 57 // Requires that the concrete subclass sets the alignment constraints
duke@435 58 // before calling.
duke@435 59 virtual void initialize_flags();
ysr@777 60 virtual void initialize_size_info();
duke@435 61 // Initialize "_permanent_generation" to a spec for the given kind of
duke@435 62 // Perm Gen.
duke@435 63 void initialize_perm_generation(PermGen::Name pgnm);
duke@435 64
duke@435 65 size_t _initial_heap_byte_size;
duke@435 66 size_t _max_heap_byte_size;
duke@435 67 size_t _min_heap_byte_size;
duke@435 68
duke@435 69 size_t _min_alignment;
duke@435 70 size_t _max_alignment;
duke@435 71
duke@435 72 CollectorPolicy() :
duke@435 73 _min_alignment(1),
duke@435 74 _max_alignment(1),
duke@435 75 _initial_heap_byte_size(0),
duke@435 76 _max_heap_byte_size(0),
duke@435 77 _min_heap_byte_size(0)
duke@435 78 {}
duke@435 79
duke@435 80 public:
duke@435 81 void set_min_alignment(size_t align) { _min_alignment = align; }
duke@435 82 size_t min_alignment() { return _min_alignment; }
duke@435 83 void set_max_alignment(size_t align) { _max_alignment = align; }
duke@435 84 size_t max_alignment() { return _max_alignment; }
duke@435 85
duke@435 86 size_t initial_heap_byte_size() { return _initial_heap_byte_size; }
jmasa@448 87 void set_initial_heap_byte_size(size_t v) { _initial_heap_byte_size = v; }
duke@435 88 size_t max_heap_byte_size() { return _max_heap_byte_size; }
jmasa@448 89 void set_max_heap_byte_size(size_t v) { _max_heap_byte_size = v; }
duke@435 90 size_t min_heap_byte_size() { return _min_heap_byte_size; }
jmasa@448 91 void set_min_heap_byte_size(size_t v) { _min_heap_byte_size = v; }
duke@435 92
duke@435 93 enum Name {
duke@435 94 CollectorPolicyKind,
duke@435 95 TwoGenerationCollectorPolicyKind,
duke@435 96 ConcurrentMarkSweepPolicyKind,
ysr@777 97 ASConcurrentMarkSweepPolicyKind,
ysr@777 98 G1CollectorPolicyKind
duke@435 99 };
duke@435 100
duke@435 101 // Identification methods.
ysr@777 102 virtual GenCollectorPolicy* as_generation_policy() { return NULL; }
duke@435 103 virtual TwoGenerationCollectorPolicy* as_two_generation_policy() { return NULL; }
duke@435 104 virtual MarkSweepPolicy* as_mark_sweep_policy() { return NULL; }
duke@435 105 #ifndef SERIALGC
duke@435 106 virtual ConcurrentMarkSweepPolicy* as_concurrent_mark_sweep_policy() { return NULL; }
ysr@777 107 virtual G1CollectorPolicy* as_g1_policy() { return NULL; }
duke@435 108 #endif // SERIALGC
duke@435 109 // Note that these are not virtual.
duke@435 110 bool is_generation_policy() { return as_generation_policy() != NULL; }
duke@435 111 bool is_two_generation_policy() { return as_two_generation_policy() != NULL; }
duke@435 112 bool is_mark_sweep_policy() { return as_mark_sweep_policy() != NULL; }
duke@435 113 #ifndef SERIALGC
duke@435 114 bool is_concurrent_mark_sweep_policy() { return as_concurrent_mark_sweep_policy() != NULL; }
ysr@777 115 bool is_g1_policy() { return as_g1_policy() != NULL; }
duke@435 116 #else // SERIALGC
duke@435 117 bool is_concurrent_mark_sweep_policy() { return false; }
ysr@777 118 bool is_g1_policy() { return false; }
duke@435 119 #endif // SERIALGC
duke@435 120
ysr@777 121
duke@435 122 virtual PermanentGenerationSpec *permanent_generation() {
duke@435 123 assert(_permanent_generation != NULL, "Sanity check");
duke@435 124 return _permanent_generation;
duke@435 125 }
duke@435 126
duke@435 127 virtual BarrierSet::Name barrier_set_name() = 0;
duke@435 128 virtual GenRemSet::Name rem_set_name() = 0;
duke@435 129
duke@435 130 // Create the remembered set (to cover the given reserved region,
duke@435 131 // allowing breaking up into at most "max_covered_regions").
duke@435 132 virtual GenRemSet* create_rem_set(MemRegion reserved,
duke@435 133 int max_covered_regions);
duke@435 134
duke@435 135 // This method controls how a collector satisfies a request
duke@435 136 // for a block of memory. "gc_time_limit_was_exceeded" will
duke@435 137 // be set to true if the adaptive size policy determine that
duke@435 138 // an excessive amount of time is being spent doing collections
duke@435 139 // and caused a NULL to be returned. If a NULL is not returned,
duke@435 140 // "gc_time_limit_was_exceeded" has an undefined meaning.
duke@435 141 virtual HeapWord* mem_allocate_work(size_t size,
duke@435 142 bool is_tlab,
duke@435 143 bool* gc_overhead_limit_was_exceeded) = 0;
duke@435 144
duke@435 145 // This method controls how a collector handles one or more
duke@435 146 // of its generations being fully allocated.
duke@435 147 virtual HeapWord *satisfy_failed_allocation(size_t size, bool is_tlab) = 0;
duke@435 148 // Performace Counter support
duke@435 149 GCPolicyCounters* counters() { return _gc_policy_counters; }
duke@435 150
duke@435 151 // Create the jstat counters for the GC policy. By default, policy's
duke@435 152 // don't have associated counters, and we complain if this is invoked.
duke@435 153 virtual void initialize_gc_policy_counters() {
duke@435 154 ShouldNotReachHere();
duke@435 155 }
duke@435 156
duke@435 157 virtual CollectorPolicy::Name kind() {
duke@435 158 return CollectorPolicy::CollectorPolicyKind;
duke@435 159 }
duke@435 160
duke@435 161 // Returns true if a collector has eden space with soft end.
duke@435 162 virtual bool has_soft_ended_eden() {
duke@435 163 return false;
duke@435 164 }
duke@435 165
duke@435 166 };
duke@435 167
duke@435 168 class GenCollectorPolicy : public CollectorPolicy {
duke@435 169 protected:
duke@435 170 size_t _min_gen0_size;
duke@435 171 size_t _initial_gen0_size;
duke@435 172 size_t _max_gen0_size;
duke@435 173
duke@435 174 GenerationSpec **_generations;
duke@435 175
duke@435 176 // The sizing of the different generations in the heap are controlled
duke@435 177 // by a sizing policy.
duke@435 178 AdaptiveSizePolicy* _size_policy;
duke@435 179
duke@435 180 // Return true if an allocation should be attempted in the older
duke@435 181 // generation if it fails in the younger generation. Return
duke@435 182 // false, otherwise.
duke@435 183 virtual bool should_try_older_generation_allocation(size_t word_size) const;
duke@435 184
duke@435 185 void initialize_flags();
duke@435 186 void initialize_size_info();
duke@435 187
duke@435 188 // Try to allocate space by expanding the heap.
duke@435 189 virtual HeapWord* expand_heap_and_allocate(size_t size, bool is_tlab);
duke@435 190
duke@435 191 // compute max heap alignment
duke@435 192 size_t compute_max_alignment();
duke@435 193
jmasa@448 194 // Scale the base_size by NewRation according to
jmasa@448 195 // result = base_size / (NewRatio + 1)
jmasa@448 196 // and align by min_alignment()
jmasa@448 197 size_t scale_by_NewRatio_aligned(size_t base_size);
jmasa@448 198
jmasa@448 199 // Bound the value by the given maximum minus the
jmasa@448 200 // min_alignment.
jmasa@448 201 size_t bound_minus_alignment(size_t desired_size, size_t maximum_size);
duke@435 202
duke@435 203 public:
jmasa@448 204 // Accessors
jmasa@448 205 size_t min_gen0_size() { return _min_gen0_size; }
jmasa@448 206 void set_min_gen0_size(size_t v) { _min_gen0_size = v; }
jmasa@448 207 size_t initial_gen0_size() { return _initial_gen0_size; }
jmasa@448 208 void set_initial_gen0_size(size_t v) { _initial_gen0_size = v; }
jmasa@448 209 size_t max_gen0_size() { return _max_gen0_size; }
jmasa@448 210 void set_max_gen0_size(size_t v) { _max_gen0_size = v; }
jmasa@448 211
duke@435 212 virtual int number_of_generations() = 0;
duke@435 213
duke@435 214 virtual GenerationSpec **generations() {
duke@435 215 assert(_generations != NULL, "Sanity check");
duke@435 216 return _generations;
duke@435 217 }
duke@435 218
duke@435 219 virtual GenCollectorPolicy* as_generation_policy() { return this; }
duke@435 220
duke@435 221 virtual void initialize_generations() = 0;
duke@435 222
duke@435 223 virtual void initialize_all() {
duke@435 224 initialize_flags();
duke@435 225 initialize_size_info();
duke@435 226 initialize_generations();
duke@435 227 }
duke@435 228
duke@435 229 HeapWord* mem_allocate_work(size_t size,
duke@435 230 bool is_tlab,
duke@435 231 bool* gc_overhead_limit_was_exceeded);
duke@435 232
duke@435 233 HeapWord *satisfy_failed_allocation(size_t size, bool is_tlab);
duke@435 234
duke@435 235 // The size that defines a "large array".
duke@435 236 virtual size_t large_typearray_limit();
duke@435 237
duke@435 238 // Adaptive size policy
duke@435 239 AdaptiveSizePolicy* size_policy() { return _size_policy; }
duke@435 240 virtual void initialize_size_policy(size_t init_eden_size,
duke@435 241 size_t init_promo_size,
duke@435 242 size_t init_survivor_size);
duke@435 243
duke@435 244 };
duke@435 245
duke@435 246
duke@435 247 // All of hotspot's current collectors are subtypes of this
duke@435 248 // class. Currently, these collectors all use the same gen[0],
duke@435 249 // but have different gen[1] types. If we add another subtype
duke@435 250 // of CollectorPolicy, this class should be broken out into
duke@435 251 // its own file.
duke@435 252
duke@435 253 class TwoGenerationCollectorPolicy : public GenCollectorPolicy {
duke@435 254 protected:
duke@435 255 size_t _min_gen1_size;
duke@435 256 size_t _initial_gen1_size;
duke@435 257 size_t _max_gen1_size;
duke@435 258
duke@435 259 void initialize_flags();
duke@435 260 void initialize_size_info();
duke@435 261 void initialize_generations() { ShouldNotReachHere(); }
duke@435 262
duke@435 263 public:
jmasa@448 264 // Accessors
jmasa@448 265 size_t min_gen1_size() { return _min_gen1_size; }
jmasa@448 266 void set_min_gen1_size(size_t v) { _min_gen1_size = v; }
jmasa@448 267 size_t initial_gen1_size() { return _initial_gen1_size; }
jmasa@448 268 void set_initial_gen1_size(size_t v) { _initial_gen1_size = v; }
jmasa@448 269 size_t max_gen1_size() { return _max_gen1_size; }
jmasa@448 270 void set_max_gen1_size(size_t v) { _max_gen1_size = v; }
jmasa@448 271
duke@435 272 // Inherited methods
duke@435 273 TwoGenerationCollectorPolicy* as_two_generation_policy() { return this; }
duke@435 274
duke@435 275 int number_of_generations() { return 2; }
duke@435 276 BarrierSet::Name barrier_set_name() { return BarrierSet::CardTableModRef; }
duke@435 277 GenRemSet::Name rem_set_name() { return GenRemSet::CardTable; }
duke@435 278
duke@435 279 virtual CollectorPolicy::Name kind() {
duke@435 280 return CollectorPolicy::TwoGenerationCollectorPolicyKind;
duke@435 281 }
jmasa@448 282
jmasa@448 283 // Returns true is gen0 sizes were adjusted
jmasa@448 284 bool adjust_gen0_sizes(size_t* gen0_size_ptr, size_t* gen1_size_ptr,
jmasa@448 285 size_t heap_size, size_t min_gen1_size);
duke@435 286 };
duke@435 287
duke@435 288 class MarkSweepPolicy : public TwoGenerationCollectorPolicy {
duke@435 289 protected:
duke@435 290 void initialize_generations();
duke@435 291
duke@435 292 public:
duke@435 293 MarkSweepPolicy();
duke@435 294
duke@435 295 MarkSweepPolicy* as_mark_sweep_policy() { return this; }
duke@435 296
duke@435 297 void initialize_gc_policy_counters();
duke@435 298 };

mercurial