Mercurial > hg > graal-jvmci-8
comparison src/share/vm/memory/collectorPolicy.cpp @ 14422:2b8e28fdf503
Merge
author | kvn |
---|---|
date | Tue, 05 Nov 2013 17:38:04 -0800 |
parents | 85c1ca43713f |
children | 4288e54fd145 |
comparison
equal
deleted
inserted
replaced
14421:3068270ba476 | 14422:2b8e28fdf503 |
---|---|
46 #endif // INCLUDE_ALL_GCS | 46 #endif // INCLUDE_ALL_GCS |
47 | 47 |
48 // CollectorPolicy methods. | 48 // CollectorPolicy methods. |
49 | 49 |
50 void CollectorPolicy::initialize_flags() { | 50 void CollectorPolicy::initialize_flags() { |
51 assert(max_alignment() >= min_alignment(), | 51 assert(_max_alignment >= _min_alignment, |
52 err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT, | 52 err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT, |
53 max_alignment(), min_alignment())); | 53 _max_alignment, _min_alignment)); |
54 assert(max_alignment() % min_alignment() == 0, | 54 assert(_max_alignment % _min_alignment == 0, |
55 err_msg("max_alignment: " SIZE_FORMAT " not aligned by min_alignment: " SIZE_FORMAT, | 55 err_msg("max_alignment: " SIZE_FORMAT " not aligned by min_alignment: " SIZE_FORMAT, |
56 max_alignment(), min_alignment())); | 56 _max_alignment, _min_alignment)); |
57 | 57 |
58 if (MaxHeapSize < InitialHeapSize) { | 58 if (MaxHeapSize < InitialHeapSize) { |
59 vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified"); | 59 vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified"); |
60 } | 60 } |
61 | 61 |
62 if (MetaspaceSize > MaxMetaspaceSize) { | 62 MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, _min_alignment); |
63 MaxMetaspaceSize = MetaspaceSize; | |
64 } | |
65 MetaspaceSize = MAX2(min_alignment(), align_size_down_(MetaspaceSize, min_alignment())); | |
66 // Don't increase Metaspace size limit above specified. | |
67 MaxMetaspaceSize = align_size_down(MaxMetaspaceSize, max_alignment()); | |
68 if (MetaspaceSize > MaxMetaspaceSize) { | |
69 MetaspaceSize = MaxMetaspaceSize; | |
70 } | |
71 | |
72 MinMetaspaceExpansion = MAX2(min_alignment(), align_size_down_(MinMetaspaceExpansion, min_alignment())); | |
73 MaxMetaspaceExpansion = MAX2(min_alignment(), align_size_down_(MaxMetaspaceExpansion, min_alignment())); | |
74 | |
75 MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, min_alignment()); | |
76 | |
77 assert(MetaspaceSize % min_alignment() == 0, "metapace alignment"); | |
78 assert(MaxMetaspaceSize % max_alignment() == 0, "maximum metaspace alignment"); | |
79 if (MetaspaceSize < 256*K) { | |
80 vm_exit_during_initialization("Too small initial Metaspace size"); | |
81 } | |
82 } | 63 } |
83 | 64 |
84 void CollectorPolicy::initialize_size_info() { | 65 void CollectorPolicy::initialize_size_info() { |
85 // User inputs from -mx and ms must be aligned | 66 // User inputs from -mx and ms must be aligned |
86 set_min_heap_byte_size(align_size_up(Arguments::min_heap_size(), min_alignment())); | 67 _min_heap_byte_size = align_size_up(Arguments::min_heap_size(), _min_alignment); |
87 set_initial_heap_byte_size(align_size_up(InitialHeapSize, min_alignment())); | 68 _initial_heap_byte_size = align_size_up(InitialHeapSize, _min_alignment); |
88 set_max_heap_byte_size(align_size_up(MaxHeapSize, max_alignment())); | 69 _max_heap_byte_size = align_size_up(MaxHeapSize, _max_alignment); |
89 | 70 |
90 // Check heap parameter properties | 71 // Check heap parameter properties |
91 if (initial_heap_byte_size() < M) { | 72 if (_initial_heap_byte_size < M) { |
92 vm_exit_during_initialization("Too small initial heap"); | 73 vm_exit_during_initialization("Too small initial heap"); |
93 } | 74 } |
94 // Check heap parameter properties | 75 // Check heap parameter properties |
95 if (min_heap_byte_size() < M) { | 76 if (_min_heap_byte_size < M) { |
96 vm_exit_during_initialization("Too small minimum heap"); | 77 vm_exit_during_initialization("Too small minimum heap"); |
97 } | 78 } |
98 if (initial_heap_byte_size() <= NewSize) { | 79 if (_initial_heap_byte_size <= NewSize) { |
99 // make sure there is at least some room in old space | 80 // make sure there is at least some room in old space |
100 vm_exit_during_initialization("Too small initial heap for new size specified"); | 81 vm_exit_during_initialization("Too small initial heap for new size specified"); |
101 } | 82 } |
102 if (max_heap_byte_size() < min_heap_byte_size()) { | 83 if (_max_heap_byte_size < _min_heap_byte_size) { |
103 vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified"); | 84 vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified"); |
104 } | 85 } |
105 if (initial_heap_byte_size() < min_heap_byte_size()) { | 86 if (_initial_heap_byte_size < _min_heap_byte_size) { |
106 vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified"); | 87 vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified"); |
107 } | 88 } |
108 if (max_heap_byte_size() < initial_heap_byte_size()) { | 89 if (_max_heap_byte_size < _initial_heap_byte_size) { |
109 vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified"); | 90 vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified"); |
110 } | 91 } |
111 | 92 |
112 if (PrintGCDetails && Verbose) { | 93 if (PrintGCDetails && Verbose) { |
113 gclog_or_tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap " | 94 gclog_or_tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap " |
114 SIZE_FORMAT " Maximum heap " SIZE_FORMAT, | 95 SIZE_FORMAT " Maximum heap " SIZE_FORMAT, |
115 min_heap_byte_size(), initial_heap_byte_size(), max_heap_byte_size()); | 96 _min_heap_byte_size, _initial_heap_byte_size, _max_heap_byte_size); |
116 } | 97 } |
117 } | 98 } |
118 | 99 |
119 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) { | 100 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) { |
120 bool result = _should_clear_all_soft_refs; | 101 bool result = _should_clear_all_soft_refs; |
122 return result; | 103 return result; |
123 } | 104 } |
124 | 105 |
125 GenRemSet* CollectorPolicy::create_rem_set(MemRegion whole_heap, | 106 GenRemSet* CollectorPolicy::create_rem_set(MemRegion whole_heap, |
126 int max_covered_regions) { | 107 int max_covered_regions) { |
127 switch (rem_set_name()) { | 108 assert(rem_set_name() == GenRemSet::CardTable, "unrecognized GenRemSet::Name"); |
128 case GenRemSet::CardTable: { | 109 return new CardTableRS(whole_heap, max_covered_regions); |
129 CardTableRS* res = new CardTableRS(whole_heap, max_covered_regions); | |
130 return res; | |
131 } | |
132 default: | |
133 guarantee(false, "unrecognized GenRemSet::Name"); | |
134 return NULL; | |
135 } | |
136 } | 110 } |
137 | 111 |
138 void CollectorPolicy::cleared_all_soft_refs() { | 112 void CollectorPolicy::cleared_all_soft_refs() { |
139 // If near gc overhear limit, continue to clear SoftRefs. SoftRefs may | 113 // If near gc overhear limit, continue to clear SoftRefs. SoftRefs may |
140 // have been cleared in the last collection but if the gc overhear | 114 // have been cleared in the last collection but if the gc overhear |
143 _should_clear_all_soft_refs = size_policy()->gc_overhead_limit_near(); | 117 _should_clear_all_soft_refs = size_policy()->gc_overhead_limit_near(); |
144 } | 118 } |
145 _all_soft_refs_clear = true; | 119 _all_soft_refs_clear = true; |
146 } | 120 } |
147 | 121 |
122 size_t CollectorPolicy::compute_max_alignment() { | |
123 // The card marking array and the offset arrays for old generations are | |
124 // committed in os pages as well. Make sure they are entirely full (to | |
125 // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1 | |
126 // byte entry and the os page size is 4096, the maximum heap size should | |
127 // be 512*4096 = 2MB aligned. | |
128 | |
129 // There is only the GenRemSet in Hotspot and only the GenRemSet::CardTable | |
130 // is supported. | |
131 // Requirements of any new remembered set implementations must be added here. | |
132 size_t alignment = GenRemSet::max_alignment_constraint(GenRemSet::CardTable); | |
133 | |
134 // Parallel GC does its own alignment of the generations to avoid requiring a | |
135 // large page (256M on some platforms) for the permanent generation. The | |
136 // other collectors should also be updated to do their own alignment and then | |
137 // this use of lcm() should be removed. | |
138 if (UseLargePages && !UseParallelGC) { | |
139 // in presence of large pages we have to make sure that our | |
140 // alignment is large page aware | |
141 alignment = lcm(os::large_page_size(), alignment); | |
142 } | |
143 | |
144 return alignment; | |
145 } | |
148 | 146 |
149 // GenCollectorPolicy methods. | 147 // GenCollectorPolicy methods. |
150 | 148 |
151 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) { | 149 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) { |
152 size_t x = base_size / (NewRatio+1); | 150 size_t x = base_size / (NewRatio+1); |
153 size_t new_gen_size = x > min_alignment() ? | 151 size_t new_gen_size = x > _min_alignment ? |
154 align_size_down(x, min_alignment()) : | 152 align_size_down(x, _min_alignment) : |
155 min_alignment(); | 153 _min_alignment; |
156 return new_gen_size; | 154 return new_gen_size; |
157 } | 155 } |
158 | 156 |
159 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size, | 157 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size, |
160 size_t maximum_size) { | 158 size_t maximum_size) { |
161 size_t alignment = min_alignment(); | 159 size_t alignment = _min_alignment; |
162 size_t max_minus = maximum_size - alignment; | 160 size_t max_minus = maximum_size - alignment; |
163 return desired_size < max_minus ? desired_size : max_minus; | 161 return desired_size < max_minus ? desired_size : max_minus; |
164 } | 162 } |
165 | 163 |
166 | 164 |
173 init_survivor_size, | 171 init_survivor_size, |
174 max_gc_pause_sec, | 172 max_gc_pause_sec, |
175 GCTimeRatio); | 173 GCTimeRatio); |
176 } | 174 } |
177 | 175 |
178 size_t GenCollectorPolicy::compute_max_alignment() { | |
179 // The card marking array and the offset arrays for old generations are | |
180 // committed in os pages as well. Make sure they are entirely full (to | |
181 // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1 | |
182 // byte entry and the os page size is 4096, the maximum heap size should | |
183 // be 512*4096 = 2MB aligned. | |
184 size_t alignment = GenRemSet::max_alignment_constraint(rem_set_name()); | |
185 | |
186 // Parallel GC does its own alignment of the generations to avoid requiring a | |
187 // large page (256M on some platforms) for the permanent generation. The | |
188 // other collectors should also be updated to do their own alignment and then | |
189 // this use of lcm() should be removed. | |
190 if (UseLargePages && !UseParallelGC) { | |
191 // in presence of large pages we have to make sure that our | |
192 // alignment is large page aware | |
193 alignment = lcm(os::large_page_size(), alignment); | |
194 } | |
195 | |
196 assert(alignment >= min_alignment(), "Must be"); | |
197 | |
198 return alignment; | |
199 } | |
200 | |
201 void GenCollectorPolicy::initialize_flags() { | 176 void GenCollectorPolicy::initialize_flags() { |
202 // All sizes must be multiples of the generation granularity. | 177 // All sizes must be multiples of the generation granularity. |
203 set_min_alignment((uintx) Generation::GenGrain); | 178 _min_alignment = (uintx) Generation::GenGrain; |
204 set_max_alignment(compute_max_alignment()); | 179 _max_alignment = compute_max_alignment(); |
205 | 180 |
206 CollectorPolicy::initialize_flags(); | 181 CollectorPolicy::initialize_flags(); |
207 | 182 |
208 // All generational heaps have a youngest gen; handle those flags here. | 183 // All generational heaps have a youngest gen; handle those flags here. |
209 | 184 |
210 // Adjust max size parameters | 185 // Adjust max size parameters |
211 if (NewSize > MaxNewSize) { | 186 if (NewSize > MaxNewSize) { |
212 MaxNewSize = NewSize; | 187 MaxNewSize = NewSize; |
213 } | 188 } |
214 NewSize = align_size_down(NewSize, min_alignment()); | 189 NewSize = align_size_down(NewSize, _min_alignment); |
215 MaxNewSize = align_size_down(MaxNewSize, min_alignment()); | 190 MaxNewSize = align_size_down(MaxNewSize, _min_alignment); |
216 | 191 |
217 // Check validity of heap flags | 192 // Check validity of heap flags |
218 assert(NewSize % min_alignment() == 0, "eden space alignment"); | 193 assert(NewSize % _min_alignment == 0, "eden space alignment"); |
219 assert(MaxNewSize % min_alignment() == 0, "survivor space alignment"); | 194 assert(MaxNewSize % _min_alignment == 0, "survivor space alignment"); |
220 | 195 |
221 if (NewSize < 3*min_alignment()) { | 196 if (NewSize < 3 * _min_alignment) { |
222 // make sure there room for eden and two survivor spaces | 197 // make sure there room for eden and two survivor spaces |
223 vm_exit_during_initialization("Too small new size specified"); | 198 vm_exit_during_initialization("Too small new size specified"); |
224 } | 199 } |
225 if (SurvivorRatio < 1 || NewRatio < 1) { | 200 if (SurvivorRatio < 1 || NewRatio < 1) { |
226 vm_exit_during_initialization("Invalid heap ratio specified"); | 201 vm_exit_during_initialization("Invalid young gen ratio specified"); |
227 } | 202 } |
228 } | 203 } |
229 | 204 |
230 void TwoGenerationCollectorPolicy::initialize_flags() { | 205 void TwoGenerationCollectorPolicy::initialize_flags() { |
231 GenCollectorPolicy::initialize_flags(); | 206 GenCollectorPolicy::initialize_flags(); |
232 | 207 |
233 OldSize = align_size_down(OldSize, min_alignment()); | 208 OldSize = align_size_down(OldSize, _min_alignment); |
234 | 209 |
235 if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(NewSize)) { | 210 if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(NewSize)) { |
236 // NewRatio will be used later to set the young generation size so we use | 211 // NewRatio will be used later to set the young generation size so we use |
237 // it to calculate how big the heap should be based on the requested OldSize | 212 // it to calculate how big the heap should be based on the requested OldSize |
238 // and NewRatio. | 213 // and NewRatio. |
239 assert(NewRatio > 0, "NewRatio should have been set up earlier"); | 214 assert(NewRatio > 0, "NewRatio should have been set up earlier"); |
240 size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1); | 215 size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1); |
241 | 216 |
242 calculated_heapsize = align_size_up(calculated_heapsize, max_alignment()); | 217 calculated_heapsize = align_size_up(calculated_heapsize, _max_alignment); |
243 MaxHeapSize = calculated_heapsize; | 218 MaxHeapSize = calculated_heapsize; |
244 InitialHeapSize = calculated_heapsize; | 219 InitialHeapSize = calculated_heapsize; |
245 } | 220 } |
246 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment()); | 221 MaxHeapSize = align_size_up(MaxHeapSize, _max_alignment); |
247 | 222 |
248 // adjust max heap size if necessary | 223 // adjust max heap size if necessary |
249 if (NewSize + OldSize > MaxHeapSize) { | 224 if (NewSize + OldSize > MaxHeapSize) { |
250 if (FLAG_IS_CMDLINE(MaxHeapSize)) { | 225 if (FLAG_IS_CMDLINE(MaxHeapSize)) { |
251 // somebody set a maximum heap size with the intention that we should not | 226 // somebody set a maximum heap size with the intention that we should not |
252 // exceed it. Adjust New/OldSize as necessary. | 227 // exceed it. Adjust New/OldSize as necessary. |
253 uintx calculated_size = NewSize + OldSize; | 228 uintx calculated_size = NewSize + OldSize; |
254 double shrink_factor = (double) MaxHeapSize / calculated_size; | 229 double shrink_factor = (double) MaxHeapSize / calculated_size; |
255 // align | 230 // align |
256 NewSize = align_size_down((uintx) (NewSize * shrink_factor), min_alignment()); | 231 NewSize = align_size_down((uintx) (NewSize * shrink_factor), _min_alignment); |
257 // OldSize is already aligned because above we aligned MaxHeapSize to | 232 // OldSize is already aligned because above we aligned MaxHeapSize to |
258 // max_alignment(), and we just made sure that NewSize is aligned to | 233 // _max_alignment, and we just made sure that NewSize is aligned to |
259 // min_alignment(). In initialize_flags() we verified that max_alignment() | 234 // _min_alignment. In initialize_flags() we verified that _max_alignment |
260 // is a multiple of min_alignment(). | 235 // is a multiple of _min_alignment. |
261 OldSize = MaxHeapSize - NewSize; | 236 OldSize = MaxHeapSize - NewSize; |
262 } else { | 237 } else { |
263 MaxHeapSize = NewSize + OldSize; | 238 MaxHeapSize = NewSize + OldSize; |
264 } | 239 } |
265 } | 240 } |
266 // need to do this again | 241 // need to do this again |
267 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment()); | 242 MaxHeapSize = align_size_up(MaxHeapSize, _max_alignment); |
268 | 243 |
269 // adjust max heap size if necessary | 244 // adjust max heap size if necessary |
270 if (NewSize + OldSize > MaxHeapSize) { | 245 if (NewSize + OldSize > MaxHeapSize) { |
271 if (FLAG_IS_CMDLINE(MaxHeapSize)) { | 246 if (FLAG_IS_CMDLINE(MaxHeapSize)) { |
272 // somebody set a maximum heap size with the intention that we should not | 247 // somebody set a maximum heap size with the intention that we should not |
273 // exceed it. Adjust New/OldSize as necessary. | 248 // exceed it. Adjust New/OldSize as necessary. |
274 uintx calculated_size = NewSize + OldSize; | 249 uintx calculated_size = NewSize + OldSize; |
275 double shrink_factor = (double) MaxHeapSize / calculated_size; | 250 double shrink_factor = (double) MaxHeapSize / calculated_size; |
276 // align | 251 // align |
277 NewSize = align_size_down((uintx) (NewSize * shrink_factor), min_alignment()); | 252 NewSize = align_size_down((uintx) (NewSize * shrink_factor), _min_alignment); |
278 // OldSize is already aligned because above we aligned MaxHeapSize to | 253 // OldSize is already aligned because above we aligned MaxHeapSize to |
279 // max_alignment(), and we just made sure that NewSize is aligned to | 254 // _max_alignment, and we just made sure that NewSize is aligned to |
280 // min_alignment(). In initialize_flags() we verified that max_alignment() | 255 // _min_alignment. In initialize_flags() we verified that _max_alignment |
281 // is a multiple of min_alignment(). | 256 // is a multiple of _min_alignment. |
282 OldSize = MaxHeapSize - NewSize; | 257 OldSize = MaxHeapSize - NewSize; |
283 } else { | 258 } else { |
284 MaxHeapSize = NewSize + OldSize; | 259 MaxHeapSize = NewSize + OldSize; |
285 } | 260 } |
286 } | 261 } |
287 // need to do this again | 262 // need to do this again |
288 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment()); | 263 MaxHeapSize = align_size_up(MaxHeapSize, _max_alignment); |
289 | 264 |
290 always_do_update_barrier = UseConcMarkSweepGC; | 265 always_do_update_barrier = UseConcMarkSweepGC; |
291 | 266 |
292 // Check validity of heap flags | 267 // Check validity of heap flags |
293 assert(OldSize % min_alignment() == 0, "old space alignment"); | 268 assert(OldSize % _min_alignment == 0, "old space alignment"); |
294 assert(MaxHeapSize % max_alignment() == 0, "maximum heap alignment"); | 269 assert(MaxHeapSize % _max_alignment == 0, "maximum heap alignment"); |
295 } | 270 } |
296 | 271 |
297 // Values set on the command line win over any ergonomically | 272 // Values set on the command line win over any ergonomically |
298 // set command line parameters. | 273 // set command line parameters. |
299 // Ergonomic choice of parameters are done before this | 274 // Ergonomic choice of parameters are done before this |
304 // In the absence of explicitly set command line flags, policies | 279 // In the absence of explicitly set command line flags, policies |
305 // such as the use of NewRatio are used to size the generation. | 280 // such as the use of NewRatio are used to size the generation. |
306 void GenCollectorPolicy::initialize_size_info() { | 281 void GenCollectorPolicy::initialize_size_info() { |
307 CollectorPolicy::initialize_size_info(); | 282 CollectorPolicy::initialize_size_info(); |
308 | 283 |
309 // min_alignment() is used for alignment within a generation. | 284 // _min_alignment is used for alignment within a generation. |
310 // There is additional alignment done down stream for some | 285 // There is additional alignment done down stream for some |
311 // collectors that sometimes causes unwanted rounding up of | 286 // collectors that sometimes causes unwanted rounding up of |
312 // generations sizes. | 287 // generations sizes. |
313 | 288 |
314 // Determine maximum size of gen0 | 289 // Determine maximum size of gen0 |
315 | 290 |
316 size_t max_new_size = 0; | 291 size_t max_new_size = 0; |
317 if (FLAG_IS_CMDLINE(MaxNewSize) || FLAG_IS_ERGO(MaxNewSize)) { | 292 if (FLAG_IS_CMDLINE(MaxNewSize) || FLAG_IS_ERGO(MaxNewSize)) { |
318 if (MaxNewSize < min_alignment()) { | 293 if (MaxNewSize < _min_alignment) { |
319 max_new_size = min_alignment(); | 294 max_new_size = _min_alignment; |
320 } | 295 } |
321 if (MaxNewSize >= max_heap_byte_size()) { | 296 if (MaxNewSize >= _max_heap_byte_size) { |
322 max_new_size = align_size_down(max_heap_byte_size() - min_alignment(), | 297 max_new_size = align_size_down(_max_heap_byte_size - _min_alignment, |
323 min_alignment()); | 298 _min_alignment); |
324 warning("MaxNewSize (" SIZE_FORMAT "k) is equal to or " | 299 warning("MaxNewSize (" SIZE_FORMAT "k) is equal to or " |
325 "greater than the entire heap (" SIZE_FORMAT "k). A " | 300 "greater than the entire heap (" SIZE_FORMAT "k). A " |
326 "new generation size of " SIZE_FORMAT "k will be used.", | 301 "new generation size of " SIZE_FORMAT "k will be used.", |
327 MaxNewSize/K, max_heap_byte_size()/K, max_new_size/K); | 302 MaxNewSize/K, _max_heap_byte_size/K, max_new_size/K); |
328 } else { | 303 } else { |
329 max_new_size = align_size_down(MaxNewSize, min_alignment()); | 304 max_new_size = align_size_down(MaxNewSize, _min_alignment); |
330 } | 305 } |
331 | 306 |
332 // The case for FLAG_IS_ERGO(MaxNewSize) could be treated | 307 // The case for FLAG_IS_ERGO(MaxNewSize) could be treated |
333 // specially at this point to just use an ergonomically set | 308 // specially at this point to just use an ergonomically set |
334 // MaxNewSize to set max_new_size. For cases with small | 309 // MaxNewSize to set max_new_size. For cases with small |
342 // can be the case in the future that the collectors would | 317 // can be the case in the future that the collectors would |
343 // only make "wise" ergonomics choices and this policy could | 318 // only make "wise" ergonomics choices and this policy could |
344 // just accept those choices. The choices currently made are | 319 // just accept those choices. The choices currently made are |
345 // not always "wise". | 320 // not always "wise". |
346 } else { | 321 } else { |
347 max_new_size = scale_by_NewRatio_aligned(max_heap_byte_size()); | 322 max_new_size = scale_by_NewRatio_aligned(_max_heap_byte_size); |
348 // Bound the maximum size by NewSize below (since it historically | 323 // Bound the maximum size by NewSize below (since it historically |
349 // would have been NewSize and because the NewRatio calculation could | 324 // would have been NewSize and because the NewRatio calculation could |
350 // yield a size that is too small) and bound it by MaxNewSize above. | 325 // yield a size that is too small) and bound it by MaxNewSize above. |
351 // Ergonomics plays here by previously calculating the desired | 326 // Ergonomics plays here by previously calculating the desired |
352 // NewSize and MaxNewSize. | 327 // NewSize and MaxNewSize. |
355 assert(max_new_size > 0, "All paths should set max_new_size"); | 330 assert(max_new_size > 0, "All paths should set max_new_size"); |
356 | 331 |
357 // Given the maximum gen0 size, determine the initial and | 332 // Given the maximum gen0 size, determine the initial and |
358 // minimum gen0 sizes. | 333 // minimum gen0 sizes. |
359 | 334 |
360 if (max_heap_byte_size() == min_heap_byte_size()) { | 335 if (_max_heap_byte_size == _min_heap_byte_size) { |
361 // The maximum and minimum heap sizes are the same so | 336 // The maximum and minimum heap sizes are the same so |
362 // the generations minimum and initial must be the | 337 // the generations minimum and initial must be the |
363 // same as its maximum. | 338 // same as its maximum. |
364 set_min_gen0_size(max_new_size); | 339 _min_gen0_size = max_new_size; |
365 set_initial_gen0_size(max_new_size); | 340 _initial_gen0_size = max_new_size; |
366 set_max_gen0_size(max_new_size); | 341 _max_gen0_size = max_new_size; |
367 } else { | 342 } else { |
368 size_t desired_new_size = 0; | 343 size_t desired_new_size = 0; |
369 if (!FLAG_IS_DEFAULT(NewSize)) { | 344 if (!FLAG_IS_DEFAULT(NewSize)) { |
370 // If NewSize is set ergonomically (for example by cms), it | 345 // If NewSize is set ergonomically (for example by cms), it |
371 // would make sense to use it. If it is used, also use it | 346 // would make sense to use it. If it is used, also use it |
382 // For the case where NewSize is the default, use NewRatio | 357 // For the case where NewSize is the default, use NewRatio |
383 // to size the minimum and initial generation sizes. | 358 // to size the minimum and initial generation sizes. |
384 // Use the default NewSize as the floor for these values. If | 359 // Use the default NewSize as the floor for these values. If |
385 // NewRatio is overly large, the resulting sizes can be too | 360 // NewRatio is overly large, the resulting sizes can be too |
386 // small. | 361 // small. |
387 _min_gen0_size = MAX2(scale_by_NewRatio_aligned(min_heap_byte_size()), | 362 _min_gen0_size = MAX2(scale_by_NewRatio_aligned(_min_heap_byte_size), NewSize); |
388 NewSize); | |
389 desired_new_size = | 363 desired_new_size = |
390 MAX2(scale_by_NewRatio_aligned(initial_heap_byte_size()), | 364 MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), NewSize); |
391 NewSize); | |
392 } | 365 } |
393 | 366 |
394 assert(_min_gen0_size > 0, "Sanity check"); | 367 assert(_min_gen0_size > 0, "Sanity check"); |
395 set_initial_gen0_size(desired_new_size); | 368 _initial_gen0_size = desired_new_size; |
396 set_max_gen0_size(max_new_size); | 369 _max_gen0_size = max_new_size; |
397 | 370 |
398 // At this point the desirable initial and minimum sizes have been | 371 // At this point the desirable initial and minimum sizes have been |
399 // determined without regard to the maximum sizes. | 372 // determined without regard to the maximum sizes. |
400 | 373 |
401 // Bound the sizes by the corresponding overall heap sizes. | 374 // Bound the sizes by the corresponding overall heap sizes. |
402 set_min_gen0_size( | 375 _min_gen0_size = bound_minus_alignment(_min_gen0_size, _min_heap_byte_size); |
403 bound_minus_alignment(_min_gen0_size, min_heap_byte_size())); | 376 _initial_gen0_size = bound_minus_alignment(_initial_gen0_size, _initial_heap_byte_size); |
404 set_initial_gen0_size( | 377 _max_gen0_size = bound_minus_alignment(_max_gen0_size, _max_heap_byte_size); |
405 bound_minus_alignment(_initial_gen0_size, initial_heap_byte_size())); | |
406 set_max_gen0_size( | |
407 bound_minus_alignment(_max_gen0_size, max_heap_byte_size())); | |
408 | 378 |
409 // At this point all three sizes have been checked against the | 379 // At this point all three sizes have been checked against the |
410 // maximum sizes but have not been checked for consistency | 380 // maximum sizes but have not been checked for consistency |
411 // among the three. | 381 // among the three. |
412 | 382 |
413 // Final check min <= initial <= max | 383 // Final check min <= initial <= max |
414 set_min_gen0_size(MIN2(_min_gen0_size, _max_gen0_size)); | 384 _min_gen0_size = MIN2(_min_gen0_size, _max_gen0_size); |
415 set_initial_gen0_size( | 385 _initial_gen0_size = MAX2(MIN2(_initial_gen0_size, _max_gen0_size), _min_gen0_size); |
416 MAX2(MIN2(_initial_gen0_size, _max_gen0_size), _min_gen0_size)); | 386 _min_gen0_size = MIN2(_min_gen0_size, _initial_gen0_size); |
417 set_min_gen0_size(MIN2(_min_gen0_size, _initial_gen0_size)); | |
418 } | 387 } |
419 | 388 |
420 if (PrintGCDetails && Verbose) { | 389 if (PrintGCDetails && Verbose) { |
421 gclog_or_tty->print_cr("1: Minimum gen0 " SIZE_FORMAT " Initial gen0 " | 390 gclog_or_tty->print_cr("1: Minimum gen0 " SIZE_FORMAT " Initial gen0 " |
422 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, | 391 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, |
423 min_gen0_size(), initial_gen0_size(), max_gen0_size()); | 392 _min_gen0_size, _initial_gen0_size, _max_gen0_size); |
424 } | 393 } |
425 } | 394 } |
426 | 395 |
427 // Call this method during the sizing of the gen1 to make | 396 // Call this method during the sizing of the gen1 to make |
428 // adjustments to gen0 because of gen1 sizing policy. gen0 initially has | 397 // adjustments to gen0 because of gen1 sizing policy. gen0 initially has |
438 const size_t min_gen1_size) { | 407 const size_t min_gen1_size) { |
439 bool result = false; | 408 bool result = false; |
440 | 409 |
441 if ((*gen1_size_ptr + *gen0_size_ptr) > heap_size) { | 410 if ((*gen1_size_ptr + *gen0_size_ptr) > heap_size) { |
442 if ((heap_size < (*gen0_size_ptr + min_gen1_size)) && | 411 if ((heap_size < (*gen0_size_ptr + min_gen1_size)) && |
443 (heap_size >= min_gen1_size + min_alignment())) { | 412 (heap_size >= min_gen1_size + _min_alignment)) { |
444 // Adjust gen0 down to accommodate min_gen1_size | 413 // Adjust gen0 down to accommodate min_gen1_size |
445 *gen0_size_ptr = heap_size - min_gen1_size; | 414 *gen0_size_ptr = heap_size - min_gen1_size; |
446 *gen0_size_ptr = | 415 *gen0_size_ptr = |
447 MAX2((uintx)align_size_down(*gen0_size_ptr, min_alignment()), | 416 MAX2((uintx)align_size_down(*gen0_size_ptr, _min_alignment), _min_alignment); |
448 min_alignment()); | |
449 assert(*gen0_size_ptr > 0, "Min gen0 is too large"); | 417 assert(*gen0_size_ptr > 0, "Min gen0 is too large"); |
450 result = true; | 418 result = true; |
451 } else { | 419 } else { |
452 *gen1_size_ptr = heap_size - *gen0_size_ptr; | 420 *gen1_size_ptr = heap_size - *gen0_size_ptr; |
453 *gen1_size_ptr = | 421 *gen1_size_ptr = |
454 MAX2((uintx)align_size_down(*gen1_size_ptr, min_alignment()), | 422 MAX2((uintx)align_size_down(*gen1_size_ptr, _min_alignment), _min_alignment); |
455 min_alignment()); | |
456 } | 423 } |
457 } | 424 } |
458 return result; | 425 return result; |
459 } | 426 } |
460 | 427 |
471 // At this point the minimum, initial and maximum sizes | 438 // At this point the minimum, initial and maximum sizes |
472 // of the overall heap and of gen0 have been determined. | 439 // of the overall heap and of gen0 have been determined. |
473 // The maximum gen1 size can be determined from the maximum gen0 | 440 // The maximum gen1 size can be determined from the maximum gen0 |
474 // and maximum heap size since no explicit flags exits | 441 // and maximum heap size since no explicit flags exits |
475 // for setting the gen1 maximum. | 442 // for setting the gen1 maximum. |
476 _max_gen1_size = max_heap_byte_size() - _max_gen0_size; | 443 _max_gen1_size = _max_heap_byte_size - _max_gen0_size; |
477 _max_gen1_size = | 444 _max_gen1_size = |
478 MAX2((uintx)align_size_down(_max_gen1_size, min_alignment()), | 445 MAX2((uintx)align_size_down(_max_gen1_size, _min_alignment), _min_alignment); |
479 min_alignment()); | |
480 // If no explicit command line flag has been set for the | 446 // If no explicit command line flag has been set for the |
481 // gen1 size, use what is left for gen1. | 447 // gen1 size, use what is left for gen1. |
482 if (FLAG_IS_DEFAULT(OldSize) || FLAG_IS_ERGO(OldSize)) { | 448 if (FLAG_IS_DEFAULT(OldSize) || FLAG_IS_ERGO(OldSize)) { |
483 // The user has not specified any value or ergonomics | 449 // The user has not specified any value or ergonomics |
484 // has chosen a value (which may or may not be consistent | 450 // has chosen a value (which may or may not be consistent |
485 // with the overall heap size). In either case make | 451 // with the overall heap size). In either case make |
486 // the minimum, maximum and initial sizes consistent | 452 // the minimum, maximum and initial sizes consistent |
487 // with the gen0 sizes and the overall heap sizes. | 453 // with the gen0 sizes and the overall heap sizes. |
488 assert(min_heap_byte_size() > _min_gen0_size, | 454 assert(_min_heap_byte_size > _min_gen0_size, |
489 "gen0 has an unexpected minimum size"); | 455 "gen0 has an unexpected minimum size"); |
490 set_min_gen1_size(min_heap_byte_size() - min_gen0_size()); | 456 _min_gen1_size = _min_heap_byte_size - _min_gen0_size; |
491 set_min_gen1_size( | 457 _min_gen1_size = |
492 MAX2((uintx)align_size_down(_min_gen1_size, min_alignment()), | 458 MAX2((uintx)align_size_down(_min_gen1_size, _min_alignment), _min_alignment); |
493 min_alignment())); | 459 _initial_gen1_size = _initial_heap_byte_size - _initial_gen0_size; |
494 set_initial_gen1_size(initial_heap_byte_size() - initial_gen0_size()); | 460 _initial_gen1_size = |
495 set_initial_gen1_size( | 461 MAX2((uintx)align_size_down(_initial_gen1_size, _min_alignment), _min_alignment); |
496 MAX2((uintx)align_size_down(_initial_gen1_size, min_alignment()), | |
497 min_alignment())); | |
498 | |
499 } else { | 462 } else { |
500 // It's been explicitly set on the command line. Use the | 463 // It's been explicitly set on the command line. Use the |
501 // OldSize and then determine the consequences. | 464 // OldSize and then determine the consequences. |
502 set_min_gen1_size(OldSize); | 465 _min_gen1_size = OldSize; |
503 set_initial_gen1_size(OldSize); | 466 _initial_gen1_size = OldSize; |
504 | 467 |
505 // If the user has explicitly set an OldSize that is inconsistent | 468 // If the user has explicitly set an OldSize that is inconsistent |
506 // with other command line flags, issue a warning. | 469 // with other command line flags, issue a warning. |
507 // The generation minimums and the overall heap mimimum should | 470 // The generation minimums and the overall heap mimimum should |
508 // be within one heap alignment. | 471 // be within one heap alignment. |
509 if ((_min_gen1_size + _min_gen0_size + min_alignment()) < | 472 if ((_min_gen1_size + _min_gen0_size + _min_alignment) < _min_heap_byte_size) { |
510 min_heap_byte_size()) { | |
511 warning("Inconsistency between minimum heap size and minimum " | 473 warning("Inconsistency between minimum heap size and minimum " |
512 "generation sizes: using minimum heap = " SIZE_FORMAT, | 474 "generation sizes: using minimum heap = " SIZE_FORMAT, |
513 min_heap_byte_size()); | 475 _min_heap_byte_size); |
514 } | 476 } |
515 if ((OldSize > _max_gen1_size)) { | 477 if ((OldSize > _max_gen1_size)) { |
516 warning("Inconsistency between maximum heap size and maximum " | 478 warning("Inconsistency between maximum heap size and maximum " |
517 "generation sizes: using maximum heap = " SIZE_FORMAT | 479 "generation sizes: using maximum heap = " SIZE_FORMAT |
518 " -XX:OldSize flag is being ignored", | 480 " -XX:OldSize flag is being ignored", |
519 max_heap_byte_size()); | 481 _max_heap_byte_size); |
520 } | 482 } |
521 // If there is an inconsistency between the OldSize and the minimum and/or | 483 // If there is an inconsistency between the OldSize and the minimum and/or |
522 // initial size of gen0, since OldSize was explicitly set, OldSize wins. | 484 // initial size of gen0, since OldSize was explicitly set, OldSize wins. |
523 if (adjust_gen0_sizes(&_min_gen0_size, &_min_gen1_size, | 485 if (adjust_gen0_sizes(&_min_gen0_size, &_min_gen1_size, |
524 min_heap_byte_size(), OldSize)) { | 486 _min_heap_byte_size, OldSize)) { |
525 if (PrintGCDetails && Verbose) { | 487 if (PrintGCDetails && Verbose) { |
526 gclog_or_tty->print_cr("2: Minimum gen0 " SIZE_FORMAT " Initial gen0 " | 488 gclog_or_tty->print_cr("2: Minimum gen0 " SIZE_FORMAT " Initial gen0 " |
527 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, | 489 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, |
528 min_gen0_size(), initial_gen0_size(), max_gen0_size()); | 490 _min_gen0_size, _initial_gen0_size, _max_gen0_size); |
529 } | 491 } |
530 } | 492 } |
531 // Initial size | 493 // Initial size |
532 if (adjust_gen0_sizes(&_initial_gen0_size, &_initial_gen1_size, | 494 if (adjust_gen0_sizes(&_initial_gen0_size, &_initial_gen1_size, |
533 initial_heap_byte_size(), OldSize)) { | 495 _initial_heap_byte_size, OldSize)) { |
534 if (PrintGCDetails && Verbose) { | 496 if (PrintGCDetails && Verbose) { |
535 gclog_or_tty->print_cr("3: Minimum gen0 " SIZE_FORMAT " Initial gen0 " | 497 gclog_or_tty->print_cr("3: Minimum gen0 " SIZE_FORMAT " Initial gen0 " |
536 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, | 498 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, |
537 min_gen0_size(), initial_gen0_size(), max_gen0_size()); | 499 _min_gen0_size, _initial_gen0_size, _max_gen0_size); |
538 } | 500 } |
539 } | 501 } |
540 } | 502 } |
541 // Enforce the maximum gen1 size. | 503 // Enforce the maximum gen1 size. |
542 set_min_gen1_size(MIN2(_min_gen1_size, _max_gen1_size)); | 504 _min_gen1_size = MIN2(_min_gen1_size, _max_gen1_size); |
543 | 505 |
544 // Check that min gen1 <= initial gen1 <= max gen1 | 506 // Check that min gen1 <= initial gen1 <= max gen1 |
545 set_initial_gen1_size(MAX2(_initial_gen1_size, _min_gen1_size)); | 507 _initial_gen1_size = MAX2(_initial_gen1_size, _min_gen1_size); |
546 set_initial_gen1_size(MIN2(_initial_gen1_size, _max_gen1_size)); | 508 _initial_gen1_size = MIN2(_initial_gen1_size, _max_gen1_size); |
547 | 509 |
548 if (PrintGCDetails && Verbose) { | 510 if (PrintGCDetails && Verbose) { |
549 gclog_or_tty->print_cr("Minimum gen1 " SIZE_FORMAT " Initial gen1 " | 511 gclog_or_tty->print_cr("Minimum gen1 " SIZE_FORMAT " Initial gen1 " |
550 SIZE_FORMAT " Maximum gen1 " SIZE_FORMAT, | 512 SIZE_FORMAT " Maximum gen1 " SIZE_FORMAT, |
551 min_gen1_size(), initial_gen1_size(), max_gen1_size()); | 513 _min_gen1_size, _initial_gen1_size, _max_gen1_size); |
552 } | 514 } |
553 } | 515 } |
554 | 516 |
555 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size, | 517 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size, |
556 bool is_tlab, | 518 bool is_tlab, |