< prev index next >

src/share/vm/runtime/arguments.cpp

Print this page




  49 #endif
  50 #ifdef TARGET_OS_FAMILY_linux
  51 # include "os_linux.inline.hpp"
  52 #endif
  53 #ifdef TARGET_OS_FAMILY_solaris
  54 # include "os_solaris.inline.hpp"
  55 #endif
  56 #ifdef TARGET_OS_FAMILY_windows
  57 # include "os_windows.inline.hpp"
  58 #endif
  59 #ifdef TARGET_OS_FAMILY_aix
  60 # include "os_aix.inline.hpp"
  61 #endif
  62 #ifdef TARGET_OS_FAMILY_bsd
  63 # include "os_bsd.inline.hpp"
  64 #endif
  65 #if INCLUDE_ALL_GCS
  66 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
  67 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  68 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"



  69 #endif // INCLUDE_ALL_GCS
  70 
  71 // Note: This is a special bug reporting site for the JVM
  72 #ifdef VENDOR_URL_VM_BUG
  73 # define DEFAULT_VENDOR_URL_BUG VENDOR_URL_VM_BUG
  74 #else
  75 # define DEFAULT_VENDOR_URL_BUG "http://bugreport.java.com/bugreport/crash.jsp"
  76 #endif
  77 #define DEFAULT_JAVA_LAUNCHER  "generic"
  78 
  79 // Disable options not supported in this release, with a warning if they
  80 // were explicitly requested on the command-line
  81 #define UNSUPPORTED_OPTION(opt, description)                    \
  82 do {                                                            \
  83   if (opt) {                                                    \
  84     if (FLAG_IS_CMDLINE(opt)) {                                 \
  85       warning(description " is disabled in this release.");     \
  86     }                                                           \
  87     FLAG_SET_DEFAULT(opt, false);                               \
  88   }                                                             \


1144     jio_fprintf(defaultStream::error_stream(),
1145       "Class data sharing is inconsistent with other specified options.\n");
1146     vm_exit_during_initialization("Unable to use shared archive.", message);
1147   } else {
1148     FLAG_SET_DEFAULT(UseSharedSpaces, false);
1149   }
1150 }
1151 #endif
1152 
1153 void Arguments::set_tiered_flags() {
1154   // With tiered, set default policy to AdvancedThresholdPolicy, which is 3.
1155   if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
1156     FLAG_SET_DEFAULT(CompilationPolicyChoice, 3);
1157   }
1158   if (CompilationPolicyChoice < 2) {
1159     vm_exit_during_initialization(
1160       "Incompatible compilation policy selected", NULL);
1161   }
1162   // Increase the code cache size - tiered compiles a lot more.
1163   if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
1164     FLAG_SET_DEFAULT(ReservedCodeCacheSize, ReservedCodeCacheSize * 5);


1165   }
1166   if (!UseInterpreter) { // -Xcomp
1167     Tier3InvokeNotifyFreqLog = 0;
1168     Tier4InvocationThreshold = 0;
1169   }
1170 }
1171 
1172 /**
1173  * Returns the minimum number of compiler threads needed to run the JVM. The following
1174  * configurations are possible.
1175  *
1176  * 1) The JVM is build using an interpreter only. As a result, the minimum number of
1177  *    compiler threads is 0.
1178  * 2) The JVM is build using the compiler(s) and tiered compilation is disabled. As
1179  *    a result, either C1 or C2 is used, so the minimum number of compiler threads is 1.
1180  * 3) The JVM is build using the compiler(s) and tiered compilation is enabled. However,
1181  *    the option "TieredStopAtLevel < CompLevel_full_optimization". As a result, only
1182  *    C1 can be used, so the minimum number of compiler threads is 1.
1183  * 4) The JVM is build using the compilers and tiered compilation is enabled. The option
1184  *    'TieredStopAtLevel = CompLevel_full_optimization' (the default value). As a result,


1520 #ifdef _WIN64
1521     if (UseLargePages && UseCompressedOops) {
1522       // Cannot allocate guard pages for implicit checks in indexed addressing
1523       // mode, when large pages are specified on windows.
1524       // This flag could be switched ON if narrow oop base address is set to 0,
1525       // see code in Universe::initialize_heap().
1526       Universe::set_narrow_oop_use_implicit_null_checks(false);
1527     }
1528 #endif //  _WIN64
1529   } else {
1530     if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
1531       warning("Max heap size too large for Compressed Oops");
1532       FLAG_SET_DEFAULT(UseCompressedOops, false);
1533       FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1534     }
1535   }
1536 #endif // _LP64
1537 #endif // ZERO
1538 }
1539 
1540 
1541 // NOTE: set_use_compressed_klass_ptrs() must be called after calling
1542 // set_use_compressed_oops().
1543 void Arguments::set_use_compressed_klass_ptrs() {
1544 #ifndef ZERO
1545 #ifdef _LP64
1546   // UseCompressedOops must be on for UseCompressedClassPointers to be on.
1547   if (!UseCompressedOops) {
1548     if (UseCompressedClassPointers) {
1549       warning("UseCompressedClassPointers requires UseCompressedOops");
1550     }
1551     FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1552   } else {
1553     // Turn on UseCompressedClassPointers too
1554     if (FLAG_IS_DEFAULT(UseCompressedClassPointers)) {
1555       FLAG_SET_ERGO(bool, UseCompressedClassPointers, true);
1556     }
1557     // Check the CompressedClassSpaceSize to make sure we use compressed klass ptrs.
1558     if (UseCompressedClassPointers) {
1559       if (CompressedClassSpaceSize > KlassEncodingMetaspaceMax) {
1560         warning("CompressedClassSpaceSize is too large for UseCompressedClassPointers");
1561         FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1562       }
1563     }
1564   }
1565 #endif // _LP64
1566 #endif // !ZERO
1567 }
1568 
1569 void Arguments::set_conservative_max_heap_alignment() {
1570   // The conservative maximum required alignment for the heap is the maximum of
1571   // the alignments imposed by several sources: any requirements from the heap
1572   // itself, the collector policy and the maximum page size we may run the VM
1573   // with.
1574   size_t heap_alignment = GenCollectedHeap::conservative_max_heap_alignment();
1575 #if INCLUDE_ALL_GCS
1576   if (UseParallelGC) {
1577     heap_alignment = ParallelScavengeHeap::conservative_max_heap_alignment();
1578   } else if (UseG1GC) {
1579     heap_alignment = G1CollectedHeap::conservative_max_heap_alignment();


1580   }
1581 #endif // INCLUDE_ALL_GCS
1582   _conservative_max_heap_alignment = MAX4(heap_alignment,
1583                                           (size_t)os::vm_allocation_granularity(),
1584                                           os::max_page_size(),
1585                                           CollectorPolicy::compute_heap_alignment());
1586 }
1587 
1588 void Arguments::select_gc_ergonomically() {
1589   if (os::is_server_class_machine()) {
1590     if (should_auto_select_low_pause_collector()) {
1591       FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
1592     } else {
1593       FLAG_SET_ERGO(bool, UseParallelGC, true);
1594     }
1595   }
1596 }
1597 
1598 void Arguments::select_gc() {
1599   if (!gc_selected()) {


1711     FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE);
1712   }
1713 
1714   if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
1715     // In G1, we want the default GC overhead goal to be higher than
1716     // say in PS. So we set it here to 10%. Otherwise the heap might
1717     // be expanded more aggressively than we would like it to. In
1718     // fact, even 10% seems to not be high enough in some cases
1719     // (especially small GC stress tests that the main thing they do
1720     // is allocation). We might consider increase it further.
1721     FLAG_SET_DEFAULT(GCTimeRatio, 9);
1722   }
1723 
1724   if (PrintGCDetails && Verbose) {
1725     tty->print_cr("MarkStackSize: %uk  MarkStackSizeMax: %uk",
1726       (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
1727     tty->print_cr("ConcGCThreads: %u", (uint) ConcGCThreads);
1728   }
1729 }
1730 




































































































































































1731 #if !INCLUDE_ALL_GCS
1732 #ifdef ASSERT
1733 static bool verify_serial_gc_flags() {
1734   return (UseSerialGC &&
1735         !(UseParNewGC || (UseConcMarkSweepGC || CMSIncrementalMode) || UseG1GC ||
1736           UseParallelGC || UseParallelOldGC));
1737 }
1738 #endif // ASSERT
1739 #endif // INCLUDE_ALL_GCS
1740 
1741 void Arguments::set_gc_specific_flags() {
1742 #if INCLUDE_ALL_GCS
1743   // Set per-collector flags
1744   if (UseParallelGC || UseParallelOldGC) {
1745     set_parallel_gc_flags();
1746   } else if (UseConcMarkSweepGC) { // Should be done before ParNew check below
1747     set_cms_and_parnew_gc_flags();
1748   } else if (UseParNewGC) {  // Skipped if CMS is set above
1749     set_parnew_gc_flags();
1750   } else if (UseG1GC) {
1751     set_g1_gc_flags();


1752   }
1753   check_deprecated_gcs();
1754   check_deprecated_gc_flags();
1755   if (AssumeMP && !UseSerialGC) {
1756     if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) {
1757       warning("If the number of processors is expected to increase from one, then"
1758               " you should configure the number of parallel GC threads appropriately"
1759               " using -XX:ParallelGCThreads=N");
1760     }
1761   }
1762   if (MinHeapFreeRatio == 100) {
1763     // Keeping the heap 100% free is hard ;-) so limit it to 99%.
1764     FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99);
1765   }
1766 
1767   // If class unloading is disabled, also disable concurrent class unloading.
1768   if (!ClassUnloading) {
1769     FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false);
1770     FLAG_SET_CMDLINE(bool, ClassUnloadingWithConcurrentMark, false);
1771     FLAG_SET_CMDLINE(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false);

1772   }
1773 #else // INCLUDE_ALL_GCS
1774   assert(verify_serial_gc_flags(), "SerialGC unset");
1775 #endif // INCLUDE_ALL_GCS
1776 }
1777 
1778 julong Arguments::limit_by_allocatable_memory(julong limit) {
1779   julong max_allocatable;
1780   julong result = limit;
1781   if (os::has_allocatable_memory_limit(&max_allocatable)) {
1782     result = MIN2(result, max_allocatable / MaxVirtMemFraction);
1783   }
1784   return result;
1785 }
1786 
1787 void Arguments::set_heap_size() {
1788   if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) {
1789     // Deprecated flag
1790     FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction);
1791   }


2132 // check if do gclog rotation
2133 // +UseGCLogFileRotation is a must,
2134 // no gc log rotation when log file not supplied or
2135 // NumberOfGCLogFiles is 0
2136 void check_gclog_consistency() {
2137   if (UseGCLogFileRotation) {
2138     if ((Arguments::gc_log_filename() == NULL) || (NumberOfGCLogFiles == 0)) {
2139       jio_fprintf(defaultStream::output_stream(),
2140                   "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files>\n"
2141                   "where num_of_file > 0\n"
2142                   "GC log rotation is turned off\n");
2143       UseGCLogFileRotation = false;
2144     }
2145   }
2146 
2147   if (UseGCLogFileRotation && (GCLogFileSize != 0) && (GCLogFileSize < 8*K)) {
2148     FLAG_SET_CMDLINE(uintx, GCLogFileSize, 8*K);
2149     jio_fprintf(defaultStream::output_stream(),
2150                 "GCLogFileSize changed to minimum 8K\n");
2151   }





2152 }
2153 
2154 // This function is called for -Xloggc:<filename>, it can be used
2155 // to check if a given file name(or string) conforms to the following
2156 // specification:
2157 // A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]"
2158 // %p and %t only allowed once. We only limit usage of filename not path
2159 bool is_filename_valid(const char *file_name) {
2160   const char* p = file_name;
2161   char file_sep = os::file_separator()[0];
2162   const char* cp;
2163   // skip prefix path
2164   for (cp = file_name; *cp != '\0'; cp++) {
2165     if (*cp == '/' || *cp == file_sep) {
2166       p = cp + 1;
2167     }
2168   }
2169 
2170   int count_p = 0;
2171   int count_t = 0;


2227   _max_heap_free_ratio = max_heap_free_ratio;
2228   return true;
2229 }
2230 
2231 // Check consistency of GC selection
2232 bool Arguments::check_gc_consistency() {
2233   check_gclog_consistency();
2234   bool status = true;
2235   // Ensure that the user has not selected conflicting sets
2236   // of collectors. [Note: this check is merely a user convenience;
2237   // collectors over-ride each other so that only a non-conflicting
2238   // set is selected; however what the user gets is not what they
2239   // may have expected from the combination they asked for. It's
2240   // better to reduce user confusion by not allowing them to
2241   // select conflicting combinations.
2242   uint i = 0;
2243   if (UseSerialGC)                       i++;
2244   if (UseConcMarkSweepGC || UseParNewGC) i++;
2245   if (UseParallelGC || UseParallelOldGC) i++;
2246   if (UseG1GC)                           i++;

2247   if (i > 1) {
2248     jio_fprintf(defaultStream::error_stream(),
2249                 "Conflicting collector combinations in option list; "
2250                 "please refer to the release notes for the combinations "
2251                 "allowed\n");
2252     status = false;
2253   }
2254   return status;
2255 }
2256 
2257 void Arguments::check_deprecated_gcs() {
2258   if (UseConcMarkSweepGC && !UseParNewGC) {
2259     warning("Using the DefNew young collector with the CMS collector is deprecated "
2260         "and will likely be removed in a future release");
2261   }
2262 
2263   if (UseParNewGC && !UseConcMarkSweepGC) {
2264     // !UseConcMarkSweepGC means that we are using serial old gc. Unfortunately we don't
2265     // set up UseSerialGC properly, so that can't be used in the check here.
2266     warning("Using the ParNew young collector with the Serial old collector is deprecated "


2614   }
2615 
2616   // Check lower bounds of the code cache
2617   // Template Interpreter code is approximately 3X larger in debug builds.
2618   uint min_code_cache_size = (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3)) + CodeCacheMinimumFreeSpace;
2619   if (InitialCodeCacheSize < (uintx)os::vm_page_size()) {
2620     jio_fprintf(defaultStream::error_stream(),
2621                 "Invalid InitialCodeCacheSize=%dK. Must be at least %dK.\n", InitialCodeCacheSize/K,
2622                 os::vm_page_size()/K);
2623     status = false;
2624   } else if (ReservedCodeCacheSize < InitialCodeCacheSize) {
2625     jio_fprintf(defaultStream::error_stream(),
2626                 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",
2627                 ReservedCodeCacheSize/K, InitialCodeCacheSize/K);
2628     status = false;
2629   } else if (ReservedCodeCacheSize < min_code_cache_size) {
2630     jio_fprintf(defaultStream::error_stream(),
2631                 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K,
2632                 min_code_cache_size/K);
2633     status = false;
2634   } else if (ReservedCodeCacheSize > 2*G) {
2635     // Code cache size larger than MAXINT is not supported.
2636     jio_fprintf(defaultStream::error_stream(),
2637                 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M,
2638                 (2*G)/M);
2639     status = false;
2640   }
2641 
2642   status &= verify_interval(NmethodSweepFraction, 1, ReservedCodeCacheSize/K, "NmethodSweepFraction");
2643   status &= verify_interval(NmethodSweepActivity, 0, 2000, "NmethodSweepActivity");
2644 
2645   if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) {
2646     warning("The VM option CICompilerCountPerCPU overrides CICompilerCount.");
2647   }
2648 
2649 #ifdef COMPILER1
2650   status &= verify_interval(SafepointPollOffset, 0, os::vm_page_size() - BytesPerWord, "SafepointPollOffset");
2651 #endif
2652 
2653   int min_number_of_compiler_threads = get_min_number_of_compiler_threads();
2654   // The default CICompilerCount's value is CI_COMPILER_COUNT.
2655   assert(min_number_of_compiler_threads <= CI_COMPILER_COUNT, "minimum should be less or equal default number");
2656   // Check the minimum number of compiler threads
2657   status &=verify_min_value(CICompilerCount, min_number_of_compiler_threads, "CICompilerCount");
2658 




  49 #endif
  50 #ifdef TARGET_OS_FAMILY_linux
  51 # include "os_linux.inline.hpp"
  52 #endif
  53 #ifdef TARGET_OS_FAMILY_solaris
  54 # include "os_solaris.inline.hpp"
  55 #endif
  56 #ifdef TARGET_OS_FAMILY_windows
  57 # include "os_windows.inline.hpp"
  58 #endif
  59 #ifdef TARGET_OS_FAMILY_aix
  60 # include "os_aix.inline.hpp"
  61 #endif
  62 #ifdef TARGET_OS_FAMILY_bsd
  63 # include "os_bsd.inline.hpp"
  64 #endif
  65 #if INCLUDE_ALL_GCS
  66 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
  67 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  68 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  69 #include "gc_implementation/shenandoah/shenandoahHeap.hpp"
  70 #include "gc_implementation/shenandoah/shenandoahLogging.hpp"
  71 #include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp"
  72 #endif // INCLUDE_ALL_GCS
  73 
  74 // Note: This is a special bug reporting site for the JVM
  75 #ifdef VENDOR_URL_VM_BUG
  76 # define DEFAULT_VENDOR_URL_BUG VENDOR_URL_VM_BUG
  77 #else
  78 # define DEFAULT_VENDOR_URL_BUG "http://bugreport.java.com/bugreport/crash.jsp"
  79 #endif
  80 #define DEFAULT_JAVA_LAUNCHER  "generic"
  81 
  82 // Disable options not supported in this release, with a warning if they
  83 // were explicitly requested on the command-line
  84 #define UNSUPPORTED_OPTION(opt, description)                    \
  85 do {                                                            \
  86   if (opt) {                                                    \
  87     if (FLAG_IS_CMDLINE(opt)) {                                 \
  88       warning(description " is disabled in this release.");     \
  89     }                                                           \
  90     FLAG_SET_DEFAULT(opt, false);                               \
  91   }                                                             \


1147     jio_fprintf(defaultStream::error_stream(),
1148       "Class data sharing is inconsistent with other specified options.\n");
1149     vm_exit_during_initialization("Unable to use shared archive.", message);
1150   } else {
1151     FLAG_SET_DEFAULT(UseSharedSpaces, false);
1152   }
1153 }
1154 #endif
1155 
1156 void Arguments::set_tiered_flags() {
1157   // With tiered, set default policy to AdvancedThresholdPolicy, which is 3.
1158   if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
1159     FLAG_SET_DEFAULT(CompilationPolicyChoice, 3);
1160   }
1161   if (CompilationPolicyChoice < 2) {
1162     vm_exit_during_initialization(
1163       "Incompatible compilation policy selected", NULL);
1164   }
1165   // Increase the code cache size - tiered compiles a lot more.
1166   if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
1167     NOT_AARCH64(FLAG_SET_DEFAULT(ReservedCodeCacheSize, ReservedCodeCacheSize * 5));
1168     AARCH64_ONLY(FLAG_SET_DEFAULT(ReservedCodeCacheSize,
1169                                   MIN2(CODE_CACHE_DEFAULT_LIMIT, ReservedCodeCacheSize * 5)));
1170   }
1171   if (!UseInterpreter) { // -Xcomp
1172     Tier3InvokeNotifyFreqLog = 0;
1173     Tier4InvocationThreshold = 0;
1174   }
1175 }
1176 
1177 /**
1178  * Returns the minimum number of compiler threads needed to run the JVM. The following
1179  * configurations are possible.
1180  *
1181  * 1) The JVM is build using an interpreter only. As a result, the minimum number of
1182  *    compiler threads is 0.
1183  * 2) The JVM is build using the compiler(s) and tiered compilation is disabled. As
1184  *    a result, either C1 or C2 is used, so the minimum number of compiler threads is 1.
1185  * 3) The JVM is build using the compiler(s) and tiered compilation is enabled. However,
1186  *    the option "TieredStopAtLevel < CompLevel_full_optimization". As a result, only
1187  *    C1 can be used, so the minimum number of compiler threads is 1.
1188  * 4) The JVM is build using the compilers and tiered compilation is enabled. The option
1189  *    'TieredStopAtLevel = CompLevel_full_optimization' (the default value). As a result,


1525 #ifdef _WIN64
1526     if (UseLargePages && UseCompressedOops) {
1527       // Cannot allocate guard pages for implicit checks in indexed addressing
1528       // mode, when large pages are specified on windows.
1529       // This flag could be switched ON if narrow oop base address is set to 0,
1530       // see code in Universe::initialize_heap().
1531       Universe::set_narrow_oop_use_implicit_null_checks(false);
1532     }
1533 #endif //  _WIN64
1534   } else {
1535     if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
1536       warning("Max heap size too large for Compressed Oops");
1537       FLAG_SET_DEFAULT(UseCompressedOops, false);
1538       FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1539     }
1540   }
1541 #endif // _LP64
1542 #endif // ZERO
1543 }
1544 

1545 // NOTE: set_use_compressed_klass_ptrs() must be called after calling
1546 // set_use_compressed_oops().
1547 void Arguments::set_use_compressed_klass_ptrs() {
1548 #ifndef ZERO
1549 #ifdef _LP64
1550   // UseCompressedOops must be on for UseCompressedClassPointers to be on.
1551   if (!UseCompressedOops) {
1552     if (UseCompressedClassPointers) {
1553       warning("UseCompressedClassPointers requires UseCompressedOops");
1554     }
1555     FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1556   } else {
1557     // Turn on UseCompressedClassPointers too
1558     if (FLAG_IS_DEFAULT(UseCompressedClassPointers)) {
1559       FLAG_SET_ERGO(bool, UseCompressedClassPointers, true);
1560     }
1561     // Check the CompressedClassSpaceSize to make sure we use compressed klass ptrs.
1562     if (UseCompressedClassPointers) {
1563       if (CompressedClassSpaceSize > KlassEncodingMetaspaceMax) {
1564         warning("CompressedClassSpaceSize is too large for UseCompressedClassPointers");
1565         FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1566       }
1567     }
1568   }
1569 #endif // _LP64
1570 #endif // !ZERO
1571 }
1572 
1573 void Arguments::set_conservative_max_heap_alignment() {
1574   // The conservative maximum required alignment for the heap is the maximum of
1575   // the alignments imposed by several sources: any requirements from the heap
1576   // itself, the collector policy and the maximum page size we may run the VM
1577   // with.
1578   size_t heap_alignment = GenCollectedHeap::conservative_max_heap_alignment();
1579 #if INCLUDE_ALL_GCS
1580   if (UseParallelGC) {
1581     heap_alignment = ParallelScavengeHeap::conservative_max_heap_alignment();
1582   } else if (UseG1GC) {
1583     heap_alignment = G1CollectedHeap::conservative_max_heap_alignment();
1584   } else if (UseShenandoahGC) {
1585     heap_alignment = ShenandoahHeap::conservative_max_heap_alignment();
1586   }
1587 #endif // INCLUDE_ALL_GCS
1588   _conservative_max_heap_alignment = MAX4(heap_alignment,
1589                                           (size_t)os::vm_allocation_granularity(),
1590                                           os::max_page_size(),
1591                                           CollectorPolicy::compute_heap_alignment());
1592 }
1593 
1594 void Arguments::select_gc_ergonomically() {
1595   if (os::is_server_class_machine()) {
1596     if (should_auto_select_low_pause_collector()) {
1597       FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
1598     } else {
1599       FLAG_SET_ERGO(bool, UseParallelGC, true);
1600     }
1601   }
1602 }
1603 
1604 void Arguments::select_gc() {
1605   if (!gc_selected()) {


1717     FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE);
1718   }
1719 
1720   if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
1721     // In G1, we want the default GC overhead goal to be higher than
1722     // say in PS. So we set it here to 10%. Otherwise the heap might
1723     // be expanded more aggressively than we would like it to. In
1724     // fact, even 10% seems to not be high enough in some cases
1725     // (especially small GC stress tests that the main thing they do
1726     // is allocation). We might consider increase it further.
1727     FLAG_SET_DEFAULT(GCTimeRatio, 9);
1728   }
1729 
1730   if (PrintGCDetails && Verbose) {
1731     tty->print_cr("MarkStackSize: %uk  MarkStackSizeMax: %uk",
1732       (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
1733     tty->print_cr("ConcGCThreads: %u", (uint) ConcGCThreads);
1734   }
1735 }
1736 
1737 void Arguments::set_shenandoah_gc_flags() {
1738 
1739 #if !(defined AARCH64 || defined AMD64 || defined IA32)
1740   UNSUPPORTED_GC_OPTION(UseShenandoahGC);
1741 #endif
1742 
1743 #if 0 // leave this block as stepping stone for future platforms
1744   warning("Shenandoah GC is not fully supported on this platform:");
1745   warning("  concurrent modes are not supported, only STW cycles are enabled;");
1746   warning("  arch-specific barrier code is not implemented, disabling barriers;");
1747 
1748 #if INCLUDE_ALL_GCS
1749   FLAG_SET_DEFAULT(ShenandoahGCHeuristics,           "passive");
1750 
1751   FLAG_SET_DEFAULT(ShenandoahSATBBarrier,            false);
1752   FLAG_SET_DEFAULT(ShenandoahLoadRefBarrier,         false);
1753   FLAG_SET_DEFAULT(ShenandoahStoreValEnqueueBarrier, false);
1754   FLAG_SET_DEFAULT(ShenandoahCASBarrier,             false);
1755   FLAG_SET_DEFAULT(ShenandoahCloneBarrier,           false);
1756 
1757   FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers,     false);
1758 #endif
1759 #endif
1760 
1761 #if INCLUDE_ALL_GCS
1762   if (!FLAG_IS_DEFAULT(ShenandoahGarbageThreshold)) {
1763     if (0 > ShenandoahGarbageThreshold || ShenandoahGarbageThreshold > 100) {
1764       vm_exit_during_initialization("The flag -XX:ShenandoahGarbageThreshold is out of range", NULL);
1765     }
1766   }
1767 
1768   if (!FLAG_IS_DEFAULT(ShenandoahAllocationThreshold)) {
1769     if (0 > ShenandoahAllocationThreshold || ShenandoahAllocationThreshold > 100) {
1770       vm_exit_during_initialization("The flag -XX:ShenandoahAllocationThreshold is out of range", NULL);
1771     }
1772   }
1773 
1774   if (!FLAG_IS_DEFAULT(ShenandoahMinFreeThreshold)) {
1775     if (0 > ShenandoahMinFreeThreshold || ShenandoahMinFreeThreshold > 100) {
1776       vm_exit_during_initialization("The flag -XX:ShenandoahMinFreeThreshold is out of range", NULL);
1777     }
1778   }
1779 #endif
1780 
1781 #if INCLUDE_ALL_GCS
1782   if (UseLargePages && (MaxHeapSize / os::large_page_size()) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {
1783     warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",
1784             os::large_page_size() / K);
1785     FLAG_SET_DEFAULT(ShenandoahUncommit, false);
1786   }
1787 #endif
1788 
1789   // Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes
1790   // storage allocation code NUMA-aware.
1791   if (FLAG_IS_DEFAULT(UseNUMA)) {
1792     FLAG_SET_DEFAULT(UseNUMA, true);
1793   }
1794 
1795   // Set up default number of concurrent threads. We want to have cycles complete fast
1796   // enough, but we also do not want to steal too much CPU from the concurrently running
1797   // application. Using 1/4 of available threads for concurrent GC seems a good
1798   // compromise here.
1799   bool ergo_conc = FLAG_IS_DEFAULT(ConcGCThreads);
1800   if (ergo_conc) {
1801     FLAG_SET_DEFAULT(ConcGCThreads, MAX2(1, os::initial_active_processor_count() / 4));
1802   }
1803 
1804   if (ConcGCThreads == 0) {
1805     vm_exit_during_initialization("Shenandoah expects ConcGCThreads > 0, check -XX:ConcGCThreads=#");
1806   }
1807 
1808   // Set up default number of parallel threads. We want to have decent pauses performance
1809   // which would use parallel threads, but we also do not want to do too many threads
1810   // that will overwhelm the OS scheduler. Using 1/2 of available threads seems to be a fair
1811   // compromise here. Due to implementation constraints, it should not be lower than
1812   // the number of concurrent threads.
1813   bool ergo_parallel = FLAG_IS_DEFAULT(ParallelGCThreads);
1814   if (ergo_parallel) {
1815     FLAG_SET_DEFAULT(ParallelGCThreads, MAX2(1, os::initial_active_processor_count() / 2));
1816   }
1817 
1818   if (ParallelGCThreads == 0) {
1819     vm_exit_during_initialization("Shenandoah expects ParallelGCThreads > 0, check -XX:ParallelGCThreads=#");
1820   }
1821 
1822   // Make sure ergonomic decisions do not break the thread count invariants.
1823   // This may happen when user overrides one of the flags, but not the other.
1824   // When that happens, we want to adjust the setting that was set ergonomically.
1825   if (ParallelGCThreads < ConcGCThreads) {
1826     if (ergo_conc && !ergo_parallel) {
1827       FLAG_SET_DEFAULT(ConcGCThreads, ParallelGCThreads);
1828     } else if (!ergo_conc && ergo_parallel) {
1829       FLAG_SET_DEFAULT(ParallelGCThreads, ConcGCThreads);
1830     } else if (ergo_conc && ergo_parallel) {
1831       // Should not happen, check the ergonomic computation above. Fail with relevant error.
1832       vm_exit_during_initialization("Shenandoah thread count ergonomic error");
1833     } else {
1834       // User settings error, report and ask user to rectify.
1835       vm_exit_during_initialization("Shenandoah expects ConcGCThreads <= ParallelGCThreads, check -XX:ParallelGCThreads, -XX:ConcGCThreads");
1836     }
1837   }
1838 
1839   if (FLAG_IS_DEFAULT(ParallelRefProcEnabled)) {
1840     FLAG_SET_DEFAULT(ParallelRefProcEnabled, true);
1841   }
1842 
1843 #if INCLUDE_ALL_GCS
1844   if (ShenandoahRegionSampling && FLAG_IS_DEFAULT(PerfDataMemorySize)) {
1845     // When sampling is enabled, max out the PerfData memory to get more
1846     // Shenandoah data in, including Matrix.
1847     FLAG_SET_DEFAULT(PerfDataMemorySize, 2048*K);
1848   }
1849 #endif
1850 
1851 #ifdef COMPILER2
1852   // Shenandoah cares more about pause times, rather than raw throughput.
1853   // Enabling safepoints in counted loops makes it more responsive with
1854   // long loops. However, it is risky in 8u, due to bugs it brings, for
1855   // example JDK-8176506. Warn user about this, and proceed.
1856   if (UseCountedLoopSafepoints) {
1857     warning("Enabling -XX:UseCountedLoopSafepoints is known to cause JVM bugs. Use at your own risk.");
1858   }
1859 
1860 #ifdef ASSERT
1861   // C2 barrier verification is only reliable when all default barriers are enabled
1862   if (ShenandoahVerifyOptoBarriers &&
1863           (!FLAG_IS_DEFAULT(ShenandoahSATBBarrier)    ||
1864            !FLAG_IS_DEFAULT(ShenandoahLoadRefBarrier) ||
1865            !FLAG_IS_DEFAULT(ShenandoahStoreValEnqueueBarrier) ||
1866            !FLAG_IS_DEFAULT(ShenandoahCASBarrier)     ||
1867            !FLAG_IS_DEFAULT(ShenandoahCloneBarrier)
1868           )) {
1869     warning("Unusual barrier configuration, disabling C2 barrier verification");
1870     FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
1871   }
1872 #else
1873   guarantee(!ShenandoahVerifyOptoBarriers, "Should be disabled");
1874 #endif // ASSERT
1875 #endif // COMPILER2
1876 
1877 #if INCLUDE_ALL_GCS
1878   if ((InitialHeapSize == MaxHeapSize) && ShenandoahUncommit) {
1879     if (PrintGC) {
1880       tty->print_cr("Min heap equals to max heap, disabling ShenandoahUncommit");
1881     }
1882     FLAG_SET_DEFAULT(ShenandoahUncommit, false);
1883   }
1884 
1885   // If class unloading is disabled, no unloading for concurrent cycles as well.
1886   if (!ClassUnloading) {
1887     FLAG_SET_DEFAULT(ClassUnloadingWithConcurrentMark, false);
1888   }
1889 
1890   // TLAB sizing policy makes resizing decisions before each GC cycle. It averages
1891   // historical data, assigning more recent data the weight according to TLABAllocationWeight.
1892   // Current default is good for generational collectors that run frequent young GCs.
1893   // With Shenandoah, GC cycles are much less frequent, so we need we need sizing policy
1894   // to converge faster over smaller number of resizing decisions.
1895   if (FLAG_IS_DEFAULT(TLABAllocationWeight)) {
1896     FLAG_SET_DEFAULT(TLABAllocationWeight, 90);
1897   }
1898 #endif
1899 }
1900 
1901 #if !INCLUDE_ALL_GCS
1902 #ifdef ASSERT
1903 static bool verify_serial_gc_flags() {
1904   return (UseSerialGC &&
1905         !(UseParNewGC || (UseConcMarkSweepGC || CMSIncrementalMode) || UseG1GC ||
1906           UseParallelGC || UseParallelOldGC));
1907 }
1908 #endif // ASSERT
1909 #endif // INCLUDE_ALL_GCS
1910 
1911 void Arguments::set_gc_specific_flags() {
1912 #if INCLUDE_ALL_GCS
1913   // Set per-collector flags
1914   if (UseParallelGC || UseParallelOldGC) {
1915     set_parallel_gc_flags();
1916   } else if (UseConcMarkSweepGC) { // Should be done before ParNew check below
1917     set_cms_and_parnew_gc_flags();
1918   } else if (UseParNewGC) {  // Skipped if CMS is set above
1919     set_parnew_gc_flags();
1920   } else if (UseG1GC) {
1921     set_g1_gc_flags();
1922   } else if (UseShenandoahGC) {
1923     set_shenandoah_gc_flags();
1924   }
1925   check_deprecated_gcs();
1926   check_deprecated_gc_flags();
1927   if (AssumeMP && !UseSerialGC) {
1928     if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) {
1929       warning("If the number of processors is expected to increase from one, then"
1930               " you should configure the number of parallel GC threads appropriately"
1931               " using -XX:ParallelGCThreads=N");
1932     }
1933   }
1934   if (MinHeapFreeRatio == 100) {
1935     // Keeping the heap 100% free is hard ;-) so limit it to 99%.
1936     FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99);
1937   }
1938 
1939   // If class unloading is disabled, also disable concurrent class unloading.
1940   if (!ClassUnloading) {
1941     FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false);
1942     FLAG_SET_CMDLINE(bool, ClassUnloadingWithConcurrentMark, false);
1943     FLAG_SET_CMDLINE(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false);
1944     FLAG_SET_CMDLINE(uintx, ShenandoahUnloadClassesFrequency, 0);
1945   }
1946 #else // INCLUDE_ALL_GCS
1947   assert(verify_serial_gc_flags(), "SerialGC unset");
1948 #endif // INCLUDE_ALL_GCS
1949 }
1950 
1951 julong Arguments::limit_by_allocatable_memory(julong limit) {
1952   julong max_allocatable;
1953   julong result = limit;
1954   if (os::has_allocatable_memory_limit(&max_allocatable)) {
1955     result = MIN2(result, max_allocatable / MaxVirtMemFraction);
1956   }
1957   return result;
1958 }
1959 
1960 void Arguments::set_heap_size() {
1961   if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) {
1962     // Deprecated flag
1963     FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction);
1964   }


2305 // check if do gclog rotation
2306 // +UseGCLogFileRotation is a must,
2307 // no gc log rotation when log file not supplied or
2308 // NumberOfGCLogFiles is 0
2309 void check_gclog_consistency() {
2310   if (UseGCLogFileRotation) {
2311     if ((Arguments::gc_log_filename() == NULL) || (NumberOfGCLogFiles == 0)) {
2312       jio_fprintf(defaultStream::output_stream(),
2313                   "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files>\n"
2314                   "where num_of_file > 0\n"
2315                   "GC log rotation is turned off\n");
2316       UseGCLogFileRotation = false;
2317     }
2318   }
2319 
2320   if (UseGCLogFileRotation && (GCLogFileSize != 0) && (GCLogFileSize < 8*K)) {
2321     FLAG_SET_CMDLINE(uintx, GCLogFileSize, 8*K);
2322     jio_fprintf(defaultStream::output_stream(),
2323                 "GCLogFileSize changed to minimum 8K\n");
2324   }
2325 
2326   // Record more information about previous cycles for improved debugging pleasure
2327   if (FLAG_IS_DEFAULT(LogEventsBufferEntries)) {
2328     FLAG_SET_DEFAULT(LogEventsBufferEntries, 250);
2329   }
2330 }
2331 
2332 // This function is called for -Xloggc:<filename>, it can be used
2333 // to check if a given file name(or string) conforms to the following
2334 // specification:
2335 // A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]"
2336 // %p and %t only allowed once. We only limit usage of filename not path
2337 bool is_filename_valid(const char *file_name) {
2338   const char* p = file_name;
2339   char file_sep = os::file_separator()[0];
2340   const char* cp;
2341   // skip prefix path
2342   for (cp = file_name; *cp != '\0'; cp++) {
2343     if (*cp == '/' || *cp == file_sep) {
2344       p = cp + 1;
2345     }
2346   }
2347 
2348   int count_p = 0;
2349   int count_t = 0;


2405   _max_heap_free_ratio = max_heap_free_ratio;
2406   return true;
2407 }
2408 
2409 // Check consistency of GC selection
2410 bool Arguments::check_gc_consistency() {
2411   check_gclog_consistency();
2412   bool status = true;
2413   // Ensure that the user has not selected conflicting sets
2414   // of collectors. [Note: this check is merely a user convenience;
2415   // collectors over-ride each other so that only a non-conflicting
2416   // set is selected; however what the user gets is not what they
2417   // may have expected from the combination they asked for. It's
2418   // better to reduce user confusion by not allowing them to
2419   // select conflicting combinations.
2420   uint i = 0;
2421   if (UseSerialGC)                       i++;
2422   if (UseConcMarkSweepGC || UseParNewGC) i++;
2423   if (UseParallelGC || UseParallelOldGC) i++;
2424   if (UseG1GC)                           i++;
2425   if (UseShenandoahGC)                   i++;
2426   if (i > 1) {
2427     jio_fprintf(defaultStream::error_stream(),
2428                 "Conflicting collector combinations in option list; "
2429                 "please refer to the release notes for the combinations "
2430                 "allowed\n");
2431     status = false;
2432   }
2433   return status;
2434 }
2435 
2436 void Arguments::check_deprecated_gcs() {
2437   if (UseConcMarkSweepGC && !UseParNewGC) {
2438     warning("Using the DefNew young collector with the CMS collector is deprecated "
2439         "and will likely be removed in a future release");
2440   }
2441 
2442   if (UseParNewGC && !UseConcMarkSweepGC) {
2443     // !UseConcMarkSweepGC means that we are using serial old gc. Unfortunately we don't
2444     // set up UseSerialGC properly, so that can't be used in the check here.
2445     warning("Using the ParNew young collector with the Serial old collector is deprecated "


2793   }
2794 
2795   // Check lower bounds of the code cache
2796   // Template Interpreter code is approximately 3X larger in debug builds.
2797   uint min_code_cache_size = (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3)) + CodeCacheMinimumFreeSpace;
2798   if (InitialCodeCacheSize < (uintx)os::vm_page_size()) {
2799     jio_fprintf(defaultStream::error_stream(),
2800                 "Invalid InitialCodeCacheSize=%dK. Must be at least %dK.\n", InitialCodeCacheSize/K,
2801                 os::vm_page_size()/K);
2802     status = false;
2803   } else if (ReservedCodeCacheSize < InitialCodeCacheSize) {
2804     jio_fprintf(defaultStream::error_stream(),
2805                 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",
2806                 ReservedCodeCacheSize/K, InitialCodeCacheSize/K);
2807     status = false;
2808   } else if (ReservedCodeCacheSize < min_code_cache_size) {
2809     jio_fprintf(defaultStream::error_stream(),
2810                 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K,
2811                 min_code_cache_size/K);
2812     status = false;
2813   } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) {
2814     // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported.
2815     jio_fprintf(defaultStream::error_stream(),
2816                 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M,
2817                 CODE_CACHE_SIZE_LIMIT/M);
2818     status = false;
2819   }
2820 
2821   status &= verify_interval(NmethodSweepFraction, 1, ReservedCodeCacheSize/K, "NmethodSweepFraction");
2822   status &= verify_interval(NmethodSweepActivity, 0, 2000, "NmethodSweepActivity");
2823 
2824   if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) {
2825     warning("The VM option CICompilerCountPerCPU overrides CICompilerCount.");
2826   }
2827 
2828 #ifdef COMPILER1
2829   status &= verify_interval(SafepointPollOffset, 0, os::vm_page_size() - BytesPerWord, "SafepointPollOffset");
2830 #endif
2831 
2832   int min_number_of_compiler_threads = get_min_number_of_compiler_threads();
2833   // The default CICompilerCount's value is CI_COMPILER_COUNT.
2834   assert(min_number_of_compiler_threads <= CI_COMPILER_COUNT, "minimum should be less or equal default number");
2835   // Check the minimum number of compiler threads
2836   status &=verify_min_value(CICompilerCount, min_number_of_compiler_threads, "CICompilerCount");
2837 


< prev index next >