@@ -1655,11 +1655,18 @@ jint Arguments::set_ergonomics_flags() {
1655
1655
return JNI_OK;
1656
1656
}
1657
1657
1658
- julong Arguments::limit_by_allocatable_memory (julong limit) {
1658
+ julong Arguments::limit_heap_by_allocatable_memory (julong limit) {
1659
1659
julong max_allocatable;
1660
1660
julong result = limit;
1661
1661
if (os::has_allocatable_memory_limit (&max_allocatable)) {
1662
- result = MIN2 (result, max_allocatable / MaxVirtMemFraction);
1662
+ // The AggressiveHeap check is a temporary workaround to avoid calling
1663
+ // GCarguments::heap_virtual_to_physical_ratio() before a GC has been
1664
+ // selected. This works because AggressiveHeap implies UseParallelGC
1665
+ // where we know the ratio will be 1. Once the AggressiveHeap option is
1666
+ // removed, this can be cleaned up.
1667
+ julong heap_virtual_to_physical_ratio = (AggressiveHeap ? 1 : GCConfig::arguments ()->heap_virtual_to_physical_ratio ());
1668
+ julong fraction = MaxVirtMemFraction * heap_virtual_to_physical_ratio;
1669
+ result = MIN2 (result, max_allocatable / fraction);
1663
1670
}
1664
1671
return result;
1665
1672
}
@@ -1775,12 +1782,12 @@ void Arguments::set_heap_size() {
1775
1782
}
1776
1783
#endif // _LP64
1777
1784
1778
- reasonable_max = limit_by_allocatable_memory (reasonable_max);
1785
+ reasonable_max = limit_heap_by_allocatable_memory (reasonable_max);
1779
1786
1780
1787
if (!FLAG_IS_DEFAULT (InitialHeapSize)) {
1781
1788
// An initial heap size was specified on the command line,
1782
1789
// so be sure that the maximum size is consistent. Done
1783
- // after call to limit_by_allocatable_memory because that
1790
+ // after call to limit_heap_by_allocatable_memory because that
1784
1791
// method might reduce the allocation size.
1785
1792
reasonable_max = MAX2 (reasonable_max, (julong)InitialHeapSize);
1786
1793
} else if (!FLAG_IS_DEFAULT (MinHeapSize)) {
@@ -1798,11 +1805,11 @@ void Arguments::set_heap_size() {
1798
1805
1799
1806
reasonable_minimum = MIN2 (reasonable_minimum, (julong)MaxHeapSize);
1800
1807
1801
- reasonable_minimum = limit_by_allocatable_memory (reasonable_minimum);
1808
+ reasonable_minimum = limit_heap_by_allocatable_memory (reasonable_minimum);
1802
1809
1803
1810
if (InitialHeapSize == 0 ) {
1804
1811
julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100 );
1805
- reasonable_initial = limit_by_allocatable_memory (reasonable_initial);
1812
+ reasonable_initial = limit_heap_by_allocatable_memory (reasonable_initial);
1806
1813
1807
1814
reasonable_initial = MAX3 (reasonable_initial, reasonable_minimum, (julong)MinHeapSize);
1808
1815
reasonable_initial = MIN2 (reasonable_initial, (julong)MaxHeapSize);
@@ -1846,7 +1853,7 @@ jint Arguments::set_aggressive_heap_flags() {
1846
1853
initHeapSize = MIN2 (total_memory / (julong) 2 ,
1847
1854
total_memory - (julong) 160 * M);
1848
1855
1849
- initHeapSize = limit_by_allocatable_memory (initHeapSize);
1856
+ initHeapSize = limit_heap_by_allocatable_memory (initHeapSize);
1850
1857
1851
1858
if (FLAG_IS_DEFAULT (MaxHeapSize)) {
1852
1859
if (FLAG_SET_CMDLINE (MaxHeapSize, initHeapSize) != JVMFlag::SUCCESS) {
0 commit comments