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