1.1 --- a/src/share/vm/runtime/arguments.cpp Mon Oct 20 23:02:07 2014 -0700 1.2 +++ b/src/share/vm/runtime/arguments.cpp Fri Oct 24 17:09:30 2014 -0700 1.3 @@ -23,6 +23,7 @@ 1.4 */ 1.5 1.6 #include "precompiled.hpp" 1.7 +#include "classfile/classLoader.hpp" 1.8 #include "classfile/javaAssertions.hpp" 1.9 #include "classfile/symbolTable.hpp" 1.10 #include "compiler/compilerOracle.hpp" 1.11 @@ -34,12 +35,14 @@ 1.12 #include "oops/oop.inline.hpp" 1.13 #include "prims/jvmtiExport.hpp" 1.14 #include "runtime/arguments.hpp" 1.15 +#include "runtime/arguments_ext.hpp" 1.16 #include "runtime/globals_extension.hpp" 1.17 #include "runtime/java.hpp" 1.18 #include "services/management.hpp" 1.19 #include "services/memTracker.hpp" 1.20 #include "utilities/defaultStream.hpp" 1.21 #include "utilities/macros.hpp" 1.22 +#include "utilities/stringUtils.hpp" 1.23 #include "utilities/taskqueue.hpp" 1.24 #ifdef TARGET_OS_FAMILY_linux 1.25 # include "os_linux.inline.hpp" 1.26 @@ -98,6 +101,8 @@ 1.27 bool Arguments::_has_profile = false; 1.28 size_t Arguments::_conservative_max_heap_alignment = 0; 1.29 uintx Arguments::_min_heap_size = 0; 1.30 +uintx Arguments::_min_heap_free_ratio = 0; 1.31 +uintx Arguments::_max_heap_free_ratio = 0; 1.32 Arguments::Mode Arguments::_mode = _mixed; 1.33 bool Arguments::_java_compiler = false; 1.34 bool Arguments::_xdebug_mode = false; 1.35 @@ -294,6 +299,7 @@ 1.36 { "UseMPSS", JDK_Version::jdk(8), JDK_Version::jdk(9) }, 1.37 { "UseStringCache", JDK_Version::jdk(8), JDK_Version::jdk(9) }, 1.38 { "UseOldInlining", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 1.39 + { "AutoShutdownNMT", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 1.40 #ifdef PRODUCT 1.41 { "DesiredMethodLimit", 1.42 JDK_Version::jdk_update(7, 2), JDK_Version::jdk(8) }, 1.43 @@ -1108,11 +1114,11 @@ 1.44 // Conflict: required to use shared spaces (-Xshare:on), but 1.45 // incompatible command line options were chosen. 1.46 1.47 -static void no_shared_spaces() { 1.48 +static void no_shared_spaces(const char* message) { 1.49 if (RequireSharedSpaces) { 1.50 jio_fprintf(defaultStream::error_stream(), 1.51 "Class data sharing is inconsistent with other specified options.\n"); 1.52 - vm_exit_during_initialization("Unable to use shared archive.", NULL); 1.53 + vm_exit_during_initialization("Unable to use shared archive.", message); 1.54 } else { 1.55 FLAG_SET_DEFAULT(UseSharedSpaces, false); 1.56 } 1.57 @@ -1398,10 +1404,26 @@ 1.58 (int)ObjectAlignmentInBytes, os::vm_page_size()); 1.59 return false; 1.60 } 1.61 + if(SurvivorAlignmentInBytes == 0) { 1.62 + SurvivorAlignmentInBytes = ObjectAlignmentInBytes; 1.63 + } else { 1.64 + if (!is_power_of_2(SurvivorAlignmentInBytes)) { 1.65 + jio_fprintf(defaultStream::error_stream(), 1.66 + "error: SurvivorAlignmentInBytes=%d must be power of 2\n", 1.67 + (int)SurvivorAlignmentInBytes); 1.68 + return false; 1.69 + } 1.70 + if (SurvivorAlignmentInBytes < ObjectAlignmentInBytes) { 1.71 + jio_fprintf(defaultStream::error_stream(), 1.72 + "error: SurvivorAlignmentInBytes=%d must be greater than ObjectAlignmentInBytes=%d \n", 1.73 + (int)SurvivorAlignmentInBytes, (int)ObjectAlignmentInBytes); 1.74 + return false; 1.75 + } 1.76 + } 1.77 return true; 1.78 } 1.79 1.80 -uintx Arguments::max_heap_for_compressed_oops() { 1.81 +size_t Arguments::max_heap_for_compressed_oops() { 1.82 // Avoid sign flip. 1.83 assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size"); 1.84 // We need to fit both the NULL page and the heap into the memory budget, while 1.85 @@ -1505,28 +1527,31 @@ 1.86 heap_alignment = G1CollectedHeap::conservative_max_heap_alignment(); 1.87 } 1.88 #endif // INCLUDE_ALL_GCS 1.89 - _conservative_max_heap_alignment = MAX3(heap_alignment, os::max_page_size(), 1.90 - CollectorPolicy::compute_heap_alignment()); 1.91 + _conservative_max_heap_alignment = MAX4(heap_alignment, 1.92 + (size_t)os::vm_allocation_granularity(), 1.93 + os::max_page_size(), 1.94 + CollectorPolicy::compute_heap_alignment()); 1.95 } 1.96 1.97 -void Arguments::set_ergonomics_flags() { 1.98 - 1.99 +void Arguments::select_gc_ergonomically() { 1.100 if (os::is_server_class_machine()) { 1.101 - // If no other collector is requested explicitly, 1.102 - // let the VM select the collector based on 1.103 - // machine class and automatic selection policy. 1.104 - if (!UseSerialGC && 1.105 - !UseConcMarkSweepGC && 1.106 - !UseG1GC && 1.107 - !UseParNewGC && 1.108 - FLAG_IS_DEFAULT(UseParallelGC)) { 1.109 - if (should_auto_select_low_pause_collector()) { 1.110 - FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true); 1.111 - } else { 1.112 - FLAG_SET_ERGO(bool, UseParallelGC, true); 1.113 - } 1.114 + if (should_auto_select_low_pause_collector()) { 1.115 + FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true); 1.116 + } else { 1.117 + FLAG_SET_ERGO(bool, UseParallelGC, true); 1.118 } 1.119 } 1.120 +} 1.121 + 1.122 +void Arguments::select_gc() { 1.123 + if (!gc_selected()) { 1.124 + ArgumentsExt::select_gc_ergonomically(); 1.125 + } 1.126 +} 1.127 + 1.128 +void Arguments::set_ergonomics_flags() { 1.129 + select_gc(); 1.130 + 1.131 #ifdef COMPILER2 1.132 // Shared spaces work fine with other GCs but causes bytecode rewriting 1.133 // to be disabled, which hurts interpreter performance and decreases 1.134 @@ -1535,7 +1560,7 @@ 1.135 // at link time, or rewrite bytecodes in non-shared methods. 1.136 if (!DumpSharedSpaces && !RequireSharedSpaces && 1.137 (FLAG_IS_DEFAULT(UseSharedSpaces) || !UseSharedSpaces)) { 1.138 - no_shared_spaces(); 1.139 + no_shared_spaces("COMPILER2 default: -Xshare:auto | off, have to manually setup to on."); 1.140 } 1.141 #endif 1.142 1.143 @@ -1578,9 +1603,11 @@ 1.144 // unless the user actually sets these flags. 1.145 if (FLAG_IS_DEFAULT(MinHeapFreeRatio)) { 1.146 FLAG_SET_DEFAULT(MinHeapFreeRatio, 0); 1.147 + _min_heap_free_ratio = MinHeapFreeRatio; 1.148 } 1.149 if (FLAG_IS_DEFAULT(MaxHeapFreeRatio)) { 1.150 FLAG_SET_DEFAULT(MaxHeapFreeRatio, 100); 1.151 + _max_heap_free_ratio = MaxHeapFreeRatio; 1.152 } 1.153 } 1.154 1.155 @@ -1619,6 +1646,12 @@ 1.156 Abstract_VM_Version::parallel_worker_threads()); 1.157 } 1.158 1.159 +#if INCLUDE_ALL_GCS 1.160 + if (G1ConcRefinementThreads == 0) { 1.161 + FLAG_SET_DEFAULT(G1ConcRefinementThreads, ParallelGCThreads); 1.162 + } 1.163 +#endif 1.164 + 1.165 // MarkStackSize will be set (if it hasn't been set by the user) 1.166 // when concurrent marking is initialized. 1.167 // Its value will be based upon the number of parallel marking threads. 1.168 @@ -1644,6 +1677,46 @@ 1.169 } 1.170 } 1.171 1.172 +#if !INCLUDE_ALL_GCS 1.173 +#ifdef ASSERT 1.174 +static bool verify_serial_gc_flags() { 1.175 + return (UseSerialGC && 1.176 + !(UseParNewGC || (UseConcMarkSweepGC || CMSIncrementalMode) || UseG1GC || 1.177 + UseParallelGC || UseParallelOldGC)); 1.178 +} 1.179 +#endif // ASSERT 1.180 +#endif // INCLUDE_ALL_GCS 1.181 + 1.182 +void Arguments::set_gc_specific_flags() { 1.183 +#if INCLUDE_ALL_GCS 1.184 + // Set per-collector flags 1.185 + if (UseParallelGC || UseParallelOldGC) { 1.186 + set_parallel_gc_flags(); 1.187 + } else if (UseConcMarkSweepGC) { // Should be done before ParNew check below 1.188 + set_cms_and_parnew_gc_flags(); 1.189 + } else if (UseParNewGC) { // Skipped if CMS is set above 1.190 + set_parnew_gc_flags(); 1.191 + } else if (UseG1GC) { 1.192 + set_g1_gc_flags(); 1.193 + } 1.194 + check_deprecated_gcs(); 1.195 + check_deprecated_gc_flags(); 1.196 + if (AssumeMP && !UseSerialGC) { 1.197 + if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) { 1.198 + warning("If the number of processors is expected to increase from one, then" 1.199 + " you should configure the number of parallel GC threads appropriately" 1.200 + " using -XX:ParallelGCThreads=N"); 1.201 + } 1.202 + } 1.203 + if (MinHeapFreeRatio == 100) { 1.204 + // Keeping the heap 100% free is hard ;-) so limit it to 99%. 1.205 + FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99); 1.206 + } 1.207 +#else // INCLUDE_ALL_GCS 1.208 + assert(verify_serial_gc_flags(), "SerialGC unset"); 1.209 +#endif // INCLUDE_ALL_GCS 1.210 +} 1.211 + 1.212 julong Arguments::limit_by_allocatable_memory(julong limit) { 1.213 julong max_allocatable; 1.214 julong result = limit; 1.215 @@ -1867,16 +1940,6 @@ 1.216 return false; 1.217 } 1.218 1.219 -#if !INCLUDE_ALL_GCS 1.220 -#ifdef ASSERT 1.221 -static bool verify_serial_gc_flags() { 1.222 - return (UseSerialGC && 1.223 - !(UseParNewGC || (UseConcMarkSweepGC || CMSIncrementalMode) || UseG1GC || 1.224 - UseParallelGC || UseParallelOldGC)); 1.225 -} 1.226 -#endif // ASSERT 1.227 -#endif // INCLUDE_ALL_GCS 1.228 - 1.229 // check if do gclog rotation 1.230 // +UseGCLogFileRotation is a must, 1.231 // no gc log rotation when log file not supplied or 1.232 @@ -1955,6 +2018,8 @@ 1.233 MaxHeapFreeRatio); 1.234 return false; 1.235 } 1.236 + // This does not set the flag itself, but stores the value in a safe place for later usage. 1.237 + _min_heap_free_ratio = min_heap_free_ratio; 1.238 return true; 1.239 } 1.240 1.241 @@ -1969,11 +2034,13 @@ 1.242 MinHeapFreeRatio); 1.243 return false; 1.244 } 1.245 + // This does not set the flag itself, but stores the value in a safe place for later usage. 1.246 + _max_heap_free_ratio = max_heap_free_ratio; 1.247 return true; 1.248 } 1.249 1.250 // Check consistency of GC selection 1.251 -bool Arguments::check_gc_consistency() { 1.252 +bool Arguments::check_gc_consistency_user() { 1.253 check_gclog_consistency(); 1.254 bool status = true; 1.255 // Ensure that the user has not selected conflicting sets 1.256 @@ -2139,7 +2206,7 @@ 1.257 FLAG_SET_DEFAULT(UseGCOverheadLimit, false); 1.258 } 1.259 1.260 - status = status && check_gc_consistency(); 1.261 + status = status && ArgumentsExt::check_gc_consistency_user(); 1.262 status = status && check_stack_pages(); 1.263 1.264 if (CMSIncrementalMode) { 1.265 @@ -2322,10 +2389,13 @@ 1.266 status = status && verify_percentage(MarkSweepDeadRatio, "MarkSweepDeadRatio"); 1.267 1.268 status = status && verify_min_value(MarkSweepAlwaysCompactCount, 1, "MarkSweepAlwaysCompactCount"); 1.269 +#ifdef COMPILER1 1.270 + status = status && verify_min_value(ValueMapInitialSize, 1, "ValueMapInitialSize"); 1.271 +#endif 1.272 1.273 if (PrintNMTStatistics) { 1.274 #if INCLUDE_NMT 1.275 - if (MemTracker::tracking_level() == MemTracker::NMT_off) { 1.276 + if (MemTracker::tracking_level() == NMT_off) { 1.277 #endif // INCLUDE_NMT 1.278 warning("PrintNMTStatistics is disabled, because native memory tracking is not enabled"); 1.279 PrintNMTStatistics = false; 1.280 @@ -3226,6 +3296,15 @@ 1.281 } 1.282 } 1.283 1.284 + // PrintSharedArchiveAndExit will turn on 1.285 + // -Xshare:on 1.286 + // -XX:+TraceClassPaths 1.287 + if (PrintSharedArchiveAndExit) { 1.288 + FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); 1.289 + FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true); 1.290 + FLAG_SET_CMDLINE(bool, TraceClassPaths, true); 1.291 + } 1.292 + 1.293 // Change the default value for flags which have different default values 1.294 // when working with older JDKs. 1.295 #ifdef LINUX 1.296 @@ -3234,9 +3313,55 @@ 1.297 FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false); 1.298 } 1.299 #endif // LINUX 1.300 + fix_appclasspath(); 1.301 return JNI_OK; 1.302 } 1.303 1.304 +// Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled) 1.305 +// 1.306 +// This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar 1.307 +// in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar". 1.308 +// Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty 1.309 +// path is treated as the current directory. 1.310 +// 1.311 +// This causes problems with CDS, which requires that all directories specified in the classpath 1.312 +// must be empty. In most cases, applications do NOT want to load classes from the current 1.313 +// directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up 1.314 +// scripts compatible with CDS. 1.315 +void Arguments::fix_appclasspath() { 1.316 + if (IgnoreEmptyClassPaths) { 1.317 + const char separator = *os::path_separator(); 1.318 + const char* src = _java_class_path->value(); 1.319 + 1.320 + // skip over all the leading empty paths 1.321 + while (*src == separator) { 1.322 + src ++; 1.323 + } 1.324 + 1.325 + char* copy = AllocateHeap(strlen(src) + 1, mtInternal); 1.326 + strncpy(copy, src, strlen(src) + 1); 1.327 + 1.328 + // trim all trailing empty paths 1.329 + for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) { 1.330 + *tail = '\0'; 1.331 + } 1.332 + 1.333 + char from[3] = {separator, separator, '\0'}; 1.334 + char to [2] = {separator, '\0'}; 1.335 + while (StringUtils::replace_no_expand(copy, from, to) > 0) { 1.336 + // Keep replacing "::" -> ":" until we have no more "::" (non-windows) 1.337 + // Keep replacing ";;" -> ";" until we have no more ";;" (windows) 1.338 + } 1.339 + 1.340 + _java_class_path->set_value(copy); 1.341 + FreeHeap(copy); // a copy was made by set_value, so don't need this anymore 1.342 + } 1.343 + 1.344 + if (!PrintSharedArchiveAndExit) { 1.345 + ClassLoader::trace_class_path("[classpath: ", _java_class_path->value()); 1.346 + } 1.347 +} 1.348 + 1.349 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) { 1.350 // This must be done after all -D arguments have been processed. 1.351 scp_p->expand_endorsed(); 1.352 @@ -3306,7 +3431,7 @@ 1.353 } 1.354 } 1.355 1.356 - if (!check_vm_args_consistency()) { 1.357 + if (!ArgumentsExt::check_vm_args_consistency()) { 1.358 return JNI_ERR; 1.359 } 1.360 1.361 @@ -3407,9 +3532,8 @@ 1.362 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); 1.363 } 1.364 } else { 1.365 - // UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces. 1.366 if (!UseCompressedOops || !UseCompressedClassPointers) { 1.367 - no_shared_spaces(); 1.368 + no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces."); 1.369 } 1.370 #endif 1.371 } 1.372 @@ -3517,15 +3641,24 @@ 1.373 CommandLineFlags::printFlags(tty, false); 1.374 vm_exit(0); 1.375 } 1.376 +#if INCLUDE_NMT 1.377 if (match_option(option, "-XX:NativeMemoryTracking", &tail)) { 1.378 -#if INCLUDE_NMT 1.379 - MemTracker::init_tracking_options(tail); 1.380 -#else 1.381 - jio_fprintf(defaultStream::error_stream(), 1.382 - "Native Memory Tracking is not supported in this VM\n"); 1.383 - return JNI_ERR; 1.384 + // The launcher did not setup nmt environment variable properly. 1.385 + if (!MemTracker::check_launcher_nmt_support(tail)) { 1.386 + warning("Native Memory Tracking did not setup properly, using wrong launcher?"); 1.387 + } 1.388 + 1.389 + // Verify if nmt option is valid. 1.390 + if (MemTracker::verify_nmt_option()) { 1.391 + // Late initialization, still in single-threaded mode. 1.392 + if (MemTracker::tracking_level() >= NMT_summary) { 1.393 + MemTracker::init(); 1.394 + } 1.395 + } else { 1.396 + vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL); 1.397 + } 1.398 + } 1.399 #endif 1.400 - } 1.401 1.402 1.403 #ifndef PRODUCT 1.404 @@ -3663,7 +3796,7 @@ 1.405 FLAG_SET_DEFAULT(UseSharedSpaces, false); 1.406 FLAG_SET_DEFAULT(PrintSharedSpaces, false); 1.407 } 1.408 - no_shared_spaces(); 1.409 + no_shared_spaces("CDS Disabled"); 1.410 #endif // INCLUDE_CDS 1.411 1.412 return JNI_OK; 1.413 @@ -3677,7 +3810,7 @@ 1.414 set_shared_spaces_flags(); 1.415 1.416 // Check the GC selections again. 1.417 - if (!check_gc_consistency()) { 1.418 + if (!ArgumentsExt::check_gc_consistency_ergo()) { 1.419 return JNI_EINVAL; 1.420 } 1.421 1.422 @@ -3699,33 +3832,7 @@ 1.423 // Set heap size based on available physical memory 1.424 set_heap_size(); 1.425 1.426 -#if INCLUDE_ALL_GCS 1.427 - // Set per-collector flags 1.428 - if (UseParallelGC || UseParallelOldGC) { 1.429 - set_parallel_gc_flags(); 1.430 - } else if (UseConcMarkSweepGC) { // Should be done before ParNew check below 1.431 - set_cms_and_parnew_gc_flags(); 1.432 - } else if (UseParNewGC) { // Skipped if CMS is set above 1.433 - set_parnew_gc_flags(); 1.434 - } else if (UseG1GC) { 1.435 - set_g1_gc_flags(); 1.436 - } 1.437 - check_deprecated_gcs(); 1.438 - check_deprecated_gc_flags(); 1.439 - if (AssumeMP && !UseSerialGC) { 1.440 - if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) { 1.441 - warning("If the number of processors is expected to increase from one, then" 1.442 - " you should configure the number of parallel GC threads appropriately" 1.443 - " using -XX:ParallelGCThreads=N"); 1.444 - } 1.445 - } 1.446 - if (MinHeapFreeRatio == 100) { 1.447 - // Keeping the heap 100% free is hard ;-) so limit it to 99%. 1.448 - FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99); 1.449 - } 1.450 -#else // INCLUDE_ALL_GCS 1.451 - assert(verify_serial_gc_flags(), "SerialGC unset"); 1.452 -#endif // INCLUDE_ALL_GCS 1.453 + set_gc_specific_flags(); 1.454 1.455 // Initialize Metaspace flags and alignments. 1.456 Metaspace::ergo_initialize(); 1.457 @@ -3781,10 +3888,6 @@ 1.458 // nothing to use the profiling, turn if off 1.459 FLAG_SET_DEFAULT(TypeProfileLevel, 0); 1.460 } 1.461 - if (UseTypeSpeculation && FLAG_IS_DEFAULT(ReplaceInParentMaps)) { 1.462 - // Doing the replace in parent maps helps speculation 1.463 - FLAG_SET_DEFAULT(ReplaceInParentMaps, true); 1.464 - } 1.465 #endif 1.466 1.467 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) { 1.468 @@ -3842,18 +3945,24 @@ 1.469 } 1.470 1.471 jint Arguments::adjust_after_os() { 1.472 -#if INCLUDE_ALL_GCS 1.473 - if (UseParallelGC || UseParallelOldGC) { 1.474 - if (UseNUMA) { 1.475 + if (UseNUMA) { 1.476 + if (UseParallelGC || UseParallelOldGC) { 1.477 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) { 1.478 - FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M); 1.479 + FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M); 1.480 } 1.481 - // For those collectors or operating systems (eg, Windows) that do 1.482 - // not support full UseNUMA, we will map to UseNUMAInterleaving for now 1.483 - UseNUMAInterleaving = true; 1.484 + } 1.485 + // UseNUMAInterleaving is set to ON for all collectors and 1.486 + // platforms when UseNUMA is set to ON. NUMA-aware collectors 1.487 + // such as the parallel collector for Linux and Solaris will 1.488 + // interleave old gen and survivor spaces on top of NUMA 1.489 + // allocation policy for the eden space. 1.490 + // Non NUMA-aware collectors such as CMS, G1 and Serial-GC on 1.491 + // all platforms and ParallelGC on Windows will interleave all 1.492 + // of the heap spaces across NUMA nodes. 1.493 + if (FLAG_IS_DEFAULT(UseNUMAInterleaving)) { 1.494 + FLAG_SET_ERGO(bool, UseNUMAInterleaving, true); 1.495 } 1.496 } 1.497 -#endif // INCLUDE_ALL_GCS 1.498 return JNI_OK; 1.499 } 1.500