src/hotspot/share/runtime/arguments.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff src/hotspot/share/runtime

src/hotspot/share/runtime/arguments.cpp

Print this page




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


1662 #endif // !ZERO
1663 }
1664 
1665 void Arguments::set_conservative_max_heap_alignment() {
1666   // The conservative maximum required alignment for the heap is the maximum of
1667   // the alignments imposed by several sources: any requirements from the heap
1668   // itself, the collector policy and the maximum page size we may run the VM
1669   // with.
1670   size_t heap_alignment = GCConfig::arguments()->conservative_max_heap_alignment();
1671   _conservative_max_heap_alignment = MAX4(heap_alignment,
1672                                           (size_t)os::vm_allocation_granularity(),
1673                                           os::max_page_size(),
1674                                           CollectorPolicy::compute_heap_alignment());
1675 }
1676 
1677 jint Arguments::set_ergonomics_flags() {
1678   GCConfig::initialize();
1679 
1680   set_conservative_max_heap_alignment();
1681 
1682 #ifndef ZERO
1683 #ifdef _LP64
1684   set_use_compressed_oops();
1685 
1686   // set_use_compressed_klass_ptrs() must be called after calling
1687   // set_use_compressed_oops().
1688   set_use_compressed_klass_ptrs();
1689 
1690   // Also checks that certain machines are slower with compressed oops
1691   // in vm_version initialization code.
1692 #endif // _LP64
1693 #endif // !ZERO
1694 
1695   return JNI_OK;
1696 }
1697 
1698 julong Arguments::limit_by_allocatable_memory(julong limit) {
1699   julong max_allocatable;
1700   julong result = limit;
1701   if (os::has_allocatable_memory_limit(&max_allocatable)) {
1702     result = MIN2(result, max_allocatable / MaxVirtMemFraction);
1703   }
1704   return result;
1705 }
1706 
1707 // Use static initialization to get the default before parsing
1708 static const size_t DefaultHeapBaseMinAddress = HeapBaseMinAddress;
1709 
1710 void Arguments::set_heap_size() {
1711   julong phys_mem =
1712     FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM)
1713                             : (julong)MaxRAM;
1714 


1727 
1728   // If the maximum heap size has not been set with -Xmx,
1729   // then set it as fraction of the size of physical memory,
1730   // respecting the maximum and minimum sizes of the heap.
1731   if (FLAG_IS_DEFAULT(MaxHeapSize)) {
1732     julong reasonable_max = (julong)((phys_mem * MaxRAMPercentage) / 100);
1733     const julong reasonable_min = (julong)((phys_mem * MinRAMPercentage) / 100);
1734     if (reasonable_min < MaxHeapSize) {
1735       // Small physical memory, so use a minimum fraction of it for the heap
1736       reasonable_max = reasonable_min;
1737     } else {
1738       // Not-small physical memory, so require a heap at least
1739       // as large as MaxHeapSize
1740       reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
1741     }
1742 
1743     if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
1744       // Limit the heap size to ErgoHeapSizeLimit
1745       reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit);
1746     }





1747     if (UseCompressedOops) {
1748       // Limit the heap size to the maximum possible when using compressed oops
1749       julong max_coop_heap = (julong)max_heap_for_compressed_oops();
1750 
1751       // HeapBaseMinAddress can be greater than default but not less than.
1752       if (!FLAG_IS_DEFAULT(HeapBaseMinAddress)) {
1753         if (HeapBaseMinAddress < DefaultHeapBaseMinAddress) {
1754           // matches compressed oops printing flags
1755           log_debug(gc, heap, coops)("HeapBaseMinAddress must be at least " SIZE_FORMAT
1756                                      " (" SIZE_FORMAT "G) which is greater than value given " SIZE_FORMAT,
1757                                      DefaultHeapBaseMinAddress,
1758                                      DefaultHeapBaseMinAddress/G,
1759                                      HeapBaseMinAddress);
1760           FLAG_SET_ERGO(size_t, HeapBaseMinAddress, DefaultHeapBaseMinAddress);
1761         }
1762       }
1763 
1764       if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) {
1765         // Heap should be above HeapBaseMinAddress to get zero based compressed oops
1766         // but it should be not less than default MaxHeapSize.
1767         max_coop_heap -= HeapBaseMinAddress;
1768       }
1769       reasonable_max = MIN2(reasonable_max, max_coop_heap);
1770     }
1771     reasonable_max = limit_by_allocatable_memory(reasonable_max);
1772 
1773     if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
1774       // An initial heap size was specified on the command line,
1775       // so be sure that the maximum size is consistent.  Done
1776       // after call to limit_by_allocatable_memory because that
1777       // method might reduce the allocation size.
1778       reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
1779     }
1780 
1781     log_trace(gc, heap)("  Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max);
1782     FLAG_SET_ERGO(size_t, MaxHeapSize, (size_t)reasonable_max);



1783   }
1784 
1785   // If the minimum or initial heap_size have not been set or requested to be set
1786   // ergonomically, set them accordingly.
1787   if (InitialHeapSize == 0 || min_heap_size() == 0) {
1788     julong reasonable_minimum = (julong)(OldSize + NewSize);
1789 
1790     reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
1791 
1792     reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
1793 
1794     if (InitialHeapSize == 0) {
1795       julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100);
1796 
1797       reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size());
1798       reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
1799 
1800       reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
1801 
1802       log_trace(gc, heap)("  Initial heap size " SIZE_FORMAT, (size_t)reasonable_initial);


3842     return JNI_ERR;
3843   }
3844   if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) ||
3845       log_is_enabled(Info, cds)) {
3846     warning("Shared spaces are not supported in this VM");
3847     FLAG_SET_DEFAULT(UseSharedSpaces, false);
3848     LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(cds));
3849   }
3850   no_shared_spaces("CDS Disabled");
3851 #endif // INCLUDE_CDS
3852 
3853   return JNI_OK;
3854 }
3855 
3856 jint Arguments::apply_ergo() {
3857   // Set flags based on ergonomics.
3858   jint result = set_ergonomics_flags();
3859   if (result != JNI_OK) return result;
3860 
3861   // Set heap size based on available physical memory

3862   set_heap_size();




3863 
3864   GCConfig::arguments()->initialize();
3865 
3866   set_shared_spaces_flags();
3867 
3868   // Initialize Metaspace flags and alignments
3869   Metaspace::ergo_initialize();
3870 
3871   // Set compiler flags after GC is selected and GC specific
3872   // flags (LoopStripMiningIter) are set.
3873   CompilerConfig::ergo_initialize();
3874 
3875   // Set bytecode rewriting flags
3876   set_bytecode_flags();
3877 
3878   // Set flags if aggressive optimization flags are enabled
3879   jint code = set_aggressive_opts_flags();
3880   if (code != JNI_OK) {
3881     return code;
3882   }




1591 
1592   if (SurvivorAlignmentInBytes == 0) {
1593     SurvivorAlignmentInBytes = ObjectAlignmentInBytes;
1594   }
1595 }
1596 
1597 size_t Arguments::max_heap_for_compressed_oops() {
1598   // Avoid sign flip.
1599   assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size");
1600   // We need to fit both the NULL page and the heap into the memory budget, while
1601   // keeping alignment constraints of the heap. To guarantee the latter, as the
1602   // NULL page is located before the heap, we pad the NULL page to the conservative
1603   // maximum alignment that the GC may ever impose upon the heap.
1604   size_t displacement_due_to_null_page = align_up((size_t)os::vm_page_size(),
1605                                                   _conservative_max_heap_alignment);
1606 
1607   LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page);
1608   NOT_LP64(ShouldNotReachHere(); return 0);
1609 }
1610 
1611 void Arguments::set_use_compressed_oops(size_t max_heap_size) {
1612 #ifndef ZERO
1613 #ifdef _LP64





1614   if (max_heap_size <= max_heap_for_compressed_oops()) {
1615 #if !defined(COMPILER1) || defined(TIERED)
1616     if (FLAG_IS_DEFAULT(UseCompressedOops)) {
1617       FLAG_SET_ERGO(bool, UseCompressedOops, true);
1618     }
1619 #endif
1620   } else {
1621     if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
1622       warning("Max heap size too large for Compressed Oops");
1623       FLAG_SET_DEFAULT(UseCompressedOops, false);
1624       FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1625     }
1626   }
1627 #endif // _LP64
1628 #endif // ZERO
1629 }
1630 
1631 
1632 // NOTE: set_use_compressed_klass_ptrs() must be called after calling
1633 // set_use_compressed_oops().


1657 #endif // !ZERO
1658 }
1659 
1660 void Arguments::set_conservative_max_heap_alignment() {
1661   // The conservative maximum required alignment for the heap is the maximum of
1662   // the alignments imposed by several sources: any requirements from the heap
1663   // itself, the collector policy and the maximum page size we may run the VM
1664   // with.
1665   size_t heap_alignment = GCConfig::arguments()->conservative_max_heap_alignment();
1666   _conservative_max_heap_alignment = MAX4(heap_alignment,
1667                                           (size_t)os::vm_allocation_granularity(),
1668                                           os::max_page_size(),
1669                                           CollectorPolicy::compute_heap_alignment());
1670 }
1671 
1672 jint Arguments::set_ergonomics_flags() {
1673   GCConfig::initialize();
1674 
1675   set_conservative_max_heap_alignment();
1676 













1677   return JNI_OK;
1678 }
1679 
1680 julong Arguments::limit_by_allocatable_memory(julong limit) {
1681   julong max_allocatable;
1682   julong result = limit;
1683   if (os::has_allocatable_memory_limit(&max_allocatable)) {
1684     result = MIN2(result, max_allocatable / MaxVirtMemFraction);
1685   }
1686   return result;
1687 }
1688 
1689 // Use static initialization to get the default before parsing
1690 static const size_t DefaultHeapBaseMinAddress = HeapBaseMinAddress;
1691 
1692 void Arguments::set_heap_size() {
1693   julong phys_mem =
1694     FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM)
1695                             : (julong)MaxRAM;
1696 


1709 
1710   // If the maximum heap size has not been set with -Xmx,
1711   // then set it as fraction of the size of physical memory,
1712   // respecting the maximum and minimum sizes of the heap.
1713   if (FLAG_IS_DEFAULT(MaxHeapSize)) {
1714     julong reasonable_max = (julong)((phys_mem * MaxRAMPercentage) / 100);
1715     const julong reasonable_min = (julong)((phys_mem * MinRAMPercentage) / 100);
1716     if (reasonable_min < MaxHeapSize) {
1717       // Small physical memory, so use a minimum fraction of it for the heap
1718       reasonable_max = reasonable_min;
1719     } else {
1720       // Not-small physical memory, so require a heap at least
1721       // as large as MaxHeapSize
1722       reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
1723     }
1724 
1725     if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
1726       // Limit the heap size to ErgoHeapSizeLimit
1727       reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit);
1728     }
1729 
1730     // Now that we have a more accurate MaxHeapSize, see if we can 
1731     // enable compressed oops.  
1732     set_use_compressed_oops(MAX2(reasonable_max, InitialHeapSize));
1733 
1734     if (UseCompressedOops) {
1735       // Limit the heap size to the maximum possible when using compressed oops
1736       julong max_coop_heap = (julong)max_heap_for_compressed_oops();
1737 
1738       // HeapBaseMinAddress can be greater than default but not less than.
1739       if (!FLAG_IS_DEFAULT(HeapBaseMinAddress)) {
1740         if (HeapBaseMinAddress < DefaultHeapBaseMinAddress) {
1741           // matches compressed oops printing flags
1742           log_debug(gc, heap, coops)("HeapBaseMinAddress must be at least " SIZE_FORMAT
1743                                      " (" SIZE_FORMAT "G) which is greater than value given " SIZE_FORMAT,
1744                                      DefaultHeapBaseMinAddress,
1745                                      DefaultHeapBaseMinAddress/G,
1746                                      HeapBaseMinAddress);
1747           FLAG_SET_ERGO(size_t, HeapBaseMinAddress, DefaultHeapBaseMinAddress);
1748         }
1749       }
1750 
1751       if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) {
1752         // Heap should be above HeapBaseMinAddress to get zero based compressed oops
1753         // but it should be not less than default MaxHeapSize.
1754         max_coop_heap -= HeapBaseMinAddress;
1755       }
1756       reasonable_max = MIN2(reasonable_max, max_coop_heap);
1757     }
1758     reasonable_max = limit_by_allocatable_memory(reasonable_max);
1759 
1760     if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
1761       // An initial heap size was specified on the command line,
1762       // so be sure that the maximum size is consistent.  Done
1763       // after call to limit_by_allocatable_memory because that
1764       // method might reduce the allocation size.
1765       reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
1766     }
1767 
1768     log_trace(gc, heap)("  Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max);
1769     FLAG_SET_ERGO(size_t, MaxHeapSize, (size_t)reasonable_max);
1770 
1771   } else {
1772       set_use_compressed_oops(MaxHeapSize);
1773   }
1774 
1775   // If the minimum or initial heap_size have not been set or requested to be set
1776   // ergonomically, set them accordingly.
1777   if (InitialHeapSize == 0 || min_heap_size() == 0) {
1778     julong reasonable_minimum = (julong)(OldSize + NewSize);
1779 
1780     reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
1781 
1782     reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
1783 
1784     if (InitialHeapSize == 0) {
1785       julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100);
1786 
1787       reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size());
1788       reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
1789 
1790       reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
1791 
1792       log_trace(gc, heap)("  Initial heap size " SIZE_FORMAT, (size_t)reasonable_initial);


3832     return JNI_ERR;
3833   }
3834   if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) ||
3835       log_is_enabled(Info, cds)) {
3836     warning("Shared spaces are not supported in this VM");
3837     FLAG_SET_DEFAULT(UseSharedSpaces, false);
3838     LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(cds));
3839   }
3840   no_shared_spaces("CDS Disabled");
3841 #endif // INCLUDE_CDS
3842 
3843   return JNI_OK;
3844 }
3845 
3846 jint Arguments::apply_ergo() {
3847   // Set flags based on ergonomics.
3848   jint result = set_ergonomics_flags();
3849   if (result != JNI_OK) return result;
3850 
3851   // Set heap size based on available physical memory
3852   // Also calls set_use_compressed_oops().
3853   set_heap_size();
3854 
3855   // set_use_compressed_klass_ptrs() must be called after calling
3856   // set_use_compressed_oops().
3857   set_use_compressed_klass_ptrs();
3858 
3859   GCConfig::arguments()->initialize();
3860 
3861   set_shared_spaces_flags();
3862 
3863   // Initialize Metaspace flags and alignments
3864   Metaspace::ergo_initialize();
3865 
3866   // Set compiler flags after GC is selected and GC specific
3867   // flags (LoopStripMiningIter) are set.
3868   CompilerConfig::ergo_initialize();
3869 
3870   // Set bytecode rewriting flags
3871   set_bytecode_flags();
3872 
3873   // Set flags if aggressive optimization flags are enabled
3874   jint code = set_aggressive_opts_flags();
3875   if (code != JNI_OK) {
3876     return code;
3877   }


src/hotspot/share/runtime/arguments.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File