239 |
239 |
240 calculated_heapsize = align_size_up(calculated_heapsize, max_alignment()); |
240 calculated_heapsize = align_size_up(calculated_heapsize, max_alignment()); |
241 MaxHeapSize = calculated_heapsize; |
241 MaxHeapSize = calculated_heapsize; |
242 InitialHeapSize = calculated_heapsize; |
242 InitialHeapSize = calculated_heapsize; |
243 } |
243 } |
|
244 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment()); |
|
245 |
|
246 // adjust max heap size if necessary |
|
247 if (NewSize + OldSize > MaxHeapSize) { |
|
248 if (FLAG_IS_CMDLINE(MaxHeapSize)) { |
|
249 // somebody set a maximum heap size with the intention that we should not |
|
250 // exceed it. Adjust New/OldSize as necessary. |
|
251 uintx calculated_size = NewSize + OldSize; |
|
252 double shrink_factor = (double) MaxHeapSize / calculated_size; |
|
253 // align |
|
254 NewSize = align_size_down((uintx) (NewSize * shrink_factor), min_alignment()); |
|
255 // OldSize is already aligned because above we aligned MaxHeapSize to |
|
256 // max_alignment(), and we just made sure that NewSize is aligned to |
|
257 // min_alignment(). In initialize_flags() we verified that max_alignment() |
|
258 // is a multiple of min_alignment(). |
|
259 OldSize = MaxHeapSize - NewSize; |
|
260 } else { |
|
261 MaxHeapSize = NewSize + OldSize; |
|
262 } |
|
263 } |
|
264 // need to do this again |
244 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment()); |
265 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment()); |
245 |
266 |
246 // adjust max heap size if necessary |
267 // adjust max heap size if necessary |
247 if (NewSize + OldSize > MaxHeapSize) { |
268 if (NewSize + OldSize > MaxHeapSize) { |
248 if (FLAG_IS_CMDLINE(MaxHeapSize)) { |
269 if (FLAG_IS_CMDLINE(MaxHeapSize)) { |
729 // we can to reclaim memory. Force collection of soft references. Force |
750 // we can to reclaim memory. Force collection of soft references. Force |
730 // a complete compaction of the heap. Any additional methods for finding |
751 // a complete compaction of the heap. Any additional methods for finding |
731 // free memory should be here, especially if they are expensive. If this |
752 // free memory should be here, especially if they are expensive. If this |
732 // attempt fails, an OOM exception will be thrown. |
753 // attempt fails, an OOM exception will be thrown. |
733 { |
754 { |
734 IntFlagSetting flag_change(MarkSweepAlwaysCompactCount, 1); // Make sure the heap is fully compacted |
755 UIntFlagSetting flag_change(MarkSweepAlwaysCompactCount, 1); // Make sure the heap is fully compacted |
735 |
756 |
736 gch->do_collection(true /* full */, |
757 gch->do_collection(true /* full */, |
737 true /* clear_all_soft_refs */, |
758 true /* clear_all_soft_refs */, |
738 size /* size */, |
759 size /* size */, |
739 is_tlab /* is_tlab */, |
760 is_tlab /* is_tlab */, |
854 MarkSweepPolicy::MarkSweepPolicy() { |
875 MarkSweepPolicy::MarkSweepPolicy() { |
855 initialize_all(); |
876 initialize_all(); |
856 } |
877 } |
857 |
878 |
858 void MarkSweepPolicy::initialize_generations() { |
879 void MarkSweepPolicy::initialize_generations() { |
859 _generations = new GenerationSpecPtr[number_of_generations()]; |
880 _generations = NEW_C_HEAP_ARRAY3(GenerationSpecPtr, number_of_generations(), mtGC, 0, AllocFailStrategy::RETURN_NULL); |
860 if (_generations == NULL) |
881 if (_generations == NULL) |
861 vm_exit_during_initialization("Unable to allocate gen spec"); |
882 vm_exit_during_initialization("Unable to allocate gen spec"); |
862 |
883 |
863 if (UseParNewGC) { |
884 if (UseParNewGC) { |
864 _generations[0] = new GenerationSpec(Generation::ParNew, _initial_gen0_size, _max_gen0_size); |
885 _generations[0] = new GenerationSpec(Generation::ParNew, _initial_gen0_size, _max_gen0_size); |