< prev index next >

src/hotspot/share/runtime/arguments.cpp

Print this page




1611 
1612 size_t Arguments::max_heap_for_compressed_oops() {
1613   // Avoid sign flip.
1614   assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size");
1615   // We need to fit both the NULL page and the heap into the memory budget, while
1616   // keeping alignment constraints of the heap. To guarantee the latter, as the
1617   // NULL page is located before the heap, we pad the NULL page to the conservative
1618   // maximum alignment that the GC may ever impose upon the heap.
1619   size_t displacement_due_to_null_page = align_up((size_t)os::vm_page_size(),
1620                                                   _conservative_max_heap_alignment);
1621 
1622   LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page);
1623   NOT_LP64(ShouldNotReachHere(); return 0);
1624 }
1625 
1626 void Arguments::set_use_compressed_oops() {
1627 #ifndef ZERO
1628 #ifdef _LP64
1629   // MaxHeapSize is not set up properly at this point, but
1630   // the only value that can override MaxHeapSize if we are
1631   // to use UseCompressedOops is InitialHeapSize.
1632   size_t max_heap_size = MAX2(MaxHeapSize, InitialHeapSize);
1633 
1634   if (max_heap_size <= max_heap_for_compressed_oops()) {
1635 #if !defined(COMPILER1) || defined(TIERED)
1636     if (FLAG_IS_DEFAULT(UseCompressedOops)) {
1637       FLAG_SET_ERGO(UseCompressedOops, true);
1638     }
1639 #endif
1640   } else {
1641     if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
1642       warning("Max heap size too large for Compressed Oops");
1643       FLAG_SET_DEFAULT(UseCompressedOops, false);
1644       FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1645     }
1646   }
1647 #endif // _LP64
1648 #endif // ZERO
1649 }
1650 
1651 
1652 // NOTE: set_use_compressed_klass_ptrs() must be called after calling


1773                                      HeapBaseMinAddress);
1774           FLAG_SET_ERGO(HeapBaseMinAddress, DefaultHeapBaseMinAddress);
1775         }
1776       }
1777 
1778       if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) {
1779         // Heap should be above HeapBaseMinAddress to get zero based compressed oops
1780         // but it should be not less than default MaxHeapSize.
1781         max_coop_heap -= HeapBaseMinAddress;
1782       }
1783       reasonable_max = MIN2(reasonable_max, max_coop_heap);
1784     }
1785     reasonable_max = limit_by_allocatable_memory(reasonable_max);
1786 
1787     if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
1788       // An initial heap size was specified on the command line,
1789       // so be sure that the maximum size is consistent.  Done
1790       // after call to limit_by_allocatable_memory because that
1791       // method might reduce the allocation size.
1792       reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);


1793     }
1794 
1795     log_trace(gc, heap)("  Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max);
1796     FLAG_SET_ERGO(MaxHeapSize, (size_t)reasonable_max);
1797   }
1798 
1799   // If the minimum or initial heap_size have not been set or requested to be set
1800   // ergonomically, set them accordingly.
1801   if (InitialHeapSize == 0 || MinHeapSize == 0) {
1802     julong reasonable_minimum = (julong)(OldSize + NewSize);
1803 
1804     reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
1805 
1806     reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
1807 
1808     if (InitialHeapSize == 0) {
1809       julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100);
1810 
1811       reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)MinHeapSize);
1812       reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
1813 
1814       reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
1815 
1816       log_trace(gc, heap)("  Initial heap size " SIZE_FORMAT, (size_t)reasonable_initial);
1817       FLAG_SET_ERGO(InitialHeapSize, (size_t)reasonable_initial);

1818     }
1819     // If the minimum heap size has not been set (via -Xms),
1820     // synchronize with InitialHeapSize to avoid errors with the default value.
1821     if (MinHeapSize == 0) {
1822       MinHeapSize = MIN2((size_t)reasonable_minimum, InitialHeapSize);
1823       log_trace(gc, heap)("  Minimum heap size " SIZE_FORMAT, MinHeapSize);
1824     }
1825   }
1826 }
1827 
1828 // This option inspects the machine and attempts to set various
1829 // parameters to be optimal for long-running, memory allocation
1830 // intensive jobs.  It is intended for machines with large
1831 // amounts of cpu and memory.
1832 jint Arguments::set_aggressive_heap_flags() {
1833   // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
1834   // VM, but we may not be able to represent the total physical memory
1835   // available (like having 8gb of memory on a box but using a 32bit VM).
1836   // Thus, we need to make sure we're using a julong for intermediate
1837   // calculations.
1838   julong initHeapSize;
1839   julong total_memory = os::physical_memory();
1840 
1841   if (total_memory < (julong) 256 * M) {
1842     jio_fprintf(defaultStream::error_stream(),


1844     vm_exit(1);
1845   }
1846 
1847   // The heap size is half of available memory, or (at most)
1848   // all of possible memory less 160mb (leaving room for the OS
1849   // when using ISM).  This is the maximum; because adaptive sizing
1850   // is turned on below, the actual space used may be smaller.
1851 
1852   initHeapSize = MIN2(total_memory / (julong) 2,
1853           total_memory - (julong) 160 * M);
1854 
1855   initHeapSize = limit_by_allocatable_memory(initHeapSize);
1856 
1857   if (FLAG_IS_DEFAULT(MaxHeapSize)) {
1858     if (FLAG_SET_CMDLINE(MaxHeapSize, initHeapSize) != JVMFlag::SUCCESS) {
1859       return JNI_EINVAL;
1860     }
1861     if (FLAG_SET_CMDLINE(InitialHeapSize, initHeapSize) != JVMFlag::SUCCESS) {
1862       return JNI_EINVAL;
1863     }
1864     // Currently the minimum size and the initial heap sizes are the same.
1865     MinHeapSize = initHeapSize;

1866   }
1867   if (FLAG_IS_DEFAULT(NewSize)) {
1868     // Make the young generation 3/8ths of the total heap.
1869     if (FLAG_SET_CMDLINE(NewSize,
1870             ((julong) MaxHeapSize / (julong) 8) * (julong) 3) != JVMFlag::SUCCESS) {
1871       return JNI_EINVAL;
1872     }
1873     if (FLAG_SET_CMDLINE(MaxNewSize, NewSize) != JVMFlag::SUCCESS) {
1874       return JNI_EINVAL;
1875     }
1876   }
1877 
1878 #if !defined(_ALLBSD_SOURCE) && !defined(AIX)  // UseLargePages is not yet supported on BSD and AIX.
1879   FLAG_SET_DEFAULT(UseLargePages, true);
1880 #endif
1881 
1882   // Increase some data structure sizes for efficiency
1883   if (FLAG_SET_CMDLINE(BaseFootPrintEstimate, MaxHeapSize) != JVMFlag::SUCCESS) {
1884     return JNI_EINVAL;
1885   }


2536         return JNI_EINVAL;
2537       }
2538     // -Xmn for compatibility with other JVM vendors
2539     } else if (match_option(option, "-Xmn", &tail)) {
2540       julong long_initial_young_size = 0;
2541       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2542       if (errcode != arg_in_range) {
2543         jio_fprintf(defaultStream::error_stream(),
2544                     "Invalid initial young generation size: %s\n", option->optionString);
2545         describe_range_error(errcode);
2546         return JNI_EINVAL;
2547       }
2548       if (FLAG_SET_CMDLINE(MaxNewSize, (size_t)long_initial_young_size) != JVMFlag::SUCCESS) {
2549         return JNI_EINVAL;
2550       }
2551       if (FLAG_SET_CMDLINE(NewSize, (size_t)long_initial_young_size) != JVMFlag::SUCCESS) {
2552         return JNI_EINVAL;
2553       }
2554     // -Xms
2555     } else if (match_option(option, "-Xms", &tail)) {
2556       julong long_initial_heap_size = 0;
2557       // an initial heap size of 0 means automatically determine
2558       ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0);
2559       if (errcode != arg_in_range) {
2560         jio_fprintf(defaultStream::error_stream(),
2561                     "Invalid initial heap size: %s\n", option->optionString);
2562         describe_range_error(errcode);
2563         return JNI_EINVAL;
2564       }
2565       MinHeapSize = (size_t)long_initial_heap_size;
2566       // Currently the minimum size and the initial heap sizes are the same.
2567       // Can be overridden with -XX:InitialHeapSize.
2568       if (FLAG_SET_CMDLINE(InitialHeapSize, (size_t)long_initial_heap_size) != JVMFlag::SUCCESS) {
2569         return JNI_EINVAL;
2570       }
2571     // -Xmx
2572     } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) {
2573       julong long_max_heap_size = 0;
2574       ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
2575       if (errcode != arg_in_range) {
2576         jio_fprintf(defaultStream::error_stream(),
2577                     "Invalid maximum heap size: %s\n", option->optionString);
2578         describe_range_error(errcode);
2579         return JNI_EINVAL;
2580       }
2581       if (FLAG_SET_CMDLINE(MaxHeapSize, (size_t)long_max_heap_size) != JVMFlag::SUCCESS) {
2582         return JNI_EINVAL;
2583       }
2584     // Xmaxf
2585     } else if (match_option(option, "-Xmaxf", &tail)) {
2586       char* err;
2587       int maxf = (int)(strtod(tail, &err) * 100);
2588       if (*err != '\0' || *tail == '\0') {




1611 
1612 size_t Arguments::max_heap_for_compressed_oops() {
1613   // Avoid sign flip.
1614   assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size");
1615   // We need to fit both the NULL page and the heap into the memory budget, while
1616   // keeping alignment constraints of the heap. To guarantee the latter, as the
1617   // NULL page is located before the heap, we pad the NULL page to the conservative
1618   // maximum alignment that the GC may ever impose upon the heap.
1619   size_t displacement_due_to_null_page = align_up((size_t)os::vm_page_size(),
1620                                                   _conservative_max_heap_alignment);
1621 
1622   LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page);
1623   NOT_LP64(ShouldNotReachHere(); return 0);
1624 }
1625 
1626 void Arguments::set_use_compressed_oops() {
1627 #ifndef ZERO
1628 #ifdef _LP64
1629   // MaxHeapSize is not set up properly at this point, but
1630   // the only value that can override MaxHeapSize if we are
1631   // to use UseCompressedOops are InitialHeapSize and MinHeapSize.
1632   size_t max_heap_size = MAX3(MaxHeapSize, InitialHeapSize, MinHeapSize);
1633 
1634   if (max_heap_size <= max_heap_for_compressed_oops()) {
1635 #if !defined(COMPILER1) || defined(TIERED)
1636     if (FLAG_IS_DEFAULT(UseCompressedOops)) {
1637       FLAG_SET_ERGO(UseCompressedOops, true);
1638     }
1639 #endif
1640   } else {
1641     if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
1642       warning("Max heap size too large for Compressed Oops");
1643       FLAG_SET_DEFAULT(UseCompressedOops, false);
1644       FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1645     }
1646   }
1647 #endif // _LP64
1648 #endif // ZERO
1649 }
1650 
1651 
1652 // NOTE: set_use_compressed_klass_ptrs() must be called after calling


1773                                      HeapBaseMinAddress);
1774           FLAG_SET_ERGO(HeapBaseMinAddress, DefaultHeapBaseMinAddress);
1775         }
1776       }
1777 
1778       if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) {
1779         // Heap should be above HeapBaseMinAddress to get zero based compressed oops
1780         // but it should be not less than default MaxHeapSize.
1781         max_coop_heap -= HeapBaseMinAddress;
1782       }
1783       reasonable_max = MIN2(reasonable_max, max_coop_heap);
1784     }
1785     reasonable_max = limit_by_allocatable_memory(reasonable_max);
1786 
1787     if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
1788       // An initial heap size was specified on the command line,
1789       // so be sure that the maximum size is consistent.  Done
1790       // after call to limit_by_allocatable_memory because that
1791       // method might reduce the allocation size.
1792       reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
1793     } else if (!FLAG_IS_DEFAULT(MinHeapSize)) {
1794       reasonable_max = MAX2(reasonable_max, (julong)MinHeapSize);
1795     }
1796 
1797     log_trace(gc, heap)("  Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max);
1798     FLAG_SET_ERGO(MaxHeapSize, (size_t)reasonable_max);
1799   }
1800 
1801   // If the minimum or initial heap_size have not been set or requested to be set
1802   // ergonomically, set them accordingly.
1803   if (InitialHeapSize == 0 || MinHeapSize == 0) {
1804     julong reasonable_minimum = (julong)(OldSize + NewSize);
1805 
1806     reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
1807 
1808     reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
1809 
1810     if (InitialHeapSize == 0) {
1811       julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100);
1812 
1813       reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)MinHeapSize);
1814       reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
1815 
1816       reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
1817 

1818       FLAG_SET_ERGO(InitialHeapSize, (size_t)reasonable_initial);
1819       log_trace(gc, heap)("  Initial heap size " SIZE_FORMAT, InitialHeapSize);
1820     }
1821     // If the minimum heap size has not been set (via -Xms or -XX:MinHeapSize),
1822     // synchronize with InitialHeapSize to avoid errors with the default value.
1823     if (MinHeapSize == 0) {
1824       FLAG_SET_ERGO(MinHeapSize, MIN2((size_t)reasonable_minimum, InitialHeapSize));
1825       log_trace(gc, heap)("  Minimum heap size " SIZE_FORMAT, MinHeapSize);
1826     }
1827   }
1828 }
1829 
1830 // This option inspects the machine and attempts to set various
1831 // parameters to be optimal for long-running, memory allocation
1832 // intensive jobs.  It is intended for machines with large
1833 // amounts of cpu and memory.
1834 jint Arguments::set_aggressive_heap_flags() {
1835   // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
1836   // VM, but we may not be able to represent the total physical memory
1837   // available (like having 8gb of memory on a box but using a 32bit VM).
1838   // Thus, we need to make sure we're using a julong for intermediate
1839   // calculations.
1840   julong initHeapSize;
1841   julong total_memory = os::physical_memory();
1842 
1843   if (total_memory < (julong) 256 * M) {
1844     jio_fprintf(defaultStream::error_stream(),


1846     vm_exit(1);
1847   }
1848 
1849   // The heap size is half of available memory, or (at most)
1850   // all of possible memory less 160mb (leaving room for the OS
1851   // when using ISM).  This is the maximum; because adaptive sizing
1852   // is turned on below, the actual space used may be smaller.
1853 
1854   initHeapSize = MIN2(total_memory / (julong) 2,
1855           total_memory - (julong) 160 * M);
1856 
1857   initHeapSize = limit_by_allocatable_memory(initHeapSize);
1858 
1859   if (FLAG_IS_DEFAULT(MaxHeapSize)) {
1860     if (FLAG_SET_CMDLINE(MaxHeapSize, initHeapSize) != JVMFlag::SUCCESS) {
1861       return JNI_EINVAL;
1862     }
1863     if (FLAG_SET_CMDLINE(InitialHeapSize, initHeapSize) != JVMFlag::SUCCESS) {
1864       return JNI_EINVAL;
1865     }
1866     if (FLAG_SET_CMDLINE(MinHeapSize, initHeapSize) != JVMFlag::SUCCESS) {
1867       return JNI_EINVAL;
1868     }
1869   }
1870   if (FLAG_IS_DEFAULT(NewSize)) {
1871     // Make the young generation 3/8ths of the total heap.
1872     if (FLAG_SET_CMDLINE(NewSize,
1873             ((julong) MaxHeapSize / (julong) 8) * (julong) 3) != JVMFlag::SUCCESS) {
1874       return JNI_EINVAL;
1875     }
1876     if (FLAG_SET_CMDLINE(MaxNewSize, NewSize) != JVMFlag::SUCCESS) {
1877       return JNI_EINVAL;
1878     }
1879   }
1880 
1881 #if !defined(_ALLBSD_SOURCE) && !defined(AIX)  // UseLargePages is not yet supported on BSD and AIX.
1882   FLAG_SET_DEFAULT(UseLargePages, true);
1883 #endif
1884 
1885   // Increase some data structure sizes for efficiency
1886   if (FLAG_SET_CMDLINE(BaseFootPrintEstimate, MaxHeapSize) != JVMFlag::SUCCESS) {
1887     return JNI_EINVAL;
1888   }


2539         return JNI_EINVAL;
2540       }
2541     // -Xmn for compatibility with other JVM vendors
2542     } else if (match_option(option, "-Xmn", &tail)) {
2543       julong long_initial_young_size = 0;
2544       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2545       if (errcode != arg_in_range) {
2546         jio_fprintf(defaultStream::error_stream(),
2547                     "Invalid initial young generation size: %s\n", option->optionString);
2548         describe_range_error(errcode);
2549         return JNI_EINVAL;
2550       }
2551       if (FLAG_SET_CMDLINE(MaxNewSize, (size_t)long_initial_young_size) != JVMFlag::SUCCESS) {
2552         return JNI_EINVAL;
2553       }
2554       if (FLAG_SET_CMDLINE(NewSize, (size_t)long_initial_young_size) != JVMFlag::SUCCESS) {
2555         return JNI_EINVAL;
2556       }
2557     // -Xms
2558     } else if (match_option(option, "-Xms", &tail)) {
2559       julong size = 0;
2560       // an initial heap size of 0 means automatically determine
2561       ArgsRange errcode = parse_memory_size(tail, &size, 0);
2562       if (errcode != arg_in_range) {
2563         jio_fprintf(defaultStream::error_stream(),
2564                     "Invalid initial heap size: %s\n", option->optionString);
2565         describe_range_error(errcode);
2566         return JNI_EINVAL;
2567       }
2568       if (FLAG_SET_CMDLINE(MinHeapSize, (size_t)size) != JVMFlag::SUCCESS) {
2569         return JNI_EINVAL;
2570       }
2571       if (FLAG_SET_CMDLINE(InitialHeapSize, (size_t)size) != JVMFlag::SUCCESS) {
2572         return JNI_EINVAL;
2573       }
2574     // -Xmx
2575     } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) {
2576       julong long_max_heap_size = 0;
2577       ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
2578       if (errcode != arg_in_range) {
2579         jio_fprintf(defaultStream::error_stream(),
2580                     "Invalid maximum heap size: %s\n", option->optionString);
2581         describe_range_error(errcode);
2582         return JNI_EINVAL;
2583       }
2584       if (FLAG_SET_CMDLINE(MaxHeapSize, (size_t)long_max_heap_size) != JVMFlag::SUCCESS) {
2585         return JNI_EINVAL;
2586       }
2587     // Xmaxf
2588     } else if (match_option(option, "-Xmaxf", &tail)) {
2589       char* err;
2590       int maxf = (int)(strtod(tail, &err) * 100);
2591       if (*err != '\0' || *tail == '\0') {


< prev index next >