comparison src/share/vm/memory/collectorPolicy.cpp @ 12830:9b4d0569f2f4

8025852: Remove unnecessary setters in collector policy classes Summary: Use instance variables directly within the collector policy classes and remove unused setters. Reviewed-by: tschatzl, jcoomes
author jwilhelm
date Thu, 03 Oct 2013 21:36:29 +0200
parents ab68fc0101ce
children 087f02e22fc2
comparison
equal deleted inserted replaced
12351:c49c7f835e8d 12830:9b4d0569f2f4
51 static size_t restricted_align_down(size_t size, size_t alignment) { 51 static size_t restricted_align_down(size_t size, size_t alignment) {
52 return MAX2(alignment, align_size_down_(size, alignment)); 52 return MAX2(alignment, align_size_down_(size, alignment));
53 } 53 }
54 54
55 void CollectorPolicy::initialize_flags() { 55 void CollectorPolicy::initialize_flags() {
56 assert(max_alignment() >= min_alignment(), 56 assert(_max_alignment >= _min_alignment,
57 err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT, 57 err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT,
58 max_alignment(), min_alignment())); 58 _max_alignment, _min_alignment));
59 assert(max_alignment() % min_alignment() == 0, 59 assert(_max_alignment % _min_alignment == 0,
60 err_msg("max_alignment: " SIZE_FORMAT " not aligned by min_alignment: " SIZE_FORMAT, 60 err_msg("max_alignment: " SIZE_FORMAT " not aligned by min_alignment: " SIZE_FORMAT,
61 max_alignment(), min_alignment())); 61 _max_alignment, _min_alignment));
62 62
63 if (MaxHeapSize < InitialHeapSize) { 63 if (MaxHeapSize < InitialHeapSize) {
64 vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified"); 64 vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified");
65 } 65 }
66 66
70 // java.lang.management.MemoryUsage API. 70 // java.lang.management.MemoryUsage API.
71 // 71 //
72 // Ideally, we would be able to set the default value of MaxMetaspaceSize in 72 // Ideally, we would be able to set the default value of MaxMetaspaceSize in
73 // globals.hpp to the aligned value, but this is not possible, since the 73 // globals.hpp to the aligned value, but this is not possible, since the
74 // alignment depends on other flags being parsed. 74 // alignment depends on other flags being parsed.
75 MaxMetaspaceSize = restricted_align_down(MaxMetaspaceSize, max_alignment()); 75 MaxMetaspaceSize = restricted_align_down(MaxMetaspaceSize, _max_alignment);
76 76
77 if (MetaspaceSize > MaxMetaspaceSize) { 77 if (MetaspaceSize > MaxMetaspaceSize) {
78 MetaspaceSize = MaxMetaspaceSize; 78 MetaspaceSize = MaxMetaspaceSize;
79 } 79 }
80 80
81 MetaspaceSize = restricted_align_down(MetaspaceSize, min_alignment()); 81 MetaspaceSize = restricted_align_down(MetaspaceSize, _min_alignment);
82 82
83 assert(MetaspaceSize <= MaxMetaspaceSize, "Must be"); 83 assert(MetaspaceSize <= MaxMetaspaceSize, "Must be");
84 84
85 MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, min_alignment()); 85 MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, _min_alignment);
86 MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, min_alignment()); 86 MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, _min_alignment);
87 87
88 MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, min_alignment()); 88 MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, _min_alignment);
89 89
90 assert(MetaspaceSize % min_alignment() == 0, "metapace alignment"); 90 assert(MetaspaceSize % _min_alignment == 0, "metapace alignment");
91 assert(MaxMetaspaceSize % max_alignment() == 0, "maximum metaspace alignment"); 91 assert(MaxMetaspaceSize % _max_alignment == 0, "maximum metaspace alignment");
92 if (MetaspaceSize < 256*K) { 92 if (MetaspaceSize < 256*K) {
93 vm_exit_during_initialization("Too small initial Metaspace size"); 93 vm_exit_during_initialization("Too small initial Metaspace size");
94 } 94 }
95 } 95 }
96 96
97 void CollectorPolicy::initialize_size_info() { 97 void CollectorPolicy::initialize_size_info() {
98 // User inputs from -mx and ms must be aligned 98 // User inputs from -mx and ms must be aligned
99 set_min_heap_byte_size(align_size_up(Arguments::min_heap_size(), min_alignment())); 99 _min_heap_byte_size = align_size_up(Arguments::min_heap_size(), _min_alignment);
100 set_initial_heap_byte_size(align_size_up(InitialHeapSize, min_alignment())); 100 _initial_heap_byte_size = align_size_up(InitialHeapSize, _min_alignment);
101 set_max_heap_byte_size(align_size_up(MaxHeapSize, max_alignment())); 101 _max_heap_byte_size = align_size_up(MaxHeapSize, _max_alignment);
102 102
103 // Check heap parameter properties 103 // Check heap parameter properties
104 if (initial_heap_byte_size() < M) { 104 if (_initial_heap_byte_size < M) {
105 vm_exit_during_initialization("Too small initial heap"); 105 vm_exit_during_initialization("Too small initial heap");
106 } 106 }
107 // Check heap parameter properties 107 // Check heap parameter properties
108 if (min_heap_byte_size() < M) { 108 if (_min_heap_byte_size < M) {
109 vm_exit_during_initialization("Too small minimum heap"); 109 vm_exit_during_initialization("Too small minimum heap");
110 } 110 }
111 if (initial_heap_byte_size() <= NewSize) { 111 if (_initial_heap_byte_size <= NewSize) {
112 // make sure there is at least some room in old space 112 // make sure there is at least some room in old space
113 vm_exit_during_initialization("Too small initial heap for new size specified"); 113 vm_exit_during_initialization("Too small initial heap for new size specified");
114 } 114 }
115 if (max_heap_byte_size() < min_heap_byte_size()) { 115 if (_max_heap_byte_size < _min_heap_byte_size) {
116 vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified"); 116 vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified");
117 } 117 }
118 if (initial_heap_byte_size() < min_heap_byte_size()) { 118 if (_initial_heap_byte_size < _min_heap_byte_size) {
119 vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified"); 119 vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified");
120 } 120 }
121 if (max_heap_byte_size() < initial_heap_byte_size()) { 121 if (_max_heap_byte_size < _initial_heap_byte_size) {
122 vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified"); 122 vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified");
123 } 123 }
124 124
125 if (PrintGCDetails && Verbose) { 125 if (PrintGCDetails && Verbose) {
126 gclog_or_tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap " 126 gclog_or_tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap "
127 SIZE_FORMAT " Maximum heap " SIZE_FORMAT, 127 SIZE_FORMAT " Maximum heap " SIZE_FORMAT,
128 min_heap_byte_size(), initial_heap_byte_size(), max_heap_byte_size()); 128 _min_heap_byte_size, _initial_heap_byte_size, _max_heap_byte_size);
129 } 129 }
130 } 130 }
131 131
132 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) { 132 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) {
133 bool result = _should_clear_all_soft_refs; 133 bool result = _should_clear_all_soft_refs;
178 178
179 // GenCollectorPolicy methods. 179 // GenCollectorPolicy methods.
180 180
181 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) { 181 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
182 size_t x = base_size / (NewRatio+1); 182 size_t x = base_size / (NewRatio+1);
183 size_t new_gen_size = x > min_alignment() ? 183 size_t new_gen_size = x > _min_alignment ?
184 align_size_down(x, min_alignment()) : 184 align_size_down(x, _min_alignment) :
185 min_alignment(); 185 _min_alignment;
186 return new_gen_size; 186 return new_gen_size;
187 } 187 }
188 188
189 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size, 189 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
190 size_t maximum_size) { 190 size_t maximum_size) {
191 size_t alignment = min_alignment(); 191 size_t alignment = _min_alignment;
192 size_t max_minus = maximum_size - alignment; 192 size_t max_minus = maximum_size - alignment;
193 return desired_size < max_minus ? desired_size : max_minus; 193 return desired_size < max_minus ? desired_size : max_minus;
194 } 194 }
195 195
196 196
205 GCTimeRatio); 205 GCTimeRatio);
206 } 206 }
207 207
208 void GenCollectorPolicy::initialize_flags() { 208 void GenCollectorPolicy::initialize_flags() {
209 // All sizes must be multiples of the generation granularity. 209 // All sizes must be multiples of the generation granularity.
210 set_min_alignment((uintx) Generation::GenGrain); 210 _min_alignment = (uintx) Generation::GenGrain;
211 set_max_alignment(compute_max_alignment()); 211 _max_alignment = compute_max_alignment();
212 212
213 CollectorPolicy::initialize_flags(); 213 CollectorPolicy::initialize_flags();
214 214
215 // All generational heaps have a youngest gen; handle those flags here. 215 // All generational heaps have a youngest gen; handle those flags here.
216 216
217 // Adjust max size parameters 217 // Adjust max size parameters
218 if (NewSize > MaxNewSize) { 218 if (NewSize > MaxNewSize) {
219 MaxNewSize = NewSize; 219 MaxNewSize = NewSize;
220 } 220 }
221 NewSize = align_size_down(NewSize, min_alignment()); 221 NewSize = align_size_down(NewSize, _min_alignment);
222 MaxNewSize = align_size_down(MaxNewSize, min_alignment()); 222 MaxNewSize = align_size_down(MaxNewSize, _min_alignment);
223 223
224 // Check validity of heap flags 224 // Check validity of heap flags
225 assert(NewSize % min_alignment() == 0, "eden space alignment"); 225 assert(NewSize % _min_alignment == 0, "eden space alignment");
226 assert(MaxNewSize % min_alignment() == 0, "survivor space alignment"); 226 assert(MaxNewSize % _min_alignment == 0, "survivor space alignment");
227 227
228 if (NewSize < 3*min_alignment()) { 228 if (NewSize < 3 * _min_alignment) {
229 // make sure there room for eden and two survivor spaces 229 // make sure there room for eden and two survivor spaces
230 vm_exit_during_initialization("Too small new size specified"); 230 vm_exit_during_initialization("Too small new size specified");
231 } 231 }
232 if (SurvivorRatio < 1 || NewRatio < 1) { 232 if (SurvivorRatio < 1 || NewRatio < 1) {
233 vm_exit_during_initialization("Invalid heap ratio specified"); 233 vm_exit_during_initialization("Invalid heap ratio specified");
235 } 235 }
236 236
237 void TwoGenerationCollectorPolicy::initialize_flags() { 237 void TwoGenerationCollectorPolicy::initialize_flags() {
238 GenCollectorPolicy::initialize_flags(); 238 GenCollectorPolicy::initialize_flags();
239 239
240 OldSize = align_size_down(OldSize, min_alignment()); 240 OldSize = align_size_down(OldSize, _min_alignment);
241 241
242 if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(NewSize)) { 242 if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(NewSize)) {
243 // NewRatio will be used later to set the young generation size so we use 243 // NewRatio will be used later to set the young generation size so we use
244 // it to calculate how big the heap should be based on the requested OldSize 244 // it to calculate how big the heap should be based on the requested OldSize
245 // and NewRatio. 245 // and NewRatio.
246 assert(NewRatio > 0, "NewRatio should have been set up earlier"); 246 assert(NewRatio > 0, "NewRatio should have been set up earlier");
247 size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1); 247 size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1);
248 248
249 calculated_heapsize = align_size_up(calculated_heapsize, max_alignment()); 249 calculated_heapsize = align_size_up(calculated_heapsize, _max_alignment);
250 MaxHeapSize = calculated_heapsize; 250 MaxHeapSize = calculated_heapsize;
251 InitialHeapSize = calculated_heapsize; 251 InitialHeapSize = calculated_heapsize;
252 } 252 }
253 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment()); 253 MaxHeapSize = align_size_up(MaxHeapSize, _max_alignment);
254 254
255 // adjust max heap size if necessary 255 // adjust max heap size if necessary
256 if (NewSize + OldSize > MaxHeapSize) { 256 if (NewSize + OldSize > MaxHeapSize) {
257 if (FLAG_IS_CMDLINE(MaxHeapSize)) { 257 if (FLAG_IS_CMDLINE(MaxHeapSize)) {
258 // somebody set a maximum heap size with the intention that we should not 258 // somebody set a maximum heap size with the intention that we should not
259 // exceed it. Adjust New/OldSize as necessary. 259 // exceed it. Adjust New/OldSize as necessary.
260 uintx calculated_size = NewSize + OldSize; 260 uintx calculated_size = NewSize + OldSize;
261 double shrink_factor = (double) MaxHeapSize / calculated_size; 261 double shrink_factor = (double) MaxHeapSize / calculated_size;
262 // align 262 // align
263 NewSize = align_size_down((uintx) (NewSize * shrink_factor), min_alignment()); 263 NewSize = align_size_down((uintx) (NewSize * shrink_factor), _min_alignment);
264 // OldSize is already aligned because above we aligned MaxHeapSize to 264 // OldSize is already aligned because above we aligned MaxHeapSize to
265 // max_alignment(), and we just made sure that NewSize is aligned to 265 // _max_alignment, and we just made sure that NewSize is aligned to
266 // min_alignment(). In initialize_flags() we verified that max_alignment() 266 // _min_alignment. In initialize_flags() we verified that _max_alignment
267 // is a multiple of min_alignment(). 267 // is a multiple of _min_alignment.
268 OldSize = MaxHeapSize - NewSize; 268 OldSize = MaxHeapSize - NewSize;
269 } else { 269 } else {
270 MaxHeapSize = NewSize + OldSize; 270 MaxHeapSize = NewSize + OldSize;
271 } 271 }
272 } 272 }
273 // need to do this again 273 // need to do this again
274 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment()); 274 MaxHeapSize = align_size_up(MaxHeapSize, _max_alignment);
275 275
276 // adjust max heap size if necessary 276 // adjust max heap size if necessary
277 if (NewSize + OldSize > MaxHeapSize) { 277 if (NewSize + OldSize > MaxHeapSize) {
278 if (FLAG_IS_CMDLINE(MaxHeapSize)) { 278 if (FLAG_IS_CMDLINE(MaxHeapSize)) {
279 // somebody set a maximum heap size with the intention that we should not 279 // somebody set a maximum heap size with the intention that we should not
280 // exceed it. Adjust New/OldSize as necessary. 280 // exceed it. Adjust New/OldSize as necessary.
281 uintx calculated_size = NewSize + OldSize; 281 uintx calculated_size = NewSize + OldSize;
282 double shrink_factor = (double) MaxHeapSize / calculated_size; 282 double shrink_factor = (double) MaxHeapSize / calculated_size;
283 // align 283 // align
284 NewSize = align_size_down((uintx) (NewSize * shrink_factor), min_alignment()); 284 NewSize = align_size_down((uintx) (NewSize * shrink_factor), _min_alignment);
285 // OldSize is already aligned because above we aligned MaxHeapSize to 285 // OldSize is already aligned because above we aligned MaxHeapSize to
286 // max_alignment(), and we just made sure that NewSize is aligned to 286 // _max_alignment, and we just made sure that NewSize is aligned to
287 // min_alignment(). In initialize_flags() we verified that max_alignment() 287 // _min_alignment. In initialize_flags() we verified that _max_alignment
288 // is a multiple of min_alignment(). 288 // is a multiple of _min_alignment.
289 OldSize = MaxHeapSize - NewSize; 289 OldSize = MaxHeapSize - NewSize;
290 } else { 290 } else {
291 MaxHeapSize = NewSize + OldSize; 291 MaxHeapSize = NewSize + OldSize;
292 } 292 }
293 } 293 }
294 // need to do this again 294 // need to do this again
295 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment()); 295 MaxHeapSize = align_size_up(MaxHeapSize, _max_alignment);
296 296
297 always_do_update_barrier = UseConcMarkSweepGC; 297 always_do_update_barrier = UseConcMarkSweepGC;
298 298
299 // Check validity of heap flags 299 // Check validity of heap flags
300 assert(OldSize % min_alignment() == 0, "old space alignment"); 300 assert(OldSize % _min_alignment == 0, "old space alignment");
301 assert(MaxHeapSize % max_alignment() == 0, "maximum heap alignment"); 301 assert(MaxHeapSize % _max_alignment == 0, "maximum heap alignment");
302 } 302 }
303 303
304 // Values set on the command line win over any ergonomically 304 // Values set on the command line win over any ergonomically
305 // set command line parameters. 305 // set command line parameters.
306 // Ergonomic choice of parameters are done before this 306 // Ergonomic choice of parameters are done before this
311 // In the absence of explicitly set command line flags, policies 311 // In the absence of explicitly set command line flags, policies
312 // such as the use of NewRatio are used to size the generation. 312 // such as the use of NewRatio are used to size the generation.
313 void GenCollectorPolicy::initialize_size_info() { 313 void GenCollectorPolicy::initialize_size_info() {
314 CollectorPolicy::initialize_size_info(); 314 CollectorPolicy::initialize_size_info();
315 315
316 // min_alignment() is used for alignment within a generation. 316 // _min_alignment is used for alignment within a generation.
317 // There is additional alignment done down stream for some 317 // There is additional alignment done down stream for some
318 // collectors that sometimes causes unwanted rounding up of 318 // collectors that sometimes causes unwanted rounding up of
319 // generations sizes. 319 // generations sizes.
320 320
321 // Determine maximum size of gen0 321 // Determine maximum size of gen0
322 322
323 size_t max_new_size = 0; 323 size_t max_new_size = 0;
324 if (FLAG_IS_CMDLINE(MaxNewSize) || FLAG_IS_ERGO(MaxNewSize)) { 324 if (FLAG_IS_CMDLINE(MaxNewSize) || FLAG_IS_ERGO(MaxNewSize)) {
325 if (MaxNewSize < min_alignment()) { 325 if (MaxNewSize < _min_alignment) {
326 max_new_size = min_alignment(); 326 max_new_size = _min_alignment;
327 } 327 }
328 if (MaxNewSize >= max_heap_byte_size()) { 328 if (MaxNewSize >= _max_heap_byte_size) {
329 max_new_size = align_size_down(max_heap_byte_size() - min_alignment(), 329 max_new_size = align_size_down(_max_heap_byte_size - _min_alignment,
330 min_alignment()); 330 _min_alignment);
331 warning("MaxNewSize (" SIZE_FORMAT "k) is equal to or " 331 warning("MaxNewSize (" SIZE_FORMAT "k) is equal to or "
332 "greater than the entire heap (" SIZE_FORMAT "k). A " 332 "greater than the entire heap (" SIZE_FORMAT "k). A "
333 "new generation size of " SIZE_FORMAT "k will be used.", 333 "new generation size of " SIZE_FORMAT "k will be used.",
334 MaxNewSize/K, max_heap_byte_size()/K, max_new_size/K); 334 MaxNewSize/K, _max_heap_byte_size/K, max_new_size/K);
335 } else { 335 } else {
336 max_new_size = align_size_down(MaxNewSize, min_alignment()); 336 max_new_size = align_size_down(MaxNewSize, _min_alignment);
337 } 337 }
338 338
339 // The case for FLAG_IS_ERGO(MaxNewSize) could be treated 339 // The case for FLAG_IS_ERGO(MaxNewSize) could be treated
340 // specially at this point to just use an ergonomically set 340 // specially at this point to just use an ergonomically set
341 // MaxNewSize to set max_new_size. For cases with small 341 // MaxNewSize to set max_new_size. For cases with small
349 // can be the case in the future that the collectors would 349 // can be the case in the future that the collectors would
350 // only make "wise" ergonomics choices and this policy could 350 // only make "wise" ergonomics choices and this policy could
351 // just accept those choices. The choices currently made are 351 // just accept those choices. The choices currently made are
352 // not always "wise". 352 // not always "wise".
353 } else { 353 } else {
354 max_new_size = scale_by_NewRatio_aligned(max_heap_byte_size()); 354 max_new_size = scale_by_NewRatio_aligned(_max_heap_byte_size);
355 // Bound the maximum size by NewSize below (since it historically 355 // Bound the maximum size by NewSize below (since it historically
356 // would have been NewSize and because the NewRatio calculation could 356 // would have been NewSize and because the NewRatio calculation could
357 // yield a size that is too small) and bound it by MaxNewSize above. 357 // yield a size that is too small) and bound it by MaxNewSize above.
358 // Ergonomics plays here by previously calculating the desired 358 // Ergonomics plays here by previously calculating the desired
359 // NewSize and MaxNewSize. 359 // NewSize and MaxNewSize.
362 assert(max_new_size > 0, "All paths should set max_new_size"); 362 assert(max_new_size > 0, "All paths should set max_new_size");
363 363
364 // Given the maximum gen0 size, determine the initial and 364 // Given the maximum gen0 size, determine the initial and
365 // minimum gen0 sizes. 365 // minimum gen0 sizes.
366 366
367 if (max_heap_byte_size() == min_heap_byte_size()) { 367 if (_max_heap_byte_size == _min_heap_byte_size) {
368 // The maximum and minimum heap sizes are the same so 368 // The maximum and minimum heap sizes are the same so
369 // the generations minimum and initial must be the 369 // the generations minimum and initial must be the
370 // same as its maximum. 370 // same as its maximum.
371 set_min_gen0_size(max_new_size); 371 _min_gen0_size = max_new_size;
372 set_initial_gen0_size(max_new_size); 372 _initial_gen0_size = max_new_size;
373 set_max_gen0_size(max_new_size); 373 _max_gen0_size = max_new_size;
374 } else { 374 } else {
375 size_t desired_new_size = 0; 375 size_t desired_new_size = 0;
376 if (!FLAG_IS_DEFAULT(NewSize)) { 376 if (!FLAG_IS_DEFAULT(NewSize)) {
377 // If NewSize is set ergonomically (for example by cms), it 377 // If NewSize is set ergonomically (for example by cms), it
378 // would make sense to use it. If it is used, also use it 378 // would make sense to use it. If it is used, also use it
389 // For the case where NewSize is the default, use NewRatio 389 // For the case where NewSize is the default, use NewRatio
390 // to size the minimum and initial generation sizes. 390 // to size the minimum and initial generation sizes.
391 // Use the default NewSize as the floor for these values. If 391 // Use the default NewSize as the floor for these values. If
392 // NewRatio is overly large, the resulting sizes can be too 392 // NewRatio is overly large, the resulting sizes can be too
393 // small. 393 // small.
394 _min_gen0_size = MAX2(scale_by_NewRatio_aligned(min_heap_byte_size()), 394 _min_gen0_size = MAX2(scale_by_NewRatio_aligned(_min_heap_byte_size), NewSize);
395 NewSize);
396 desired_new_size = 395 desired_new_size =
397 MAX2(scale_by_NewRatio_aligned(initial_heap_byte_size()), 396 MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), NewSize);
398 NewSize);
399 } 397 }
400 398
401 assert(_min_gen0_size > 0, "Sanity check"); 399 assert(_min_gen0_size > 0, "Sanity check");
402 set_initial_gen0_size(desired_new_size); 400 _initial_gen0_size = desired_new_size;
403 set_max_gen0_size(max_new_size); 401 _max_gen0_size = max_new_size;
404 402
405 // At this point the desirable initial and minimum sizes have been 403 // At this point the desirable initial and minimum sizes have been
406 // determined without regard to the maximum sizes. 404 // determined without regard to the maximum sizes.
407 405
408 // Bound the sizes by the corresponding overall heap sizes. 406 // Bound the sizes by the corresponding overall heap sizes.
409 set_min_gen0_size( 407 _min_gen0_size = bound_minus_alignment(_min_gen0_size, _min_heap_byte_size);
410 bound_minus_alignment(_min_gen0_size, min_heap_byte_size())); 408 _initial_gen0_size = bound_minus_alignment(_initial_gen0_size, _initial_heap_byte_size);
411 set_initial_gen0_size( 409 _max_gen0_size = bound_minus_alignment(_max_gen0_size, _max_heap_byte_size);
412 bound_minus_alignment(_initial_gen0_size, initial_heap_byte_size()));
413 set_max_gen0_size(
414 bound_minus_alignment(_max_gen0_size, max_heap_byte_size()));
415 410
416 // At this point all three sizes have been checked against the 411 // At this point all three sizes have been checked against the
417 // maximum sizes but have not been checked for consistency 412 // maximum sizes but have not been checked for consistency
418 // among the three. 413 // among the three.
419 414
420 // Final check min <= initial <= max 415 // Final check min <= initial <= max
421 set_min_gen0_size(MIN2(_min_gen0_size, _max_gen0_size)); 416 _min_gen0_size = MIN2(_min_gen0_size, _max_gen0_size);
422 set_initial_gen0_size( 417 _initial_gen0_size = MAX2(MIN2(_initial_gen0_size, _max_gen0_size), _min_gen0_size);
423 MAX2(MIN2(_initial_gen0_size, _max_gen0_size), _min_gen0_size)); 418 _min_gen0_size = MIN2(_min_gen0_size, _initial_gen0_size);
424 set_min_gen0_size(MIN2(_min_gen0_size, _initial_gen0_size));
425 } 419 }
426 420
427 if (PrintGCDetails && Verbose) { 421 if (PrintGCDetails && Verbose) {
428 gclog_or_tty->print_cr("1: Minimum gen0 " SIZE_FORMAT " Initial gen0 " 422 gclog_or_tty->print_cr("1: Minimum gen0 " SIZE_FORMAT " Initial gen0 "
429 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, 423 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT,
430 min_gen0_size(), initial_gen0_size(), max_gen0_size()); 424 _min_gen0_size, _initial_gen0_size, _max_gen0_size);
431 } 425 }
432 } 426 }
433 427
434 // Call this method during the sizing of the gen1 to make 428 // Call this method during the sizing of the gen1 to make
435 // adjustments to gen0 because of gen1 sizing policy. gen0 initially has 429 // adjustments to gen0 because of gen1 sizing policy. gen0 initially has
445 const size_t min_gen1_size) { 439 const size_t min_gen1_size) {
446 bool result = false; 440 bool result = false;
447 441
448 if ((*gen1_size_ptr + *gen0_size_ptr) > heap_size) { 442 if ((*gen1_size_ptr + *gen0_size_ptr) > heap_size) {
449 if ((heap_size < (*gen0_size_ptr + min_gen1_size)) && 443 if ((heap_size < (*gen0_size_ptr + min_gen1_size)) &&
450 (heap_size >= min_gen1_size + min_alignment())) { 444 (heap_size >= min_gen1_size + _min_alignment)) {
451 // Adjust gen0 down to accommodate min_gen1_size 445 // Adjust gen0 down to accommodate min_gen1_size
452 *gen0_size_ptr = heap_size - min_gen1_size; 446 *gen0_size_ptr = heap_size - min_gen1_size;
453 *gen0_size_ptr = 447 *gen0_size_ptr =
454 MAX2((uintx)align_size_down(*gen0_size_ptr, min_alignment()), 448 MAX2((uintx)align_size_down(*gen0_size_ptr, _min_alignment), _min_alignment);
455 min_alignment());
456 assert(*gen0_size_ptr > 0, "Min gen0 is too large"); 449 assert(*gen0_size_ptr > 0, "Min gen0 is too large");
457 result = true; 450 result = true;
458 } else { 451 } else {
459 *gen1_size_ptr = heap_size - *gen0_size_ptr; 452 *gen1_size_ptr = heap_size - *gen0_size_ptr;
460 *gen1_size_ptr = 453 *gen1_size_ptr =
461 MAX2((uintx)align_size_down(*gen1_size_ptr, min_alignment()), 454 MAX2((uintx)align_size_down(*gen1_size_ptr, _min_alignment), _min_alignment);
462 min_alignment());
463 } 455 }
464 } 456 }
465 return result; 457 return result;
466 } 458 }
467 459
478 // At this point the minimum, initial and maximum sizes 470 // At this point the minimum, initial and maximum sizes
479 // of the overall heap and of gen0 have been determined. 471 // of the overall heap and of gen0 have been determined.
480 // The maximum gen1 size can be determined from the maximum gen0 472 // The maximum gen1 size can be determined from the maximum gen0
481 // and maximum heap size since no explicit flags exits 473 // and maximum heap size since no explicit flags exits
482 // for setting the gen1 maximum. 474 // for setting the gen1 maximum.
483 _max_gen1_size = max_heap_byte_size() - _max_gen0_size; 475 _max_gen1_size = _max_heap_byte_size - _max_gen0_size;
484 _max_gen1_size = 476 _max_gen1_size =
485 MAX2((uintx)align_size_down(_max_gen1_size, min_alignment()), 477 MAX2((uintx)align_size_down(_max_gen1_size, _min_alignment), _min_alignment);
486 min_alignment());
487 // If no explicit command line flag has been set for the 478 // If no explicit command line flag has been set for the
488 // gen1 size, use what is left for gen1. 479 // gen1 size, use what is left for gen1.
489 if (FLAG_IS_DEFAULT(OldSize) || FLAG_IS_ERGO(OldSize)) { 480 if (FLAG_IS_DEFAULT(OldSize) || FLAG_IS_ERGO(OldSize)) {
490 // The user has not specified any value or ergonomics 481 // The user has not specified any value or ergonomics
491 // has chosen a value (which may or may not be consistent 482 // has chosen a value (which may or may not be consistent
492 // with the overall heap size). In either case make 483 // with the overall heap size). In either case make
493 // the minimum, maximum and initial sizes consistent 484 // the minimum, maximum and initial sizes consistent
494 // with the gen0 sizes and the overall heap sizes. 485 // with the gen0 sizes and the overall heap sizes.
495 assert(min_heap_byte_size() > _min_gen0_size, 486 assert(_min_heap_byte_size > _min_gen0_size,
496 "gen0 has an unexpected minimum size"); 487 "gen0 has an unexpected minimum size");
497 set_min_gen1_size(min_heap_byte_size() - min_gen0_size()); 488 _min_gen1_size = _min_heap_byte_size - _min_gen0_size;
498 set_min_gen1_size( 489 _min_gen1_size =
499 MAX2((uintx)align_size_down(_min_gen1_size, min_alignment()), 490 MAX2((uintx)align_size_down(_min_gen1_size, _min_alignment), _min_alignment);
500 min_alignment())); 491 _initial_gen1_size = _initial_heap_byte_size - _initial_gen0_size;
501 set_initial_gen1_size(initial_heap_byte_size() - initial_gen0_size()); 492 _initial_gen1_size =
502 set_initial_gen1_size( 493 MAX2((uintx)align_size_down(_initial_gen1_size, _min_alignment), _min_alignment);
503 MAX2((uintx)align_size_down(_initial_gen1_size, min_alignment()),
504 min_alignment()));
505
506 } else { 494 } else {
507 // It's been explicitly set on the command line. Use the 495 // It's been explicitly set on the command line. Use the
508 // OldSize and then determine the consequences. 496 // OldSize and then determine the consequences.
509 set_min_gen1_size(OldSize); 497 _min_gen1_size = OldSize;
510 set_initial_gen1_size(OldSize); 498 _initial_gen1_size = OldSize;
511 499
512 // If the user has explicitly set an OldSize that is inconsistent 500 // If the user has explicitly set an OldSize that is inconsistent
513 // with other command line flags, issue a warning. 501 // with other command line flags, issue a warning.
514 // The generation minimums and the overall heap mimimum should 502 // The generation minimums and the overall heap mimimum should
515 // be within one heap alignment. 503 // be within one heap alignment.
516 if ((_min_gen1_size + _min_gen0_size + min_alignment()) < 504 if ((_min_gen1_size + _min_gen0_size + _min_alignment) < _min_heap_byte_size) {
517 min_heap_byte_size()) {
518 warning("Inconsistency between minimum heap size and minimum " 505 warning("Inconsistency between minimum heap size and minimum "
519 "generation sizes: using minimum heap = " SIZE_FORMAT, 506 "generation sizes: using minimum heap = " SIZE_FORMAT,
520 min_heap_byte_size()); 507 _min_heap_byte_size);
521 } 508 }
522 if ((OldSize > _max_gen1_size)) { 509 if ((OldSize > _max_gen1_size)) {
523 warning("Inconsistency between maximum heap size and maximum " 510 warning("Inconsistency between maximum heap size and maximum "
524 "generation sizes: using maximum heap = " SIZE_FORMAT 511 "generation sizes: using maximum heap = " SIZE_FORMAT
525 " -XX:OldSize flag is being ignored", 512 " -XX:OldSize flag is being ignored",
526 max_heap_byte_size()); 513 _max_heap_byte_size);
527 } 514 }
528 // If there is an inconsistency between the OldSize and the minimum and/or 515 // If there is an inconsistency between the OldSize and the minimum and/or
529 // initial size of gen0, since OldSize was explicitly set, OldSize wins. 516 // initial size of gen0, since OldSize was explicitly set, OldSize wins.
530 if (adjust_gen0_sizes(&_min_gen0_size, &_min_gen1_size, 517 if (adjust_gen0_sizes(&_min_gen0_size, &_min_gen1_size,
531 min_heap_byte_size(), OldSize)) { 518 _min_heap_byte_size, OldSize)) {
532 if (PrintGCDetails && Verbose) { 519 if (PrintGCDetails && Verbose) {
533 gclog_or_tty->print_cr("2: Minimum gen0 " SIZE_FORMAT " Initial gen0 " 520 gclog_or_tty->print_cr("2: Minimum gen0 " SIZE_FORMAT " Initial gen0 "
534 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, 521 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT,
535 min_gen0_size(), initial_gen0_size(), max_gen0_size()); 522 _min_gen0_size, _initial_gen0_size, _max_gen0_size);
536 } 523 }
537 } 524 }
538 // Initial size 525 // Initial size
539 if (adjust_gen0_sizes(&_initial_gen0_size, &_initial_gen1_size, 526 if (adjust_gen0_sizes(&_initial_gen0_size, &_initial_gen1_size,
540 initial_heap_byte_size(), OldSize)) { 527 _initial_heap_byte_size, OldSize)) {
541 if (PrintGCDetails && Verbose) { 528 if (PrintGCDetails && Verbose) {
542 gclog_or_tty->print_cr("3: Minimum gen0 " SIZE_FORMAT " Initial gen0 " 529 gclog_or_tty->print_cr("3: Minimum gen0 " SIZE_FORMAT " Initial gen0 "
543 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, 530 SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT,
544 min_gen0_size(), initial_gen0_size(), max_gen0_size()); 531 _min_gen0_size, _initial_gen0_size, _max_gen0_size);
545 } 532 }
546 } 533 }
547 } 534 }
548 // Enforce the maximum gen1 size. 535 // Enforce the maximum gen1 size.
549 set_min_gen1_size(MIN2(_min_gen1_size, _max_gen1_size)); 536 _min_gen1_size = MIN2(_min_gen1_size, _max_gen1_size);
550 537
551 // Check that min gen1 <= initial gen1 <= max gen1 538 // Check that min gen1 <= initial gen1 <= max gen1
552 set_initial_gen1_size(MAX2(_initial_gen1_size, _min_gen1_size)); 539 _initial_gen1_size = MAX2(_initial_gen1_size, _min_gen1_size);
553 set_initial_gen1_size(MIN2(_initial_gen1_size, _max_gen1_size)); 540 _initial_gen1_size = MIN2(_initial_gen1_size, _max_gen1_size);
554 541
555 if (PrintGCDetails && Verbose) { 542 if (PrintGCDetails && Verbose) {
556 gclog_or_tty->print_cr("Minimum gen1 " SIZE_FORMAT " Initial gen1 " 543 gclog_or_tty->print_cr("Minimum gen1 " SIZE_FORMAT " Initial gen1 "
557 SIZE_FORMAT " Maximum gen1 " SIZE_FORMAT, 544 SIZE_FORMAT " Maximum gen1 " SIZE_FORMAT,
558 min_gen1_size(), initial_gen1_size(), max_gen1_size()); 545 _min_gen1_size, _initial_gen1_size, _max_gen1_size);
559 } 546 }
560 } 547 }
561 548
562 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size, 549 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size,
563 bool is_tlab, 550 bool is_tlab,