1 /* 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "classfile/classLoader.hpp" 27 #include "classfile/javaAssertions.hpp" 28 #include "classfile/stringTable.hpp" 29 #include "classfile/symbolTable.hpp" 30 #include "compiler/compilerOracle.hpp" 31 #include "memory/allocation.inline.hpp" 32 #include "memory/cardTableRS.hpp" 33 #include "memory/genCollectedHeap.hpp" 34 #include "memory/referenceProcessor.hpp" 35 #include "memory/universe.inline.hpp" 36 #include "oops/oop.inline.hpp" 37 #include "prims/jvmtiExport.hpp" 38 #include "runtime/arguments.hpp" 39 #include "runtime/arguments_ext.hpp" 40 #include "runtime/globals_extension.hpp" 41 #include "runtime/java.hpp" 42 #include "runtime/os.hpp" 43 #include "runtime/vm_version.hpp" 44 #include "services/management.hpp" 45 #include "services/memTracker.hpp" 46 #include "utilities/defaultStream.hpp" 47 #include "utilities/macros.hpp" 48 #include "utilities/stringUtils.hpp" 49 #include "utilities/taskqueue.hpp" 50 #if INCLUDE_ALL_GCS 51 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp" 52 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" 53 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" 54 #endif // INCLUDE_ALL_GCS 55 56 // Note: This is a special bug reporting site for the JVM 57 #define DEFAULT_VENDOR_URL_BUG "http://bugreport.java.com/bugreport/crash.jsp" 58 #define DEFAULT_JAVA_LAUNCHER "generic" 59 60 // Disable options not supported in this release, with a warning if they 61 // were explicitly requested on the command-line 62 #define UNSUPPORTED_OPTION(opt, description) \ 63 do { \ 64 if (opt) { \ 65 if (FLAG_IS_CMDLINE(opt)) { \ 66 warning(description " is disabled in this release."); \ 67 } \ 68 FLAG_SET_DEFAULT(opt, false); \ 69 } \ 70 } while(0) 71 72 #define UNSUPPORTED_GC_OPTION(gc) \ 73 do { \ 74 if (gc) { \ 75 if (FLAG_IS_CMDLINE(gc)) { \ 76 warning(#gc " is not supported in this VM. Using Serial GC."); \ 77 } \ 78 FLAG_SET_DEFAULT(gc, false); \ 79 } \ 80 } while(0) 81 82 char** Arguments::_jvm_flags_array = NULL; 83 int Arguments::_num_jvm_flags = 0; 84 char** Arguments::_jvm_args_array = NULL; 85 int Arguments::_num_jvm_args = 0; 86 char* Arguments::_java_command = NULL; 87 SystemProperty* Arguments::_system_properties = NULL; 88 const char* Arguments::_gc_log_filename = NULL; 89 bool Arguments::_has_profile = false; 90 size_t Arguments::_conservative_max_heap_alignment = 0; 91 uintx Arguments::_min_heap_size = 0; 92 uintx Arguments::_min_heap_free_ratio = 0; 93 uintx Arguments::_max_heap_free_ratio = 0; 94 Arguments::Mode Arguments::_mode = _mixed; 95 bool Arguments::_java_compiler = false; 96 bool Arguments::_xdebug_mode = false; 97 const char* Arguments::_java_vendor_url_bug = DEFAULT_VENDOR_URL_BUG; 98 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER; 99 int Arguments::_sun_java_launcher_pid = -1; 100 bool Arguments::_sun_java_launcher_is_altjvm = false; 101 102 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*) 103 bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 104 bool Arguments::_UseOnStackReplacement = UseOnStackReplacement; 105 bool Arguments::_BackgroundCompilation = BackgroundCompilation; 106 bool Arguments::_ClipInlining = ClipInlining; 107 108 char* Arguments::SharedArchivePath = NULL; 109 110 AgentLibraryList Arguments::_libraryList; 111 AgentLibraryList Arguments::_agentList; 112 113 abort_hook_t Arguments::_abort_hook = NULL; 114 exit_hook_t Arguments::_exit_hook = NULL; 115 vfprintf_hook_t Arguments::_vfprintf_hook = NULL; 116 117 118 SystemProperty *Arguments::_sun_boot_library_path = NULL; 119 SystemProperty *Arguments::_java_library_path = NULL; 120 SystemProperty *Arguments::_java_home = NULL; 121 SystemProperty *Arguments::_java_class_path = NULL; 122 SystemProperty *Arguments::_sun_boot_class_path = NULL; 123 124 char* Arguments::_meta_index_path = NULL; 125 char* Arguments::_meta_index_dir = NULL; 126 char* Arguments::_ext_dirs = NULL; 127 128 // Check if head of 'option' matches 'name', and sets 'tail' to the remaining 129 // part of the option string. 130 131 static bool match_option(const JavaVMOption *option, const char* name, 132 const char** tail) { 133 int len = (int) strlen(name); 134 if (strncmp(option->optionString, name, len) == 0) { 135 *tail = option->optionString + len; 136 return true; 137 } else { 138 return false; 139 } 140 } 141 142 // Check if 'option' matches 'name'. No "tail" is allowed. 143 144 static bool match_option(const JavaVMOption *option, const char* name) { 145 const char* tail = NULL; 146 bool result = match_option(option, name, &tail); 147 if (tail != NULL && *tail == '\0') { 148 return result; 149 } else { 150 return false; 151 } 152 } 153 154 // Return true if any of the strings in null-terminated array 'names' matches. 155 // If tail_allowed is true, then the tail must begin with a colon; otherwise, 156 // the option must match exactly. 157 158 static bool match_option(const JavaVMOption* option, const char** names, const char** tail, 159 bool tail_allowed) { 160 for (/* empty */; *names != NULL; ++names) { 161 if (match_option(option, *names, tail)) { 162 if (**tail == '\0' || tail_allowed && **tail == ':') { 163 return true; 164 } 165 } 166 } 167 return false; 168 } 169 170 static void logOption(const char* opt) { 171 if (PrintVMOptions) { 172 jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt); 173 } 174 } 175 176 // Process java launcher properties. 177 178 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) { 179 // See if sun.java.launcher, sun.java.launcher.is_altjvm or 180 // sun.java.launcher.pid is defined. 181 // Must do this before setting up other system properties, 182 // as some of them may depend on launcher type. 183 for (int index = 0; index < args->nOptions; index++) { 184 const JavaVMOption* option = args->options + index; 185 const char* tail; 186 187 if (match_option(option, "-Dsun.java.launcher=", &tail)) { 188 process_java_launcher_argument(tail, option->extraInfo); 189 continue; 190 } 191 if (match_option(option, "-Dsun.java.launcher.is_altjvm=", &tail)) { 192 if (strcmp(tail, "true") == 0) { 193 _sun_java_launcher_is_altjvm = true; 194 } 195 continue; 196 } 197 if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) { 198 _sun_java_launcher_pid = atoi(tail); 199 continue; 200 } 201 } 202 } 203 204 // Initialize system properties key and value. 205 206 void Arguments::init_system_properties() { 207 208 PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name", 209 "Java Virtual Machine Specification", false)); 210 PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(), false)); 211 PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(), false)); 212 PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(), true)); 213 214 // Following are JVMTI agent writable properties. 215 // Properties values are set to NULL and they are 216 // os specific they are initialized in os::init_system_properties_values(). 217 _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL, true); 218 _java_library_path = new SystemProperty("java.library.path", NULL, true); 219 _java_home = new SystemProperty("java.home", NULL, true); 220 _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL, true); 221 222 _java_class_path = new SystemProperty("java.class.path", "", true); 223 224 // Add to System Property list. 225 PropertyList_add(&_system_properties, _sun_boot_library_path); 226 PropertyList_add(&_system_properties, _java_library_path); 227 PropertyList_add(&_system_properties, _java_home); 228 PropertyList_add(&_system_properties, _java_class_path); 229 PropertyList_add(&_system_properties, _sun_boot_class_path); 230 231 // Set OS specific system properties values 232 os::init_system_properties_values(); 233 } 234 235 236 // Update/Initialize System properties after JDK version number is known 237 238 void Arguments::init_version_specific_system_properties() { 239 240 enum { 241 bufsz = 16 242 }; 243 char buffer[bufsz]; 244 const char* spec_vendor = "Sun Microsystems Inc."; 245 uint32_t spec_version = 0; 246 247 spec_vendor = "Oracle Corporation"; 248 spec_version = JDK_Version::current().major_version(); 249 jio_snprintf(buffer, bufsz, "1." UINT32_FORMAT, spec_version); 250 251 PropertyList_add(&_system_properties, 252 new SystemProperty("java.vm.specification.vendor", spec_vendor, false)); 253 PropertyList_add(&_system_properties, 254 new SystemProperty("java.vm.specification.version", buffer, false)); 255 PropertyList_add(&_system_properties, 256 new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(), false)); 257 } 258 259 /* 260 * -XX argument processing: 261 * 262 * -XX arguments are usually defined in globals.hpp, globals_<cpu>.hpp, globals_<os>.hpp, <compiler>_globals.hpp, or <gc>_globals.hpp. 263 * -XX arguments are parsed in parse_argument(). 264 * -XX argument bounds checking is done in check_vm_args_consistency(). 265 * 266 * Over time -XX arguments may change. There are mechanisms to handle common cases: 267 * 268 * ALIAS: An option may be renamed or replaced by another option. The old name can be supported by adding 269 * the old and new option names to the "aliased_jvm_flags" table. Delete the old variable from globals.hpp. 270 * This is often part of the process of deprecating a flag, but not all aliases need to be deprecated. 271 * 272 * DEPRECATED: An option may be supported, but a warning is printed to let the user know that support may be removed 273 * in the future. Both regular and aliased options may be deprecated. 274 * Add a deprecation warning for an option (or alias) by adding an entry in the "deprecated_jvm_flags" table. 275 * Specify the option name, the jdk version that deprecated the option, and the jdk version that will 276 * expire the option (if removal has been scheduled). 277 * 278 * OBSOLETE: An option may be removed (and deleted from globals.hpp), but still be accepted on the command line. 279 * A warning is printed to let the user know that support may be removed in the future. 280 * Add an obsolete warning for an option (or alias) by adding an entry in the "obsolete_jvm_flags" table. 281 * Specify the option name, the jdk version that obsoleted the option, and the jdk version that will 282 * expire the option (if removal has been scheduled). 283 * 284 * EXPIRED: When the current JDK version is equal or greater to the "accept_until" version of a deprecated or obsolete 285 * option, the system will flatly refuse to admit the existence of the flag. This allows a flag to die correctly 286 * over JDK releases using HSX. 287 * Note that manual cleanup of expired options should be done at major JDK version upgrades: 288 * - Expired options can be removed from the obsolete_jvm_flags, deprecated_jvm_flags tables, and aliased_jvm_flags tables. 289 * - Expired deprecated options may still have global variable definitions that should be removed (in globals.hpp, etc). 290 * 291 * Tests: Aliases are tested in VMAliasOptions.java. Deprecated options in VMDeprecatedOptions.java. Obsolete options are tested in various files. 292 */ 293 294 // Obsolete or deprecated -XX flag. 295 296 typedef struct SpecialFlag { 297 const char* name; 298 JDK_Version obsoleted_in; // When the warning started (obsolete or deprecated). 299 JDK_Version accept_until; // Which version to start denying the existence of the flag (if scheduled). 300 301 static const uint8_t _removal_unscheduled = 0; 302 303 bool is_removal_scheduled() const { 304 return accept_until.major_version() != _removal_unscheduled; 305 } 306 307 } SpecialFlag; 308 309 // When a flag is eliminated, it can be added to this list in order to 310 // continue accepting this flag on the command-line, while issuing a warning 311 // and ignoring the value. Once the JDK version reaches the 'accept_until' 312 // limit, we flatly refuse to admit the existence of the flag. 313 static SpecialFlag const obsolete_jvm_flags[] = { 314 { "UseTrainGC", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 315 { "UseSpecialLargeObjectHandling", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 316 { "UseOversizedCarHandling", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 317 { "TraceCarAllocation", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 318 { "PrintTrainGCProcessingStats", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 319 { "LogOfCarSpaceSize", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 320 { "OversizedCarThreshold", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 321 { "MinTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 322 { "DefaultTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 323 { "MaxTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 324 { "DelayTickAdjustment", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 325 { "ProcessingToTenuringRatio", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 326 { "MinTrainLength", JDK_Version::jdk(5), JDK_Version::jdk(7)}, 327 { "AppendRatio", JDK_Version::jdk_update(6, 10), JDK_Version::jdk(7)}, 328 { "DefaultMaxRAM", JDK_Version::jdk_update(6, 18), JDK_Version::jdk(7)}, 329 { "DefaultInitialRAMFraction", 330 JDK_Version::jdk_update(6, 18), JDK_Version::jdk(7)}, 331 { "UseDepthFirstScavengeOrder", 332 JDK_Version::jdk_update(6, 22), JDK_Version::jdk(7)}, 333 { "HandlePromotionFailure", 334 JDK_Version::jdk_update(6, 24), JDK_Version::jdk(8)}, 335 { "MaxLiveObjectEvacuationRatio", 336 JDK_Version::jdk_update(6, 24), JDK_Version::jdk(8)}, 337 { "ForceSharedSpaces", JDK_Version::jdk_update(6, 25), JDK_Version::jdk(8)}, 338 { "UseParallelOldGCCompacting", 339 JDK_Version::jdk_update(6, 27), JDK_Version::jdk(8)}, 340 { "UseParallelDensePrefixUpdate", 341 JDK_Version::jdk_update(6, 27), JDK_Version::jdk(8)}, 342 { "UseParallelOldGCDensePrefix", 343 JDK_Version::jdk_update(6, 27), JDK_Version::jdk(8)}, 344 { "AllowTransitionalJSR292", JDK_Version::jdk(7), JDK_Version::jdk(8)}, 345 { "UseCompressedStrings", JDK_Version::jdk(7), JDK_Version::jdk(8)}, 346 { "CMSPermGenPrecleaningEnabled", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 347 { "CMSTriggerPermRatio", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 348 { "CMSInitiatingPermOccupancyFraction", 349 JDK_Version::jdk(8), JDK_Version::jdk(9)}, 350 { "AdaptivePermSizeWeight", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 351 { "PermGenPadding", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 352 { "PermMarkSweepDeadRatio", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 353 { "PermSize", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 354 { "MaxPermSize", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 355 { "MinPermHeapExpansion", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 356 { "MaxPermHeapExpansion", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 357 { "CMSRevisitStackSize", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 358 { "PrintRevisitStats", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 359 { "UseVectoredExceptions", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 360 { "UseSplitVerifier", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 361 { "UseISM", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 362 { "UsePermISM", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 363 { "UseMPSS", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 364 { "UseStringCache", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 365 { "UseOldInlining", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 366 { "SafepointPollOffset", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 367 #ifdef PRODUCT 368 { "DesiredMethodLimit", JDK_Version::jdk_update(7, 2), JDK_Version::jdk(8)}, 369 #endif // PRODUCT 370 { "UseVMInterruptibleIO", JDK_Version::jdk(8), JDK_Version::jdk(9)}, 371 { "UseBoundThreads", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 372 { "DefaultThreadPriority", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 373 { "NoYieldsInMicrolock", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 374 { "BackEdgeThreshold", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 375 { "UseNewReflection", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 376 { "ReflectionWrapResolutionErrors", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 377 { "VerifyReflectionBytecodes", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 378 { "AutoShutdownNMT", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 379 { "NmethodSweepFraction", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 380 { "NmethodSweepCheckInterval", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 381 { "CodeCacheMinimumFreeSpace", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 382 #ifndef ZERO 383 { "UseFastAccessorMethods", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 384 { "UseFastEmptyMethods", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 385 #endif // ZERO 386 { "UseCompilerSafepoints", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 387 { NULL, JDK_Version(0), JDK_Version(0)} 388 }; 389 390 // When a flag is deprecated, it can be added to this list in order to issuing a warning when the flag is used. 391 // Once the JDK version reaches the 'accept_until' limit, we flatly refuse to admit the existence of the flag. 392 static SpecialFlag const deprecated_jvm_flags[] = { 393 // deprecated non-alias flags: 394 { "MaxGCMinorPauseMillis", JDK_Version::jdk(8), JDK_Version::jdk(SpecialFlag::_removal_unscheduled)}, 395 { "UseParNewGC", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 396 397 // deprecated alias flags (see also aliased_jvm_flags): 398 { "DefaultMaxRAMFraction", JDK_Version::jdk(8), JDK_Version::jdk(SpecialFlag::_removal_unscheduled)}, 399 { "CMSMarkStackSizeMax", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 400 { "CMSMarkStackSize", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 401 { "G1MarkStackSize", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 402 { "ParallelMarkingThreads", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 403 { "ParallelCMSThreads", JDK_Version::jdk(9), JDK_Version::jdk(10)}, 404 { NULL, JDK_Version(0), JDK_Version(0)} 405 }; 406 407 // Flags that are aliases for other flags. 408 409 typedef struct { 410 const char* alias_name; 411 const char* real_name; 412 } AliasedFlag; 413 414 static AliasedFlag const aliased_jvm_flags[] = { 415 { "DefaultMaxRAMFraction", "MaxRAMFraction"}, 416 { "CMSMarkStackSizeMax", "MarkStackSizeMax"}, 417 { "CMSMarkStackSize", "MarkStackSize"}, 418 { "G1MarkStackSize", "MarkStackSize"}, 419 { "ParallelMarkingThreads", "ConcGCThreads"}, 420 { "ParallelCMSThreads", "ConcGCThreads"}, 421 { NULL, NULL} 422 }; 423 424 // Returns 1 if the flag is special and jdk version is in the range specified. 425 // In this case the 'version' buffer is filled in with the version number when 426 // the flag became special. 427 // Returns -1 if the flag is special and has expired (should be ignored). 428 // Returns 0 if the flag is not special. 429 430 static int is_special_flag(const SpecialFlag special_table[], const char *s, JDK_Version* version) { 431 int i = 0; 432 assert(version != NULL, "Must provide a version buffer"); 433 while (special_table[i].name != NULL) { 434 const SpecialFlag& flag_status = special_table[i]; 435 // <flag>=xxx form 436 // [-|+]<flag> form 437 size_t len = strlen(flag_status.name); 438 if (((strncmp(flag_status.name, s, len) == 0) && 439 (strlen(s) == len)) || 440 ((s[0] == '+' || s[0] == '-') && 441 (strncmp(flag_status.name, &s[1], len) == 0) && 442 (strlen(&s[1]) == len))) { 443 if (!flag_status.is_removal_scheduled() || 444 JDK_Version::current().compare(flag_status.accept_until) == -1) { 445 *version = flag_status.obsoleted_in; 446 return 1; 447 } else { 448 return -1; 449 } 450 } 451 i++; 452 } 453 return 0; 454 } 455 456 bool Arguments::is_newly_obsolete(const char *s, JDK_Version* version) { 457 return (is_special_flag(obsolete_jvm_flags, s, version) == 1); 458 } 459 460 int Arguments::is_deprecated_flag(const char *s, JDK_Version* version) { 461 return is_special_flag(deprecated_jvm_flags, s, version); 462 } 463 464 const char* Arguments::real_flag_name(const char *flag_name) { 465 int i = 0; 466 while (aliased_jvm_flags[i].alias_name != NULL) { 467 const AliasedFlag& flag_status = aliased_jvm_flags[i]; 468 size_t len = strlen(flag_status.alias_name); 469 if (((strncmp(flag_status.alias_name, flag_name, len) == 0) && 470 (strlen(flag_name) == len))) { 471 return flag_status.real_name; 472 } 473 i++; 474 } 475 return flag_name; 476 } 477 478 // Constructs the system class path (aka boot class path) from the following 479 // components, in order: 480 // 481 // prefix // from -Xbootclasspath/p:... 482 // base // from os::get_system_properties() or -Xbootclasspath= 483 // suffix // from -Xbootclasspath/a:... 484 // 485 // This could be AllStatic, but it isn't needed after argument processing is 486 // complete. 487 488 class SysClassPath : public StackObj { 489 public: 490 SysClassPath(const char* base); 491 ~SysClassPath(); 492 493 inline void set_base(const char* base); 494 inline void add_prefix(const char* prefix); 495 inline void add_suffix_to_prefix(const char* suffix); 496 inline void add_suffix(const char* suffix); 497 inline void reset_path(const char* base); 498 499 inline const char* get_base() const { 500 return _items[_scp_base]; 501 } 502 503 inline const char* get_prefix() const { 504 return _items[_scp_prefix]; 505 } 506 507 inline const char* get_suffix() const { 508 return _items[_scp_suffix]; 509 } 510 511 // Combine all the components into a single c-heap-allocated string; caller 512 // must free the string if/when no longer needed. 513 char* combined_path(); 514 515 private: 516 // Utility routines. 517 static char* add_to_path(const char* path, const char* str, bool prepend); 518 static char* add_jars_to_path(char* path, const char* directory); 519 520 inline void reset_item_at(int index); 521 522 // Array indices for the items that make up the sysclasspath. All except the 523 // base are allocated in the C heap and freed by this class. 524 525 enum { 526 _scp_prefix, // from -Xbootclasspath/p:... 527 _scp_base, // the default sysclasspath 528 _scp_suffix, // from -Xbootclasspath/a:... 529 _scp_nitems // the number of items, must be last. 530 }; 531 532 const char* _items[_scp_nitems]; 533 }; 534 535 SysClassPath::SysClassPath(const char* base) { 536 memset(_items, 0, sizeof (_items)); 537 _items[_scp_base] = base; 538 } 539 540 SysClassPath::~SysClassPath() { 541 // Free everything except the base. 542 for (int i = 0; i < _scp_nitems; ++i) { 543 if (i != _scp_base) reset_item_at(i); 544 } 545 } 546 547 inline void SysClassPath::set_base(const char* base) { 548 _items[_scp_base] = base; 549 } 550 551 inline void SysClassPath::add_prefix(const char* prefix) { 552 _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true); 553 } 554 555 inline void SysClassPath::add_suffix_to_prefix(const char* suffix) { 556 _items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false); 557 } 558 559 inline void SysClassPath::add_suffix(const char* suffix) { 560 _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false); 561 } 562 563 inline void SysClassPath::reset_item_at(int index) { 564 assert(index < _scp_nitems && index != _scp_base, "just checking"); 565 if (_items[index] != NULL) { 566 FREE_C_HEAP_ARRAY(char, _items[index]); 567 _items[index] = NULL; 568 } 569 } 570 571 inline void SysClassPath::reset_path(const char* base) { 572 // Clear the prefix and suffix. 573 reset_item_at(_scp_prefix); 574 reset_item_at(_scp_suffix); 575 set_base(base); 576 } 577 578 //------------------------------------------------------------------------------ 579 580 581 // Combine the bootclasspath elements, some of which may be null, into a single 582 // c-heap-allocated string. 583 584 char* SysClassPath::combined_path() { 585 assert(_items[_scp_base] != NULL, "empty default sysclasspath"); 586 587 size_t lengths[_scp_nitems]; 588 size_t total_len = 0; 589 590 const char separator = *os::path_separator(); 591 592 // Get the lengths. 593 int i; 594 for (i = 0; i < _scp_nitems; ++i) { 595 if (_items[i] != NULL) { 596 lengths[i] = strlen(_items[i]); 597 // Include space for the separator char (or a NULL for the last item). 598 total_len += lengths[i] + 1; 599 } 600 } 601 assert(total_len > 0, "empty sysclasspath not allowed"); 602 603 // Copy the _items to a single string. 604 char* cp = NEW_C_HEAP_ARRAY(char, total_len, mtInternal); 605 char* cp_tmp = cp; 606 for (i = 0; i < _scp_nitems; ++i) { 607 if (_items[i] != NULL) { 608 memcpy(cp_tmp, _items[i], lengths[i]); 609 cp_tmp += lengths[i]; 610 *cp_tmp++ = separator; 611 } 612 } 613 *--cp_tmp = '\0'; // Replace the extra separator. 614 return cp; 615 } 616 617 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null. 618 619 char* 620 SysClassPath::add_to_path(const char* path, const char* str, bool prepend) { 621 char *cp; 622 623 assert(str != NULL, "just checking"); 624 if (path == NULL) { 625 size_t len = strlen(str) + 1; 626 cp = NEW_C_HEAP_ARRAY(char, len, mtInternal); 627 memcpy(cp, str, len); // copy the trailing null 628 } else { 629 const char separator = *os::path_separator(); 630 size_t old_len = strlen(path); 631 size_t str_len = strlen(str); 632 size_t len = old_len + str_len + 2; 633 634 if (prepend) { 635 cp = NEW_C_HEAP_ARRAY(char, len, mtInternal); 636 char* cp_tmp = cp; 637 memcpy(cp_tmp, str, str_len); 638 cp_tmp += str_len; 639 *cp_tmp = separator; 640 memcpy(++cp_tmp, path, old_len + 1); // copy the trailing null 641 FREE_C_HEAP_ARRAY(char, path); 642 } else { 643 cp = REALLOC_C_HEAP_ARRAY(char, path, len, mtInternal); 644 char* cp_tmp = cp + old_len; 645 *cp_tmp = separator; 646 memcpy(++cp_tmp, str, str_len + 1); // copy the trailing null 647 } 648 } 649 return cp; 650 } 651 652 // Scan the directory and append any jar or zip files found to path. 653 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null. 654 655 char* SysClassPath::add_jars_to_path(char* path, const char* directory) { 656 DIR* dir = os::opendir(directory); 657 if (dir == NULL) return path; 658 659 char dir_sep[2] = {'\0', '\0'}; 660 size_t directory_len = strlen(directory); 661 const char fileSep = *os::file_separator(); 662 if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep; 663 664 /* Scan the directory for jars/zips, appending them to path. */ 665 struct dirent *entry; 666 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal); 667 while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { 668 const char* name = entry->d_name; 669 const char* ext = name + strlen(name) - 4; 670 bool isJarOrZip = ext > name && 671 (os::file_name_strcmp(ext, ".jar") == 0 || 672 os::file_name_strcmp(ext, ".zip") == 0); 673 if (isJarOrZip) { 674 char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name), mtInternal); 675 sprintf(jarpath, "%s%s%s", directory, dir_sep, name); 676 path = add_to_path(path, jarpath, false); 677 FREE_C_HEAP_ARRAY(char, jarpath); 678 } 679 } 680 FREE_C_HEAP_ARRAY(char, dbuf); 681 os::closedir(dir); 682 return path; 683 } 684 685 // Parses a memory size specification string. 686 687 static bool atomull(const char *s, julong* result) { 688 julong n = 0; 689 int args_read = 0; 690 bool is_hex = false; 691 // Skip leading 0[xX] for hexadecimal 692 if (*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')) { 693 s += 2; 694 is_hex = true; 695 args_read = sscanf(s, JULONG_FORMAT_X, &n); 696 } else { 697 args_read = sscanf(s, JULONG_FORMAT, &n); 698 } 699 if (args_read != 1) { 700 return false; 701 } 702 while (*s != '\0' && (isdigit(*s) || (is_hex && isxdigit(*s)))) { 703 s++; 704 } 705 // 4705540: illegal if more characters are found after the first non-digit 706 if (strlen(s) > 1) { 707 return false; 708 } 709 switch (*s) { 710 case 'T': case 't': 711 *result = n * G * K; 712 // Check for overflow. 713 if (*result / ((julong) G * K) != n) return false; 714 return true; 715 case 'G': case 'g': 716 *result = n * G; 717 if (*result / G != n) return false; 718 return true; 719 case 'M': case 'm': 720 *result = n * M; 721 if (*result / M != n) return false; 722 return true; 723 case 'K': case 'k': 724 *result = n * K; 725 if (*result / K != n) return false; 726 return true; 727 case '\0': 728 *result = n; 729 return true; 730 default: 731 return false; 732 } 733 } 734 735 Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size) { 736 if (size < min_size) return arg_too_small; 737 // Check that size will fit in a size_t (only relevant on 32-bit) 738 if (size > max_uintx) return arg_too_big; 739 return arg_in_range; 740 } 741 742 // Describe an argument out of range error 743 744 void Arguments::describe_range_error(ArgsRange errcode) { 745 switch (errcode) { 746 case arg_too_big: 747 jio_fprintf(defaultStream::error_stream(), 748 "The specified size exceeds the maximum " 749 "representable size.\n"); 750 break; 751 case arg_too_small: 752 case arg_unreadable: 753 case arg_in_range: 754 // do nothing for now 755 break; 756 default: 757 ShouldNotReachHere(); 758 } 759 } 760 761 static bool set_bool_flag(const char* name, bool value, Flag::Flags origin) { 762 return CommandLineFlags::boolAtPut(name, &value, origin); 763 } 764 765 static bool set_fp_numeric_flag(const char* name, char* value, Flag::Flags origin) { 766 double v; 767 if (sscanf(value, "%lf", &v) != 1) { 768 return false; 769 } 770 771 if (CommandLineFlags::doubleAtPut(name, &v, origin)) { 772 return true; 773 } 774 return false; 775 } 776 777 static bool set_numeric_flag(const char* name, char* value, Flag::Flags origin) { 778 julong v; 779 intx intx_v; 780 bool is_neg = false; 781 // Check the sign first since atomull() parses only unsigned values. 782 if (*value == '-') { 783 if (!CommandLineFlags::intxAt(name, &intx_v)) { 784 return false; 785 } 786 value++; 787 is_neg = true; 788 } 789 if (!atomull(value, &v)) { 790 return false; 791 } 792 intx_v = (intx) v; 793 if (is_neg) { 794 intx_v = -intx_v; 795 } 796 if (CommandLineFlags::intxAtPut(name, &intx_v, origin)) { 797 return true; 798 } 799 uintx uintx_v = (uintx) v; 800 if (!is_neg && CommandLineFlags::uintxAtPut(name, &uintx_v, origin)) { 801 return true; 802 } 803 uint64_t uint64_t_v = (uint64_t) v; 804 if (!is_neg && CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin)) { 805 return true; 806 } 807 size_t size_t_v = (size_t) v; 808 if (!is_neg && CommandLineFlags::size_tAtPut(name, &size_t_v, origin)) { 809 return true; 810 } 811 return false; 812 } 813 814 static bool set_string_flag(const char* name, const char* value, Flag::Flags origin) { 815 if (!CommandLineFlags::ccstrAtPut(name, &value, origin)) return false; 816 // Contract: CommandLineFlags always returns a pointer that needs freeing. 817 FREE_C_HEAP_ARRAY(char, value); 818 return true; 819 } 820 821 static bool append_to_string_flag(const char* name, const char* new_value, Flag::Flags origin) { 822 const char* old_value = ""; 823 if (!CommandLineFlags::ccstrAt(name, &old_value)) return false; 824 size_t old_len = old_value != NULL ? strlen(old_value) : 0; 825 size_t new_len = strlen(new_value); 826 const char* value; 827 char* free_this_too = NULL; 828 if (old_len == 0) { 829 value = new_value; 830 } else if (new_len == 0) { 831 value = old_value; 832 } else { 833 char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1, mtInternal); 834 // each new setting adds another LINE to the switch: 835 sprintf(buf, "%s\n%s", old_value, new_value); 836 value = buf; 837 free_this_too = buf; 838 } 839 (void) CommandLineFlags::ccstrAtPut(name, &value, origin); 840 // CommandLineFlags always returns a pointer that needs freeing. 841 FREE_C_HEAP_ARRAY(char, value); 842 if (free_this_too != NULL) { 843 // CommandLineFlags made its own copy, so I must delete my own temp. buffer. 844 FREE_C_HEAP_ARRAY(char, free_this_too); 845 } 846 return true; 847 } 848 849 const char* Arguments::handle_aliases_and_deprecation(const char* arg) { 850 const char* real_name = real_flag_name(arg); 851 JDK_Version since = JDK_Version(); 852 switch (is_deprecated_flag(arg, &since)) { 853 case -1: 854 return NULL; 855 case 0: 856 return real_name; 857 case 1: 858 { 859 char version[256]; 860 since.to_string(version, sizeof (version)); 861 if (real_name != arg) { 862 warning("option %s was deprecated in version %s and will likely be removed in a future release. Use option %s instead.", 863 arg, version, real_name); 864 } else { 865 warning("option %s was deprecated in version %s and will likely be removed in a future release.", 866 arg, version); 867 } 868 return real_name; 869 } 870 } 871 ShouldNotReachHere(); 872 return NULL; 873 } 874 875 bool Arguments::parse_argument(const char* arg, Flag::Flags origin) { 876 877 // range of acceptable characters spelled out for portability reasons 878 #define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]" 879 #define BUFLEN 255 880 char name[BUFLEN + 1]; 881 char dummy; 882 const char* real_name; 883 884 if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) { 885 real_name = handle_aliases_and_deprecation(name); 886 if (real_name == NULL) { 887 return false; // "name" is a deprecated option that has expired. 888 } 889 return set_bool_flag(real_name, false, origin); 890 } 891 if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) { 892 real_name = handle_aliases_and_deprecation(name); 893 if (real_name == NULL) { 894 return false; 895 } 896 return set_bool_flag(real_name, true, origin); 897 } 898 899 char punct; 900 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') { 901 const char* value = strchr(arg, '=') + 1; 902 Flag* flag; 903 904 real_name = handle_aliases_and_deprecation(name); 905 if (real_name == NULL) { 906 return false; 907 } 908 flag = Flag::find_flag(real_name, strlen(real_name)); 909 if (flag != NULL && flag->is_ccstr()) { 910 if (flag->ccstr_accumulates()) { 911 return append_to_string_flag(real_name, value, origin); 912 } else { 913 if (value[0] == '\0') { 914 value = NULL; 915 } 916 return set_string_flag(real_name, value, origin); 917 } 918 } 919 } 920 921 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') { 922 const char* value = strchr(arg, '=') + 1; 923 // -XX:Foo:=xxx will reset the string flag to the given value. 924 if (value[0] == '\0') { 925 value = NULL; 926 } 927 real_name = handle_aliases_and_deprecation(name); 928 if (real_name == NULL) { 929 return false; 930 } 931 return set_string_flag(real_name, value, origin); 932 } 933 934 #define SIGNED_FP_NUMBER_RANGE "[-0123456789.]" 935 #define SIGNED_NUMBER_RANGE "[-0123456789]" 936 #define NUMBER_RANGE "[0123456789]" 937 char value[BUFLEN + 1]; 938 char value2[BUFLEN + 1]; 939 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) { 940 // Looks like a floating-point number -- try again with more lenient format string 941 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) { 942 real_name = handle_aliases_and_deprecation(name); 943 if (real_name == NULL) { 944 return false; 945 } 946 return set_fp_numeric_flag(real_name, value, origin); 947 } 948 } 949 950 #define VALUE_RANGE "[-kmgtxKMGTX0123456789abcdefABCDEF]" 951 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) { 952 real_name = handle_aliases_and_deprecation(name); 953 if (real_name == NULL) { 954 return false; 955 } 956 return set_numeric_flag(real_name, value, origin); 957 } 958 959 return false; 960 } 961 962 void Arguments::add_string(char*** bldarray, int* count, const char* arg) { 963 assert(bldarray != NULL, "illegal argument"); 964 965 if (arg == NULL) { 966 return; 967 } 968 969 int new_count = *count + 1; 970 971 // expand the array and add arg to the last element 972 if (*bldarray == NULL) { 973 *bldarray = NEW_C_HEAP_ARRAY(char*, new_count, mtInternal); 974 } else { 975 *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, new_count, mtInternal); 976 } 977 (*bldarray)[*count] = os::strdup_check_oom(arg); 978 *count = new_count; 979 } 980 981 void Arguments::build_jvm_args(const char* arg) { 982 add_string(&_jvm_args_array, &_num_jvm_args, arg); 983 } 984 985 void Arguments::build_jvm_flags(const char* arg) { 986 add_string(&_jvm_flags_array, &_num_jvm_flags, arg); 987 } 988 989 // utility function to return a string that concatenates all 990 // strings in a given char** array 991 992 const char* Arguments::build_resource_string(char** args, int count) { 993 if (args == NULL || count == 0) { 994 return NULL; 995 } 996 size_t length = strlen(args[0]) + 1; // add 1 for the null terminator 997 for (int i = 1; i < count; i++) { 998 length += strlen(args[i]) + 1; // add 1 for a space 999 } 1000 char* s = NEW_RESOURCE_ARRAY(char, length); 1001 strcpy(s, args[0]); 1002 for (int j = 1; j < count; j++) { 1003 strcat(s, " "); 1004 strcat(s, args[j]); 1005 } 1006 return (const char*) s; 1007 } 1008 1009 void Arguments::print_on(outputStream* st) { 1010 st->print_cr("VM Arguments:"); 1011 if (num_jvm_flags() > 0) { 1012 st->print("jvm_flags: "); 1013 print_jvm_flags_on(st); 1014 } 1015 if (num_jvm_args() > 0) { 1016 st->print("jvm_args: "); 1017 print_jvm_args_on(st); 1018 } 1019 st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>"); 1020 if (_java_class_path != NULL) { 1021 char* path = _java_class_path->value(); 1022 st->print_cr("java_class_path (initial): %s", strlen(path) == 0 ? "<not set>" : path); 1023 } 1024 st->print_cr("Launcher Type: %s", _sun_java_launcher); 1025 } 1026 1027 void Arguments::print_jvm_flags_on(outputStream* st) { 1028 if (_num_jvm_flags > 0) { 1029 for (int i = 0; i < _num_jvm_flags; i++) { 1030 st->print("%s ", _jvm_flags_array[i]); 1031 } 1032 st->cr(); 1033 } 1034 } 1035 1036 void Arguments::print_jvm_args_on(outputStream* st) { 1037 if (_num_jvm_args > 0) { 1038 for (int i = 0; i < _num_jvm_args; i++) { 1039 st->print("%s ", _jvm_args_array[i]); 1040 } 1041 st->cr(); 1042 } 1043 } 1044 1045 bool Arguments::process_argument(const char* arg, 1046 jboolean ignore_unrecognized, Flag::Flags origin) { 1047 1048 JDK_Version since = JDK_Version(); 1049 1050 if (parse_argument(arg, origin) || ignore_unrecognized) { 1051 return true; 1052 } 1053 1054 bool has_plus_minus = (*arg == '+' || *arg == '-'); 1055 const char* const argname = has_plus_minus ? arg + 1 : arg; 1056 if (is_newly_obsolete(arg, &since)) { 1057 char version[256]; 1058 since.to_string(version, sizeof (version)); 1059 warning("ignoring option %s; support was removed in %s", argname, version); 1060 return true; 1061 } 1062 1063 // For locked flags, report a custom error message if available. 1064 // Otherwise, report the standard unrecognized VM option. 1065 1066 size_t arg_len; 1067 const char* equal_sign = strchr(argname, '='); 1068 if (equal_sign == NULL) { 1069 arg_len = strlen(argname); 1070 } else { 1071 arg_len = equal_sign - argname; 1072 } 1073 1074 Flag* found_flag = Flag::find_flag((const char*) argname, arg_len, true, true); 1075 if (found_flag != NULL) { 1076 char locked_message_buf[BUFLEN]; 1077 found_flag->get_locked_message(locked_message_buf, BUFLEN); 1078 if (strlen(locked_message_buf) == 0) { 1079 if (found_flag->is_bool() && !has_plus_minus) { 1080 jio_fprintf(defaultStream::error_stream(), 1081 "Missing +/- setting for VM option '%s'\n", argname); 1082 } else if (!found_flag->is_bool() && has_plus_minus) { 1083 jio_fprintf(defaultStream::error_stream(), 1084 "Unexpected +/- setting in VM option '%s'\n", argname); 1085 } else { 1086 jio_fprintf(defaultStream::error_stream(), 1087 "Improperly specified VM option '%s'\n", argname); 1088 } 1089 } else { 1090 jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf); 1091 } 1092 } else { 1093 jio_fprintf(defaultStream::error_stream(), 1094 "Unrecognized VM option '%s'\n", argname); 1095 Flag* fuzzy_matched = Flag::fuzzy_match((const char*) argname, arg_len, true); 1096 if (fuzzy_matched != NULL) { 1097 jio_fprintf(defaultStream::error_stream(), 1098 "Did you mean '%s%s%s'? ", 1099 (fuzzy_matched->is_bool()) ? "(+/-)" : "", 1100 fuzzy_matched->_name, 1101 (fuzzy_matched->is_bool()) ? "" : "=<value>"); 1102 if (is_newly_obsolete(fuzzy_matched->_name, &since)) { 1103 char version[256]; 1104 since.to_string(version, sizeof (version)); 1105 jio_fprintf(defaultStream::error_stream(), 1106 "Warning: support for %s was removed in %s\n", 1107 fuzzy_matched->_name, 1108 version); 1109 } 1110 } 1111 } 1112 1113 // allow for commandline "commenting out" options like -XX:#+Verbose 1114 return arg[0] == '#'; 1115 } 1116 1117 bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) { 1118 FILE* stream = fopen(file_name, "rb"); 1119 if (stream == NULL) { 1120 if (should_exist) { 1121 jio_fprintf(defaultStream::error_stream(), 1122 "Could not open settings file %s\n", file_name); 1123 return false; 1124 } else { 1125 return true; 1126 } 1127 } 1128 1129 char token[1024]; 1130 int pos = 0; 1131 1132 bool in_white_space = true; 1133 bool in_comment = false; 1134 bool in_quote = false; 1135 char quote_c = 0; 1136 bool result = true; 1137 1138 int c = getc(stream); 1139 while (c != EOF && pos < (int) (sizeof (token) - 1)) { 1140 if (in_white_space) { 1141 if (in_comment) { 1142 if (c == '\n') in_comment = false; 1143 } else { 1144 if (c == '#') in_comment = true; 1145 else if (!isspace(c)) { 1146 in_white_space = false; 1147 token[pos++] = c; 1148 } 1149 } 1150 } else { 1151 if (c == '\n' || (!in_quote && isspace(c))) { 1152 // token ends at newline, or at unquoted whitespace 1153 // this allows a way to include spaces in string-valued options 1154 token[pos] = '\0'; 1155 logOption(token); 1156 result &= process_argument(token, ignore_unrecognized, Flag::CONFIG_FILE); 1157 build_jvm_flags(token); 1158 pos = 0; 1159 in_white_space = true; 1160 in_quote = false; 1161 } else if (!in_quote && (c == '\'' || c == '"')) { 1162 in_quote = true; 1163 quote_c = c; 1164 } else if (in_quote && (c == quote_c)) { 1165 in_quote = false; 1166 } else { 1167 token[pos++] = c; 1168 } 1169 } 1170 c = getc(stream); 1171 } 1172 if (pos > 0) { 1173 token[pos] = '\0'; 1174 result &= process_argument(token, ignore_unrecognized, Flag::CONFIG_FILE); 1175 build_jvm_flags(token); 1176 } 1177 fclose(stream); 1178 return result; 1179 } 1180 1181 //============================================================================================================= 1182 // Parsing of properties (-D) 1183 1184 const char* Arguments::get_property(const char* key) { 1185 return PropertyList_get_value(system_properties(), key); 1186 } 1187 1188 bool Arguments::add_property(const char* prop) { 1189 const char* eq = strchr(prop, '='); 1190 char* key; 1191 // ns must be static--its address may be stored in a SystemProperty object. 1192 const static char ns[1] = {0}; 1193 char* value = (char *) ns; 1194 1195 size_t key_len = (eq == NULL) ? strlen(prop) : (eq - prop); 1196 key = AllocateHeap(key_len + 1, mtInternal); 1197 strncpy(key, prop, key_len); 1198 key[key_len] = '\0'; 1199 1200 if (eq != NULL) { 1201 size_t value_len = strlen(prop) - key_len - 1; 1202 value = AllocateHeap(value_len + 1, mtInternal); 1203 strncpy(value, &prop[key_len + 1], value_len + 1); 1204 } 1205 1206 if (strcmp(key, "java.compiler") == 0) { 1207 process_java_compiler_argument(value); 1208 FreeHeap(key); 1209 if (eq != NULL) { 1210 FreeHeap(value); 1211 } 1212 return true; 1213 } else if (strcmp(key, "sun.java.command") == 0) { 1214 _java_command = value; 1215 1216 // Record value in Arguments, but let it get passed to Java. 1217 } else if (strcmp(key, "sun.java.launcher.is_altjvm") == 0 || 1218 strcmp(key, "sun.java.launcher.pid") == 0) { 1219 // sun.java.launcher.is_altjvm and sun.java.launcher.pid property are 1220 // private and are processed in process_sun_java_launcher_properties(); 1221 // the sun.java.launcher property is passed on to the java application 1222 FreeHeap(key); 1223 if (eq != NULL) { 1224 FreeHeap(value); 1225 } 1226 return true; 1227 } else if (strcmp(key, "java.vendor.url.bug") == 0) { 1228 // save it in _java_vendor_url_bug, so JVM fatal error handler can access 1229 // its value without going through the property list or making a Java call. 1230 _java_vendor_url_bug = value; 1231 } else if (strcmp(key, "sun.boot.library.path") == 0) { 1232 PropertyList_unique_add(&_system_properties, key, value, true); 1233 return true; 1234 } 1235 // Create new property and add at the end of the list 1236 PropertyList_unique_add(&_system_properties, key, value); 1237 return true; 1238 } 1239 1240 //=========================================================================================================== 1241 // Setting int/mixed/comp mode flags 1242 1243 void Arguments::set_mode_flags(Mode mode) { 1244 // Set up default values for all flags. 1245 // If you add a flag to any of the branches below, 1246 // add a default value for it here. 1247 set_java_compiler(false); 1248 _mode = mode; 1249 1250 // Ensure Agent_OnLoad has the correct initial values. 1251 // This may not be the final mode; mode may change later in onload phase. 1252 PropertyList_unique_add(&_system_properties, "java.vm.info", 1253 (char*) VM_Version::vm_info_string(), false); 1254 1255 UseInterpreter = true; 1256 UseCompiler = true; 1257 UseLoopCounter = true; 1258 1259 // Default values may be platform/compiler dependent - 1260 // use the saved values 1261 ClipInlining = Arguments::_ClipInlining; 1262 AlwaysCompileLoopMethods = Arguments::_AlwaysCompileLoopMethods; 1263 UseOnStackReplacement = Arguments::_UseOnStackReplacement; 1264 BackgroundCompilation = Arguments::_BackgroundCompilation; 1265 1266 // Change from defaults based on mode 1267 switch (mode) { 1268 default: 1269 ShouldNotReachHere(); 1270 break; 1271 case _int: 1272 UseCompiler = false; 1273 UseLoopCounter = false; 1274 AlwaysCompileLoopMethods = false; 1275 UseOnStackReplacement = false; 1276 break; 1277 case _mixed: 1278 // same as default 1279 break; 1280 case _comp: 1281 UseInterpreter = false; 1282 BackgroundCompilation = false; 1283 ClipInlining = false; 1284 // Be much more aggressive in tiered mode with -Xcomp and exercise C2 more. 1285 // We will first compile a level 3 version (C1 with full profiling), then do one invocation of it and 1286 // compile a level 4 (C2) and then continue executing it. 1287 if (TieredCompilation) { 1288 Tier3InvokeNotifyFreqLog = 0; 1289 Tier4InvocationThreshold = 0; 1290 } 1291 break; 1292 } 1293 } 1294 1295 #if defined(COMPILER2) || defined(_LP64) || !INCLUDE_CDS 1296 // Conflict: required to use shared spaces (-Xshare:on), but 1297 // incompatible command line options were chosen. 1298 1299 static void no_shared_spaces(const char* message) { 1300 if (RequireSharedSpaces) { 1301 jio_fprintf(defaultStream::error_stream(), 1302 "Class data sharing is inconsistent with other specified options.\n"); 1303 vm_exit_during_initialization("Unable to use shared archive.", message); 1304 } else { 1305 FLAG_SET_DEFAULT(UseSharedSpaces, false); 1306 } 1307 } 1308 #endif 1309 1310 // Returns threshold scaled with CompileThresholdScaling 1311 1312 intx Arguments::get_scaled_compile_threshold(intx threshold) { 1313 return (intx) (threshold * CompileThresholdScaling); 1314 } 1315 1316 // Returns freq_log scaled with CompileThresholdScaling 1317 1318 intx Arguments::get_scaled_freq_log(intx freq_log) { 1319 intx scaled_freq = get_scaled_compile_threshold((intx) 1 << freq_log); 1320 if (scaled_freq == 0) { 1321 return 0; 1322 } else { 1323 return log2_intptr(scaled_freq); 1324 } 1325 } 1326 1327 void Arguments::set_tiered_flags() { 1328 // With tiered, set default policy to AdvancedThresholdPolicy, which is 3. 1329 if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) { 1330 FLAG_SET_DEFAULT(CompilationPolicyChoice, 3); 1331 } 1332 if (CompilationPolicyChoice < 2) { 1333 vm_exit_during_initialization( 1334 "Incompatible compilation policy selected", NULL); 1335 } 1336 // Increase the code cache size - tiered compiles a lot more. 1337 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { 1338 FLAG_SET_ERGO(uintx, ReservedCodeCacheSize, ReservedCodeCacheSize * 5); 1339 } 1340 // Enable SegmentedCodeCache if TieredCompilation is enabled and ReservedCodeCacheSize >= 240M 1341 if (FLAG_IS_DEFAULT(SegmentedCodeCache) && ReservedCodeCacheSize >= 240 * M) { 1342 FLAG_SET_ERGO(bool, SegmentedCodeCache, true); 1343 1344 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { 1345 // Multiply sizes by 5 but fix NonNMethodCodeHeapSize (distribute among non-profiled and profiled code heap) 1346 if (FLAG_IS_DEFAULT(ProfiledCodeHeapSize)) { 1347 FLAG_SET_ERGO(uintx, ProfiledCodeHeapSize, ProfiledCodeHeapSize * 5 + NonNMethodCodeHeapSize * 2); 1348 } 1349 if (FLAG_IS_DEFAULT(NonProfiledCodeHeapSize)) { 1350 FLAG_SET_ERGO(uintx, NonProfiledCodeHeapSize, NonProfiledCodeHeapSize * 5 + NonNMethodCodeHeapSize * 2); 1351 } 1352 // Check consistency of code heap sizes 1353 if ((NonNMethodCodeHeapSize + NonProfiledCodeHeapSize + ProfiledCodeHeapSize) != ReservedCodeCacheSize) { 1354 jio_fprintf(defaultStream::error_stream(), 1355 "Invalid code heap sizes: NonNMethodCodeHeapSize(%dK) + ProfiledCodeHeapSize(%dK) + NonProfiledCodeHeapSize(%dK) = %dK. Must be equal to ReservedCodeCacheSize = %uK.\n", 1356 NonNMethodCodeHeapSize / K, ProfiledCodeHeapSize / K, NonProfiledCodeHeapSize / K, 1357 (NonNMethodCodeHeapSize + ProfiledCodeHeapSize + NonProfiledCodeHeapSize) / K, ReservedCodeCacheSize / K); 1358 vm_exit(1); 1359 } 1360 } 1361 } 1362 if (!UseInterpreter) { // -Xcomp 1363 Tier3InvokeNotifyFreqLog = 0; 1364 Tier4InvocationThreshold = 0; 1365 } 1366 // Scale tiered compilation thresholds 1367 if (!FLAG_IS_DEFAULT(CompileThresholdScaling)) { 1368 FLAG_SET_ERGO(intx, Tier0InvokeNotifyFreqLog, get_scaled_freq_log(Tier0InvokeNotifyFreqLog)); 1369 FLAG_SET_ERGO(intx, Tier0BackedgeNotifyFreqLog, get_scaled_freq_log(Tier0BackedgeNotifyFreqLog)); 1370 1371 FLAG_SET_ERGO(intx, Tier3InvocationThreshold, get_scaled_compile_threshold(Tier3InvocationThreshold)); 1372 FLAG_SET_ERGO(intx, Tier3MinInvocationThreshold, get_scaled_compile_threshold(Tier3MinInvocationThreshold)); 1373 FLAG_SET_ERGO(intx, Tier3CompileThreshold, get_scaled_compile_threshold(Tier3CompileThreshold)); 1374 FLAG_SET_ERGO(intx, Tier3BackEdgeThreshold, get_scaled_compile_threshold(Tier3BackEdgeThreshold)); 1375 1376 // Tier2{Invocation,MinInvocation,Compile,Backedge}Threshold should be scaled here 1377 // once these thresholds become supported. 1378 1379 FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, get_scaled_freq_log(Tier2InvokeNotifyFreqLog)); 1380 FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, get_scaled_freq_log(Tier2BackedgeNotifyFreqLog)); 1381 1382 FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, get_scaled_freq_log(Tier3InvokeNotifyFreqLog)); 1383 FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, get_scaled_freq_log(Tier3BackedgeNotifyFreqLog)); 1384 1385 FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, get_scaled_freq_log(Tier23InlineeNotifyFreqLog)); 1386 1387 FLAG_SET_ERGO(intx, Tier4InvocationThreshold, get_scaled_compile_threshold(Tier4InvocationThreshold)); 1388 FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, get_scaled_compile_threshold(Tier4MinInvocationThreshold)); 1389 FLAG_SET_ERGO(intx, Tier4CompileThreshold, get_scaled_compile_threshold(Tier4CompileThreshold)); 1390 FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, get_scaled_compile_threshold(Tier4BackEdgeThreshold)); 1391 } 1392 } 1393 1394 /** 1395 * Returns the minimum number of compiler threads needed to run the JVM. The following 1396 * configurations are possible. 1397 * 1398 * 1) The JVM is build using an interpreter only. As a result, the minimum number of 1399 * compiler threads is 0. 1400 * 2) The JVM is build using the compiler(s) and tiered compilation is disabled. As 1401 * a result, either C1 or C2 is used, so the minimum number of compiler threads is 1. 1402 * 3) The JVM is build using the compiler(s) and tiered compilation is enabled. However, 1403 * the option "TieredStopAtLevel < CompLevel_full_optimization". As a result, only 1404 * C1 can be used, so the minimum number of compiler threads is 1. 1405 * 4) The JVM is build using the compilers and tiered compilation is enabled. The option 1406 * 'TieredStopAtLevel = CompLevel_full_optimization' (the default value). As a result, 1407 * the minimum number of compiler threads is 2. 1408 */ 1409 int Arguments::get_min_number_of_compiler_threads() { 1410 #if !defined(COMPILER1) && !defined(COMPILER2) && !defined(SHARK) 1411 return 0; // case 1 1412 #else 1413 if (!TieredCompilation || (TieredStopAtLevel < CompLevel_full_optimization)) { 1414 return 1; // case 2 or case 3 1415 } 1416 return 2; // case 4 (tiered) 1417 #endif 1418 } 1419 1420 #if INCLUDE_ALL_GCS 1421 1422 static void disable_adaptive_size_policy(const char* collector_name) { 1423 if (UseAdaptiveSizePolicy) { 1424 if (FLAG_IS_CMDLINE(UseAdaptiveSizePolicy)) { 1425 warning("disabling UseAdaptiveSizePolicy; it is incompatible with %s.", 1426 collector_name); 1427 } 1428 FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false); 1429 } 1430 } 1431 1432 void Arguments::set_parnew_gc_flags() { 1433 assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC, 1434 "control point invariant"); 1435 assert(UseConcMarkSweepGC, "CMS is expected to be on here"); 1436 assert(UseParNewGC, "ParNew should always be used with CMS"); 1437 1438 if (FLAG_IS_DEFAULT(ParallelGCThreads)) { 1439 FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads()); 1440 assert(ParallelGCThreads > 0, "We should always have at least one thread by default"); 1441 } else if (ParallelGCThreads == 0) { 1442 jio_fprintf(defaultStream::error_stream(), 1443 "The ParNew GC can not be combined with -XX:ParallelGCThreads=0\n"); 1444 vm_exit(1); 1445 } 1446 1447 // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 respectively, 1448 // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration 1449 // we set them to 1024 and 1024. 1450 // See CR 6362902. 1451 if (FLAG_IS_DEFAULT(YoungPLABSize)) { 1452 FLAG_SET_DEFAULT(YoungPLABSize, (intx) 1024); 1453 } 1454 if (FLAG_IS_DEFAULT(OldPLABSize)) { 1455 FLAG_SET_DEFAULT(OldPLABSize, (intx) 1024); 1456 } 1457 1458 // When using compressed oops, we use local overflow stacks, 1459 // rather than using a global overflow list chained through 1460 // the klass word of the object's pre-image. 1461 if (UseCompressedOops && !ParGCUseLocalOverflow) { 1462 if (!FLAG_IS_DEFAULT(ParGCUseLocalOverflow)) { 1463 warning("Forcing +ParGCUseLocalOverflow: needed if using compressed references"); 1464 } 1465 FLAG_SET_DEFAULT(ParGCUseLocalOverflow, true); 1466 } 1467 assert(ParGCUseLocalOverflow || !UseCompressedOops, "Error"); 1468 } 1469 1470 // Adjust some sizes to suit CMS and/or ParNew needs; these work well on 1471 // sparc/solaris for certain applications, but would gain from 1472 // further optimization and tuning efforts, and would almost 1473 // certainly gain from analysis of platform and environment. 1474 1475 void Arguments::set_cms_and_parnew_gc_flags() { 1476 assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error"); 1477 assert(UseConcMarkSweepGC, "CMS is expected to be on here"); 1478 assert(UseParNewGC, "ParNew should always be used with CMS"); 1479 1480 // Turn off AdaptiveSizePolicy by default for cms until it is complete. 1481 disable_adaptive_size_policy("UseConcMarkSweepGC"); 1482 1483 set_parnew_gc_flags(); 1484 1485 size_t max_heap = align_size_down(MaxHeapSize, 1486 CardTableRS::ct_max_alignment_constraint()); 1487 1488 // Now make adjustments for CMS 1489 intx tenuring_default = (intx) 6; 1490 size_t young_gen_per_worker = CMSYoungGenPerWorker; 1491 1492 // Preferred young gen size for "short" pauses: 1493 // upper bound depends on # of threads and NewRatio. 1494 const uintx parallel_gc_threads = 1495 (ParallelGCThreads == 0 ? 1 : ParallelGCThreads); 1496 const size_t preferred_max_new_size_unaligned = 1497 MIN2(max_heap / (NewRatio + 1), ScaleForWordSize(young_gen_per_worker * parallel_gc_threads)); 1498 size_t preferred_max_new_size = 1499 align_size_up(preferred_max_new_size_unaligned, os::vm_page_size()); 1500 1501 // Unless explicitly requested otherwise, size young gen 1502 // for "short" pauses ~ CMSYoungGenPerWorker*ParallelGCThreads 1503 1504 // If either MaxNewSize or NewRatio is set on the command line, 1505 // assume the user is trying to set the size of the young gen. 1506 if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) { 1507 1508 // Set MaxNewSize to our calculated preferred_max_new_size unless 1509 // NewSize was set on the command line and it is larger than 1510 // preferred_max_new_size. 1511 if (!FLAG_IS_DEFAULT(NewSize)) { // NewSize explicitly set at command-line 1512 FLAG_SET_ERGO(uintx, MaxNewSize, MAX2(NewSize, preferred_max_new_size)); 1513 } else { 1514 FLAG_SET_ERGO(uintx, MaxNewSize, preferred_max_new_size); 1515 } 1516 if (PrintGCDetails && Verbose) { 1517 // Too early to use gclog_or_tty 1518 tty->print_cr("CMS ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize); 1519 } 1520 1521 // Code along this path potentially sets NewSize and OldSize 1522 if (PrintGCDetails && Verbose) { 1523 // Too early to use gclog_or_tty 1524 tty->print_cr("CMS set min_heap_size: " SIZE_FORMAT 1525 " initial_heap_size: " SIZE_FORMAT 1526 " max_heap: " SIZE_FORMAT, 1527 min_heap_size(), InitialHeapSize, max_heap); 1528 } 1529 size_t min_new = preferred_max_new_size; 1530 if (FLAG_IS_CMDLINE(NewSize)) { 1531 min_new = NewSize; 1532 } 1533 if (max_heap > min_new && min_heap_size() > min_new) { 1534 // Unless explicitly requested otherwise, make young gen 1535 // at least min_new, and at most preferred_max_new_size. 1536 if (FLAG_IS_DEFAULT(NewSize)) { 1537 FLAG_SET_ERGO(uintx, NewSize, MAX2(NewSize, min_new)); 1538 FLAG_SET_ERGO(uintx, NewSize, MIN2(preferred_max_new_size, NewSize)); 1539 if (PrintGCDetails && Verbose) { 1540 // Too early to use gclog_or_tty 1541 tty->print_cr("CMS ergo set NewSize: " SIZE_FORMAT, NewSize); 1542 } 1543 } 1544 // Unless explicitly requested otherwise, size old gen 1545 // so it's NewRatio x of NewSize. 1546 if (FLAG_IS_DEFAULT(OldSize)) { 1547 if (max_heap > NewSize) { 1548 FLAG_SET_ERGO(uintx, OldSize, MIN2(NewRatio*NewSize, max_heap - NewSize)); 1549 if (PrintGCDetails && Verbose) { 1550 // Too early to use gclog_or_tty 1551 tty->print_cr("CMS ergo set OldSize: " SIZE_FORMAT, OldSize); 1552 } 1553 } 1554 } 1555 } 1556 } 1557 // Unless explicitly requested otherwise, definitely 1558 // promote all objects surviving "tenuring_default" scavenges. 1559 if (FLAG_IS_DEFAULT(MaxTenuringThreshold) && 1560 FLAG_IS_DEFAULT(SurvivorRatio)) { 1561 FLAG_SET_ERGO(uintx, MaxTenuringThreshold, tenuring_default); 1562 } 1563 // If we decided above (or user explicitly requested) 1564 // `promote all' (via MaxTenuringThreshold := 0), 1565 // prefer minuscule survivor spaces so as not to waste 1566 // space for (non-existent) survivors 1567 if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) { 1568 FLAG_SET_ERGO(uintx, SurvivorRatio, MAX2((uintx) 1024, SurvivorRatio)); 1569 } 1570 1571 // OldPLABSize is interpreted in CMS as not the size of the PLAB in words, 1572 // but rather the number of free blocks of a given size that are used when 1573 // replenishing the local per-worker free list caches. 1574 if (FLAG_IS_DEFAULT(OldPLABSize)) { 1575 if (!FLAG_IS_DEFAULT(ResizeOldPLAB) && !ResizeOldPLAB) { 1576 // OldPLAB sizing manually turned off: Use a larger default setting, 1577 // unless it was manually specified. This is because a too-low value 1578 // will slow down scavenges. 1579 FLAG_SET_ERGO(uintx, OldPLABSize, CFLS_LAB::_default_static_old_plab_size); // default value before 6631166 1580 } else { 1581 FLAG_SET_DEFAULT(OldPLABSize, CFLS_LAB::_default_dynamic_old_plab_size); // old CMSParPromoteBlocksToClaim default 1582 } 1583 } 1584 1585 // If either of the static initialization defaults have changed, note this 1586 // modification. 1587 if (!FLAG_IS_DEFAULT(OldPLABSize) || !FLAG_IS_DEFAULT(OldPLABWeight)) { 1588 CFLS_LAB::modify_initialization(OldPLABSize, OldPLABWeight); 1589 } 1590 if (PrintGCDetails && Verbose) { 1591 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk", 1592 (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K)); 1593 tty->print_cr("ConcGCThreads: %u", (uint) ConcGCThreads); 1594 } 1595 } 1596 #endif // INCLUDE_ALL_GCS 1597 1598 void set_object_alignment() { 1599 // Object alignment. 1600 assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2"); 1601 MinObjAlignmentInBytes = ObjectAlignmentInBytes; 1602 assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small"); 1603 MinObjAlignment = MinObjAlignmentInBytes / HeapWordSize; 1604 assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect"); 1605 MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1; 1606 1607 LogMinObjAlignmentInBytes = exact_log2(ObjectAlignmentInBytes); 1608 LogMinObjAlignment = LogMinObjAlignmentInBytes - LogHeapWordSize; 1609 1610 // Oop encoding heap max 1611 OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes; 1612 1613 #if INCLUDE_ALL_GCS 1614 // Set CMS global values 1615 CompactibleFreeListSpace::set_cms_values(); 1616 #endif // INCLUDE_ALL_GCS 1617 } 1618 1619 bool verify_object_alignment() { 1620 // Object alignment. 1621 if (!is_power_of_2(ObjectAlignmentInBytes)) { 1622 jio_fprintf(defaultStream::error_stream(), 1623 "error: ObjectAlignmentInBytes=%d must be power of 2\n", 1624 (int) ObjectAlignmentInBytes); 1625 return false; 1626 } 1627 if ((int) ObjectAlignmentInBytes < BytesPerLong) { 1628 jio_fprintf(defaultStream::error_stream(), 1629 "error: ObjectAlignmentInBytes=%d must be greater or equal %d\n", 1630 (int) ObjectAlignmentInBytes, BytesPerLong); 1631 return false; 1632 } 1633 // It does not make sense to have big object alignment 1634 // since a space lost due to alignment will be greater 1635 // then a saved space from compressed oops. 1636 if ((int) ObjectAlignmentInBytes > 256) { 1637 jio_fprintf(defaultStream::error_stream(), 1638 "error: ObjectAlignmentInBytes=%d must not be greater than 256\n", 1639 (int) ObjectAlignmentInBytes); 1640 return false; 1641 } 1642 // In case page size is very small. 1643 if ((int) ObjectAlignmentInBytes >= os::vm_page_size()) { 1644 jio_fprintf(defaultStream::error_stream(), 1645 "error: ObjectAlignmentInBytes=%d must be less than page size %d\n", 1646 (int) ObjectAlignmentInBytes, os::vm_page_size()); 1647 return false; 1648 } 1649 if (SurvivorAlignmentInBytes == 0) { 1650 SurvivorAlignmentInBytes = ObjectAlignmentInBytes; 1651 } else { 1652 if (!is_power_of_2(SurvivorAlignmentInBytes)) { 1653 jio_fprintf(defaultStream::error_stream(), 1654 "error: SurvivorAlignmentInBytes=%d must be power of 2\n", 1655 (int) SurvivorAlignmentInBytes); 1656 return false; 1657 } 1658 if (SurvivorAlignmentInBytes < ObjectAlignmentInBytes) { 1659 jio_fprintf(defaultStream::error_stream(), 1660 "error: SurvivorAlignmentInBytes=%d must be greater than ObjectAlignmentInBytes=%d \n", 1661 (int) SurvivorAlignmentInBytes, (int) ObjectAlignmentInBytes); 1662 return false; 1663 } 1664 } 1665 return true; 1666 } 1667 1668 size_t Arguments::max_heap_for_compressed_oops() { 1669 // Avoid sign flip. 1670 assert(OopEncodingHeapMax > (uint64_t) os::vm_page_size(), "Unusual page size"); 1671 // We need to fit both the NULL page and the heap into the memory budget, while 1672 // keeping alignment constraints of the heap. To guarantee the latter, as the 1673 // NULL page is located before the heap, we pad the NULL page to the conservative 1674 // maximum alignment that the GC may ever impose upon the heap. 1675 size_t displacement_due_to_null_page = align_size_up_(os::vm_page_size(), 1676 _conservative_max_heap_alignment); 1677 1678 LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page); 1679 NOT_LP64(ShouldNotReachHere(); return 0); 1680 } 1681 1682 bool Arguments::should_auto_select_low_pause_collector() { 1683 if (UseAutoGCSelectPolicy && 1684 !FLAG_IS_DEFAULT(MaxGCPauseMillis) && 1685 (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) { 1686 if (PrintGCDetails) { 1687 // Cannot use gclog_or_tty yet. 1688 tty->print_cr("Automatic selection of the low pause collector" 1689 " based on pause goal of %d (ms)", (int) MaxGCPauseMillis); 1690 } 1691 return true; 1692 } 1693 return false; 1694 } 1695 1696 void Arguments::set_use_compressed_oops() { 1697 #ifndef ZERO 1698 #ifdef _LP64 1699 // MaxHeapSize is not set up properly at this point, but 1700 // the only value that can override MaxHeapSize if we are 1701 // to use UseCompressedOops is InitialHeapSize. 1702 size_t max_heap_size = MAX2(MaxHeapSize, InitialHeapSize); 1703 1704 if (max_heap_size <= max_heap_for_compressed_oops()) { 1705 #if !defined(COMPILER1) || defined(TIERED) 1706 if (FLAG_IS_DEFAULT(UseCompressedOops)) { 1707 FLAG_SET_ERGO(bool, UseCompressedOops, true); 1708 } 1709 #endif 1710 } else { 1711 if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) { 1712 warning("Max heap size too large for Compressed Oops"); 1713 FLAG_SET_DEFAULT(UseCompressedOops, false); 1714 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1715 } 1716 } 1717 #endif // _LP64 1718 #endif // ZERO 1719 } 1720 1721 1722 // NOTE: set_use_compressed_klass_ptrs() must be called after calling 1723 // set_use_compressed_oops(). 1724 1725 void Arguments::set_use_compressed_klass_ptrs() { 1726 #ifndef ZERO 1727 #ifdef _LP64 1728 // UseCompressedOops must be on for UseCompressedClassPointers to be on. 1729 if (!UseCompressedOops) { 1730 if (UseCompressedClassPointers) { 1731 warning("UseCompressedClassPointers requires UseCompressedOops"); 1732 } 1733 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1734 } else { 1735 // Turn on UseCompressedClassPointers too 1736 if (FLAG_IS_DEFAULT(UseCompressedClassPointers)) { 1737 FLAG_SET_ERGO(bool, UseCompressedClassPointers, true); 1738 } 1739 // Check the CompressedClassSpaceSize to make sure we use compressed klass ptrs. 1740 if (UseCompressedClassPointers) { 1741 if (CompressedClassSpaceSize > KlassEncodingMetaspaceMax) { 1742 warning("CompressedClassSpaceSize is too large for UseCompressedClassPointers"); 1743 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1744 } 1745 } 1746 } 1747 #endif // _LP64 1748 #endif // !ZERO 1749 } 1750 1751 void Arguments::set_conservative_max_heap_alignment() { 1752 // The conservative maximum required alignment for the heap is the maximum of 1753 // the alignments imposed by several sources: any requirements from the heap 1754 // itself, the collector policy and the maximum page size we may run the VM 1755 // with. 1756 size_t heap_alignment = GenCollectedHeap::conservative_max_heap_alignment(); 1757 #if INCLUDE_ALL_GCS 1758 if (UseParallelGC) { 1759 heap_alignment = ParallelScavengeHeap::conservative_max_heap_alignment(); 1760 } else if (UseG1GC) { 1761 heap_alignment = G1CollectedHeap::conservative_max_heap_alignment(); 1762 } 1763 #endif // INCLUDE_ALL_GCS 1764 _conservative_max_heap_alignment = MAX4(heap_alignment, 1765 (size_t) os::vm_allocation_granularity(), 1766 os::max_page_size(), 1767 CollectorPolicy::compute_heap_alignment()); 1768 } 1769 1770 void Arguments::select_gc_ergonomically() { 1771 if (os::is_server_class_machine()) { 1772 if (should_auto_select_low_pause_collector()) { 1773 FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true); 1774 } else { 1775 FLAG_SET_ERGO(bool, UseParallelGC, true); 1776 } 1777 } 1778 } 1779 1780 void Arguments::select_gc() { 1781 if (!gc_selected()) { 1782 ArgumentsExt::select_gc_ergonomically(); 1783 } 1784 } 1785 1786 void Arguments::set_ergonomics_flags() { 1787 select_gc(); 1788 1789 #ifdef COMPILER2 1790 // Shared spaces work fine with other GCs but causes bytecode rewriting 1791 // to be disabled, which hurts interpreter performance and decreases 1792 // server performance. When -server is specified, keep the default off 1793 // unless it is asked for. Future work: either add bytecode rewriting 1794 // at link time, or rewrite bytecodes in non-shared methods. 1795 if (!DumpSharedSpaces && !RequireSharedSpaces && 1796 (FLAG_IS_DEFAULT(UseSharedSpaces) || !UseSharedSpaces)) { 1797 no_shared_spaces("COMPILER2 default: -Xshare:auto | off, have to manually setup to on."); 1798 } 1799 #endif 1800 1801 set_conservative_max_heap_alignment(); 1802 1803 #ifndef ZERO 1804 #ifdef _LP64 1805 set_use_compressed_oops(); 1806 1807 // set_use_compressed_klass_ptrs() must be called after calling 1808 // set_use_compressed_oops(). 1809 set_use_compressed_klass_ptrs(); 1810 1811 // Also checks that certain machines are slower with compressed oops 1812 // in vm_version initialization code. 1813 #endif // _LP64 1814 #endif // !ZERO 1815 } 1816 1817 void Arguments::set_parallel_gc_flags() { 1818 assert(UseParallelGC || UseParallelOldGC, "Error"); 1819 // Enable ParallelOld unless it was explicitly disabled (cmd line or rc file). 1820 if (FLAG_IS_DEFAULT(UseParallelOldGC)) { 1821 FLAG_SET_DEFAULT(UseParallelOldGC, true); 1822 } 1823 FLAG_SET_DEFAULT(UseParallelGC, true); 1824 1825 // If no heap maximum was requested explicitly, use some reasonable fraction 1826 // of the physical memory, up to a maximum of 1GB. 1827 FLAG_SET_DEFAULT(ParallelGCThreads, 1828 Abstract_VM_Version::parallel_worker_threads()); 1829 if (ParallelGCThreads == 0) { 1830 jio_fprintf(defaultStream::error_stream(), 1831 "The Parallel GC can not be combined with -XX:ParallelGCThreads=0\n"); 1832 vm_exit(1); 1833 } 1834 1835 if (UseAdaptiveSizePolicy) { 1836 // We don't want to limit adaptive heap sizing's freedom to adjust the heap 1837 // unless the user actually sets these flags. 1838 if (FLAG_IS_DEFAULT(MinHeapFreeRatio)) { 1839 FLAG_SET_DEFAULT(MinHeapFreeRatio, 0); 1840 _min_heap_free_ratio = MinHeapFreeRatio; 1841 } 1842 if (FLAG_IS_DEFAULT(MaxHeapFreeRatio)) { 1843 FLAG_SET_DEFAULT(MaxHeapFreeRatio, 100); 1844 _max_heap_free_ratio = MaxHeapFreeRatio; 1845 } 1846 } 1847 1848 // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the 1849 // SurvivorRatio has been set, reset their default values to SurvivorRatio + 1850 // 2. By doing this we make SurvivorRatio also work for Parallel Scavenger. 1851 // See CR 6362902 for details. 1852 if (!FLAG_IS_DEFAULT(SurvivorRatio)) { 1853 if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) { 1854 FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2); 1855 } 1856 if (FLAG_IS_DEFAULT(MinSurvivorRatio)) { 1857 FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2); 1858 } 1859 } 1860 1861 if (UseParallelOldGC) { 1862 // Par compact uses lower default values since they are treated as 1863 // minimums. These are different defaults because of the different 1864 // interpretation and are not ergonomically set. 1865 if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) { 1866 FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1); 1867 } 1868 } 1869 } 1870 1871 void Arguments::set_g1_gc_flags() { 1872 assert(UseG1GC, "Error"); 1873 #ifdef COMPILER1 1874 FastTLABRefill = false; 1875 #endif 1876 FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads()); 1877 if (ParallelGCThreads == 0) { 1878 assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0."); 1879 vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL); 1880 } 1881 1882 #if INCLUDE_ALL_GCS 1883 if (G1ConcRefinementThreads == 0) { 1884 FLAG_SET_DEFAULT(G1ConcRefinementThreads, ParallelGCThreads); 1885 } 1886 #endif 1887 1888 // MarkStackSize will be set (if it hasn't been set by the user) 1889 // when concurrent marking is initialized. 1890 // Its value will be based upon the number of parallel marking threads. 1891 // But we do set the maximum mark stack size here. 1892 if (FLAG_IS_DEFAULT(MarkStackSizeMax)) { 1893 FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE); 1894 } 1895 1896 if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) { 1897 // In G1, we want the default GC overhead goal to be higher than 1898 // say in PS. So we set it here to 10%. Otherwise the heap might 1899 // be expanded more aggressively than we would like it to. In 1900 // fact, even 10% seems to not be high enough in some cases 1901 // (especially small GC stress tests that the main thing they do 1902 // is allocation). We might consider increase it further. 1903 FLAG_SET_DEFAULT(GCTimeRatio, 9); 1904 } 1905 1906 if (PrintGCDetails && Verbose) { 1907 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk", 1908 (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K)); 1909 tty->print_cr("ConcGCThreads: %u", (uint) ConcGCThreads); 1910 } 1911 } 1912 1913 #if !INCLUDE_ALL_GCS 1914 #ifdef ASSERT 1915 1916 static bool verify_serial_gc_flags() { 1917 return (UseSerialGC && 1918 !(UseParNewGC || (UseConcMarkSweepGC) || UseG1GC || 1919 UseParallelGC || UseParallelOldGC)); 1920 } 1921 #endif // ASSERT 1922 #endif // INCLUDE_ALL_GCS 1923 1924 void Arguments::set_gc_specific_flags() { 1925 #if INCLUDE_ALL_GCS 1926 // Set per-collector flags 1927 if (UseParallelGC || UseParallelOldGC) { 1928 set_parallel_gc_flags(); 1929 } else if (UseConcMarkSweepGC) { 1930 set_cms_and_parnew_gc_flags(); 1931 } else if (UseG1GC) { 1932 set_g1_gc_flags(); 1933 } 1934 if (AssumeMP && !UseSerialGC) { 1935 if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) { 1936 warning("If the number of processors is expected to increase from one, then" 1937 " you should configure the number of parallel GC threads appropriately" 1938 " using -XX:ParallelGCThreads=N"); 1939 } 1940 } 1941 if (MinHeapFreeRatio == 100) { 1942 // Keeping the heap 100% free is hard ;-) so limit it to 99%. 1943 FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99); 1944 } 1945 #else // INCLUDE_ALL_GCS 1946 assert(verify_serial_gc_flags(), "SerialGC unset"); 1947 #endif // INCLUDE_ALL_GCS 1948 } 1949 1950 julong Arguments::limit_by_allocatable_memory(julong limit) { 1951 julong max_allocatable; 1952 julong result = limit; 1953 if (os::has_allocatable_memory_limit(&max_allocatable)) { 1954 result = MIN2(result, max_allocatable / MaxVirtMemFraction); 1955 } 1956 return result; 1957 } 1958 1959 // Use static initialization to get the default before parsing 1960 static const uintx DefaultHeapBaseMinAddress = HeapBaseMinAddress; 1961 1962 void Arguments::set_heap_size() { 1963 const julong phys_mem = 1964 FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong) MaxRAM) 1965 : (julong) MaxRAM; 1966 1967 // If the maximum heap size has not been set with -Xmx, 1968 // then set it as fraction of the size of physical memory, 1969 // respecting the maximum and minimum sizes of the heap. 1970 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 1971 julong reasonable_max = phys_mem / MaxRAMFraction; 1972 1973 if (phys_mem <= MaxHeapSize * MinRAMFraction) { 1974 // Small physical memory, so use a minimum fraction of it for the heap 1975 reasonable_max = phys_mem / MinRAMFraction; 1976 } else { 1977 // Not-small physical memory, so require a heap at least 1978 // as large as MaxHeapSize 1979 reasonable_max = MAX2(reasonable_max, (julong) MaxHeapSize); 1980 } 1981 if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) { 1982 // Limit the heap size to ErgoHeapSizeLimit 1983 reasonable_max = MIN2(reasonable_max, (julong) ErgoHeapSizeLimit); 1984 } 1985 if (UseCompressedOops) { 1986 // Limit the heap size to the maximum possible when using compressed oops 1987 julong max_coop_heap = (julong) max_heap_for_compressed_oops(); 1988 1989 // HeapBaseMinAddress can be greater than default but not less than. 1990 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress)) { 1991 if (HeapBaseMinAddress < DefaultHeapBaseMinAddress) { 1992 // matches compressed oops printing flags 1993 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) { 1994 jio_fprintf(defaultStream::error_stream(), 1995 "HeapBaseMinAddress must be at least " UINTX_FORMAT 1996 " (" UINTX_FORMAT "G) which is greater than value given " 1997 UINTX_FORMAT "\n", 1998 DefaultHeapBaseMinAddress, 1999 DefaultHeapBaseMinAddress / G, 2000 HeapBaseMinAddress); 2001 } 2002 FLAG_SET_ERGO(uintx, HeapBaseMinAddress, DefaultHeapBaseMinAddress); 2003 } 2004 } 2005 2006 if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) { 2007 // Heap should be above HeapBaseMinAddress to get zero based compressed oops 2008 // but it should be not less than default MaxHeapSize. 2009 max_coop_heap -= HeapBaseMinAddress; 2010 } 2011 reasonable_max = MIN2(reasonable_max, max_coop_heap); 2012 } 2013 reasonable_max = limit_by_allocatable_memory(reasonable_max); 2014 2015 if (!FLAG_IS_DEFAULT(InitialHeapSize)) { 2016 // An initial heap size was specified on the command line, 2017 // so be sure that the maximum size is consistent. Done 2018 // after call to limit_by_allocatable_memory because that 2019 // method might reduce the allocation size. 2020 reasonable_max = MAX2(reasonable_max, (julong) InitialHeapSize); 2021 } 2022 2023 if (PrintGCDetails && Verbose) { 2024 // Cannot use gclog_or_tty yet. 2025 tty->print_cr(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max); 2026 } 2027 FLAG_SET_ERGO(uintx, MaxHeapSize, (uintx) reasonable_max); 2028 } 2029 2030 // If the minimum or initial heap_size have not been set or requested to be set 2031 // ergonomically, set them accordingly. 2032 if (InitialHeapSize == 0 || min_heap_size() == 0) { 2033 julong reasonable_minimum = (julong) (OldSize + NewSize); 2034 2035 reasonable_minimum = MIN2(reasonable_minimum, (julong) MaxHeapSize); 2036 2037 reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum); 2038 2039 if (InitialHeapSize == 0) { 2040 julong reasonable_initial = phys_mem / InitialRAMFraction; 2041 2042 reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong) min_heap_size()); 2043 reasonable_initial = MIN2(reasonable_initial, (julong) MaxHeapSize); 2044 2045 reasonable_initial = limit_by_allocatable_memory(reasonable_initial); 2046 2047 if (PrintGCDetails && Verbose) { 2048 // Cannot use gclog_or_tty yet. 2049 tty->print_cr(" Initial heap size " SIZE_FORMAT, (uintx) reasonable_initial); 2050 } 2051 FLAG_SET_ERGO(uintx, InitialHeapSize, (uintx) reasonable_initial); 2052 } 2053 // If the minimum heap size has not been set (via -Xms), 2054 // synchronize with InitialHeapSize to avoid errors with the default value. 2055 if (min_heap_size() == 0) { 2056 set_min_heap_size(MIN2((uintx) reasonable_minimum, InitialHeapSize)); 2057 if (PrintGCDetails && Verbose) { 2058 // Cannot use gclog_or_tty yet. 2059 tty->print_cr(" Minimum heap size " SIZE_FORMAT, min_heap_size()); 2060 } 2061 } 2062 } 2063 } 2064 2065 // This must be called after ergonomics because we want bytecode rewriting 2066 // if the server compiler is used, or if UseSharedSpaces is disabled. 2067 2068 void Arguments::set_bytecode_flags() { 2069 // Better not attempt to store into a read-only space. 2070 if (UseSharedSpaces) { 2071 FLAG_SET_DEFAULT(RewriteBytecodes, false); 2072 FLAG_SET_DEFAULT(RewriteFrequentPairs, false); 2073 } 2074 2075 if (!RewriteBytecodes) { 2076 FLAG_SET_DEFAULT(RewriteFrequentPairs, false); 2077 } 2078 } 2079 2080 // Aggressive optimization flags -XX:+AggressiveOpts 2081 2082 void Arguments::set_aggressive_opts_flags() { 2083 #ifdef COMPILER2 2084 if (AggressiveUnboxing) { 2085 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 2086 FLAG_SET_DEFAULT(EliminateAutoBox, true); 2087 } else if (!EliminateAutoBox) { 2088 // warning("AggressiveUnboxing is disabled because EliminateAutoBox is disabled"); 2089 AggressiveUnboxing = false; 2090 } 2091 if (FLAG_IS_DEFAULT(DoEscapeAnalysis)) { 2092 FLAG_SET_DEFAULT(DoEscapeAnalysis, true); 2093 } else if (!DoEscapeAnalysis) { 2094 // warning("AggressiveUnboxing is disabled because DoEscapeAnalysis is disabled"); 2095 AggressiveUnboxing = false; 2096 } 2097 } 2098 if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) { 2099 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 2100 FLAG_SET_DEFAULT(EliminateAutoBox, true); 2101 } 2102 if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) { 2103 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000); 2104 } 2105 2106 // Feed the cache size setting into the JDK 2107 char buffer[1024]; 2108 sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax); 2109 add_property(buffer); 2110 } 2111 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) { 2112 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500); 2113 } 2114 #endif 2115 2116 if (AggressiveOpts) { 2117 // Sample flag setting code 2118 // if (FLAG_IS_DEFAULT(EliminateZeroing)) { 2119 // FLAG_SET_DEFAULT(EliminateZeroing, true); 2120 // } 2121 } 2122 } 2123 2124 //=========================================================================================================== 2125 // Parsing of java.compiler property 2126 2127 void Arguments::process_java_compiler_argument(char* arg) { 2128 // For backwards compatibility, Djava.compiler=NONE or "" 2129 // causes us to switch to -Xint mode UNLESS -Xdebug 2130 // is also specified. 2131 if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) { 2132 set_java_compiler(true); // "-Djava.compiler[=...]" most recently seen. 2133 } 2134 } 2135 2136 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) { 2137 _sun_java_launcher = os::strdup_check_oom(launcher); 2138 } 2139 2140 bool Arguments::created_by_java_launcher() { 2141 assert(_sun_java_launcher != NULL, "property must have value"); 2142 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0; 2143 } 2144 2145 bool Arguments::sun_java_launcher_is_altjvm() { 2146 return _sun_java_launcher_is_altjvm; 2147 } 2148 2149 //=========================================================================================================== 2150 // Parsing of main arguments 2151 2152 bool Arguments::verify_interval(uintx val, uintx min, 2153 uintx max, const char* name) { 2154 // Returns true iff value is in the inclusive interval [min..max] 2155 // false, otherwise. 2156 if (val >= min && val <= max) { 2157 return true; 2158 } 2159 jio_fprintf(defaultStream::error_stream(), 2160 "%s of " UINTX_FORMAT " is invalid; must be between " UINTX_FORMAT 2161 " and " UINTX_FORMAT "\n", 2162 name, val, min, max); 2163 return false; 2164 } 2165 2166 bool Arguments::verify_min_value(intx val, intx min, const char* name) { 2167 // Returns true if given value is at least specified min threshold 2168 // false, otherwise. 2169 if (val >= min) { 2170 return true; 2171 } 2172 jio_fprintf(defaultStream::error_stream(), 2173 "%s of " INTX_FORMAT " is invalid; must be at least " INTX_FORMAT "\n", 2174 name, val, min); 2175 return false; 2176 } 2177 2178 bool Arguments::verify_percentage(uintx value, const char* name) { 2179 if (is_percentage(value)) { 2180 return true; 2181 } 2182 jio_fprintf(defaultStream::error_stream(), 2183 "%s of " UINTX_FORMAT " is invalid; must be between 0 and 100\n", 2184 name, value); 2185 return false; 2186 } 2187 2188 // check if do gclog rotation 2189 // +UseGCLogFileRotation is a must, 2190 // no gc log rotation when log file not supplied or 2191 // NumberOfGCLogFiles is 0 2192 2193 void check_gclog_consistency() { 2194 if (UseGCLogFileRotation) { 2195 if ((Arguments::gc_log_filename() == NULL) || (NumberOfGCLogFiles == 0)) { 2196 jio_fprintf(defaultStream::output_stream(), 2197 "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files>\n" 2198 "where num_of_file > 0\n" 2199 "GC log rotation is turned off\n"); 2200 UseGCLogFileRotation = false; 2201 } 2202 } 2203 2204 if (UseGCLogFileRotation && (GCLogFileSize != 0) && (GCLogFileSize < 8 * K)) { 2205 FLAG_SET_CMDLINE(uintx, GCLogFileSize, 8 * K); 2206 jio_fprintf(defaultStream::output_stream(), 2207 "GCLogFileSize changed to minimum 8K\n"); 2208 } 2209 } 2210 2211 // This function is called for -Xloggc:<filename>, it can be used 2212 // to check if a given file name(or string) conforms to the following 2213 // specification: 2214 // A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]" 2215 // %p and %t only allowed once. We only limit usage of filename not path 2216 2217 bool is_filename_valid(const char *file_name) { 2218 const char* p = file_name; 2219 char file_sep = os::file_separator()[0]; 2220 const char* cp; 2221 // skip prefix path 2222 for (cp = file_name; *cp != '\0'; cp++) { 2223 if (*cp == '/' || *cp == file_sep) { 2224 p = cp + 1; 2225 } 2226 } 2227 2228 int count_p = 0; 2229 int count_t = 0; 2230 while (*p != '\0') { 2231 if ((*p >= '0' && *p <= '9') || 2232 (*p >= 'A' && *p <= 'Z') || 2233 (*p >= 'a' && *p <= 'z') || 2234 *p == '-' || 2235 *p == '_' || 2236 *p == '.') { 2237 p++; 2238 continue; 2239 } 2240 if (*p == '%') { 2241 if (*(p + 1) == 'p') { 2242 p += 2; 2243 count_p++; 2244 continue; 2245 } 2246 if (*(p + 1) == 't') { 2247 p += 2; 2248 count_t++; 2249 continue; 2250 } 2251 } 2252 return false; 2253 } 2254 return count_p < 2 && count_t < 2; 2255 } 2256 2257 bool Arguments::verify_MinHeapFreeRatio(FormatBuffer<80>& err_msg, uintx min_heap_free_ratio) { 2258 if (!is_percentage(min_heap_free_ratio)) { 2259 err_msg.print("MinHeapFreeRatio must have a value between 0 and 100"); 2260 return false; 2261 } 2262 if (min_heap_free_ratio > MaxHeapFreeRatio) { 2263 err_msg.print("MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or " 2264 "equal to MaxHeapFreeRatio (" UINTX_FORMAT ")", min_heap_free_ratio, 2265 MaxHeapFreeRatio); 2266 return false; 2267 } 2268 // This does not set the flag itself, but stores the value in a safe place for later usage. 2269 _min_heap_free_ratio = min_heap_free_ratio; 2270 return true; 2271 } 2272 2273 bool Arguments::verify_MaxHeapFreeRatio(FormatBuffer<80>& err_msg, uintx max_heap_free_ratio) { 2274 if (!is_percentage(max_heap_free_ratio)) { 2275 err_msg.print("MaxHeapFreeRatio must have a value between 0 and 100"); 2276 return false; 2277 } 2278 if (max_heap_free_ratio < MinHeapFreeRatio) { 2279 err_msg.print("MaxHeapFreeRatio (" UINTX_FORMAT ") must be greater than or " 2280 "equal to MinHeapFreeRatio (" UINTX_FORMAT ")", max_heap_free_ratio, 2281 MinHeapFreeRatio); 2282 return false; 2283 } 2284 // This does not set the flag itself, but stores the value in a safe place for later usage. 2285 _max_heap_free_ratio = max_heap_free_ratio; 2286 return true; 2287 } 2288 2289 // Check consistency of GC selection 2290 2291 bool Arguments::check_gc_consistency_user() { 2292 check_gclog_consistency(); 2293 // Ensure that the user has not selected conflicting sets 2294 // of collectors. 2295 uint i = 0; 2296 if (UseSerialGC) i++; 2297 if (UseConcMarkSweepGC) i++; 2298 if (UseParallelGC || UseParallelOldGC) i++; 2299 if (UseG1GC) i++; 2300 if (i > 1) { 2301 jio_fprintf(defaultStream::error_stream(), 2302 "Conflicting collector combinations in option list; " 2303 "please refer to the release notes for the combinations " 2304 "allowed\n"); 2305 return false; 2306 } 2307 2308 if (UseConcMarkSweepGC && !UseParNewGC) { 2309 jio_fprintf(defaultStream::error_stream(), 2310 "It is not possible to combine the DefNew young collector with the CMS collector.\n"); 2311 return false; 2312 } 2313 2314 if (UseParNewGC && !UseConcMarkSweepGC) { 2315 // !UseConcMarkSweepGC means that we are using serial old gc. Unfortunately we don't 2316 // set up UseSerialGC properly, so that can't be used in the check here. 2317 jio_fprintf(defaultStream::error_stream(), 2318 "It is not possible to combine the ParNew young collector with the Serial old collector.\n"); 2319 return false; 2320 } 2321 2322 return true; 2323 } 2324 2325 // Check stack pages settings 2326 2327 bool Arguments::check_stack_pages() { 2328 bool status = true; 2329 status = status && verify_min_value(StackYellowPages, 1, "StackYellowPages"); 2330 status = status && verify_min_value(StackRedPages, 1, "StackRedPages"); 2331 // greater stack shadow pages can't generate instruction to bang stack 2332 status = status && verify_interval(StackShadowPages, 1, 50, "StackShadowPages"); 2333 return status; 2334 } 2335 2336 // Check the consistency of vm_init_args 2337 2338 bool Arguments::check_vm_args_consistency() { 2339 // Method for adding checks for flag consistency. 2340 // The intent is to warn the user of all possible conflicts, 2341 // before returning an error. 2342 // Note: Needs platform-dependent factoring. 2343 bool status = true; 2344 2345 if (TLABRefillWasteFraction == 0) { 2346 jio_fprintf(defaultStream::error_stream(), 2347 "TLABRefillWasteFraction should be a denominator, " 2348 "not " SIZE_FORMAT "\n", 2349 TLABRefillWasteFraction); 2350 status = false; 2351 } 2352 2353 status = status && verify_interval(AdaptiveSizePolicyWeight, 0, 100, 2354 "AdaptiveSizePolicyWeight"); 2355 status = status && verify_percentage(ThresholdTolerance, "ThresholdTolerance"); 2356 2357 // Divide by bucket size to prevent a large size from causing rollover when 2358 // calculating amount of memory needed to be allocated for the String table. 2359 status = status && verify_interval(StringTableSize, minimumStringTableSize, 2360 (max_uintx / StringTable::bucket_size()), "StringTable size"); 2361 2362 status = status && verify_interval(SymbolTableSize, minimumSymbolTableSize, 2363 (max_uintx / SymbolTable::bucket_size()), "SymbolTable size"); 2364 2365 { 2366 // Using "else if" below to avoid printing two error messages if min > max. 2367 // This will also prevent us from reporting both min>100 and max>100 at the 2368 // same time, but that is less annoying than printing two identical errors IMHO. 2369 FormatBuffer<80> err_msg("%s", ""); 2370 if (!verify_MinHeapFreeRatio(err_msg, MinHeapFreeRatio)) { 2371 jio_fprintf(defaultStream::error_stream(), "%s\n", err_msg.buffer()); 2372 status = false; 2373 } else if (!verify_MaxHeapFreeRatio(err_msg, MaxHeapFreeRatio)) { 2374 jio_fprintf(defaultStream::error_stream(), "%s\n", err_msg.buffer()); 2375 status = false; 2376 } 2377 } 2378 2379 // Min/MaxMetaspaceFreeRatio 2380 status = status && verify_percentage(MinMetaspaceFreeRatio, "MinMetaspaceFreeRatio"); 2381 status = status && verify_percentage(MaxMetaspaceFreeRatio, "MaxMetaspaceFreeRatio"); 2382 2383 if (MinMetaspaceFreeRatio > MaxMetaspaceFreeRatio) { 2384 jio_fprintf(defaultStream::error_stream(), 2385 "MinMetaspaceFreeRatio (%s" UINTX_FORMAT ") must be less than or " 2386 "equal to MaxMetaspaceFreeRatio (%s" UINTX_FORMAT ")\n", 2387 FLAG_IS_DEFAULT(MinMetaspaceFreeRatio) ? "Default: " : "", 2388 MinMetaspaceFreeRatio, 2389 FLAG_IS_DEFAULT(MaxMetaspaceFreeRatio) ? "Default: " : "", 2390 MaxMetaspaceFreeRatio); 2391 status = false; 2392 } 2393 2394 // Trying to keep 100% free is not practical 2395 MinMetaspaceFreeRatio = MIN2(MinMetaspaceFreeRatio, (uintx) 99); 2396 2397 if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) { 2398 MarkSweepAlwaysCompactCount = 1; // Move objects every gc. 2399 } 2400 2401 if (UseParallelOldGC && ParallelOldGCSplitALot) { 2402 // Settings to encourage splitting. 2403 if (!FLAG_IS_CMDLINE(NewRatio)) { 2404 FLAG_SET_CMDLINE(uintx, NewRatio, 2); 2405 } 2406 if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) { 2407 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false); 2408 } 2409 } 2410 2411 if (!(UseParallelGC || UseParallelOldGC) && FLAG_IS_DEFAULT(ScavengeBeforeFullGC)) { 2412 FLAG_SET_DEFAULT(ScavengeBeforeFullGC, false); 2413 } 2414 2415 status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit"); 2416 status = status && verify_percentage(GCTimeLimit, "GCTimeLimit"); 2417 if (GCTimeLimit == 100) { 2418 // Turn off gc-overhead-limit-exceeded checks 2419 FLAG_SET_DEFAULT(UseGCOverheadLimit, false); 2420 } 2421 2422 status = status && check_gc_consistency_user(); 2423 status = status && check_stack_pages(); 2424 2425 status = status && verify_percentage(CMSIncrementalSafetyFactor, 2426 "CMSIncrementalSafetyFactor"); 2427 2428 // CMS space iteration, which FLSVerifyAllHeapreferences entails, 2429 // insists that we hold the requisite locks so that the iteration is 2430 // MT-safe. For the verification at start-up and shut-down, we don't 2431 // yet have a good way of acquiring and releasing these locks, 2432 // which are not visible at the CollectedHeap level. We want to 2433 // be able to acquire these locks and then do the iteration rather 2434 // than just disable the lock verification. This will be fixed under 2435 // bug 4788986. 2436 if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) { 2437 if (VerifyDuringStartup) { 2438 warning("Heap verification at start-up disabled " 2439 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2440 VerifyDuringStartup = false; // Disable verification at start-up 2441 } 2442 2443 if (VerifyBeforeExit) { 2444 warning("Heap verification at shutdown disabled " 2445 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2446 VerifyBeforeExit = false; // Disable verification at shutdown 2447 } 2448 } 2449 2450 // Note: only executed in non-PRODUCT mode 2451 if (!UseAsyncConcMarkSweepGC && 2452 (ExplicitGCInvokesConcurrent || 2453 ExplicitGCInvokesConcurrentAndUnloadsClasses)) { 2454 jio_fprintf(defaultStream::error_stream(), 2455 "error: +ExplicitGCInvokesConcurrent[AndUnloadsClasses] conflicts" 2456 " with -UseAsyncConcMarkSweepGC"); 2457 status = false; 2458 } 2459 2460 status = status && verify_min_value(ParGCArrayScanChunk, 1, "ParGCArrayScanChunk"); 2461 2462 #if INCLUDE_ALL_GCS 2463 if (UseG1GC) { 2464 status = status && verify_percentage(G1NewSizePercent, "G1NewSizePercent"); 2465 status = status && verify_percentage(G1MaxNewSizePercent, "G1MaxNewSizePercent"); 2466 status = status && verify_interval(G1NewSizePercent, 0, G1MaxNewSizePercent, "G1NewSizePercent"); 2467 2468 status = status && verify_percentage(InitiatingHeapOccupancyPercent, 2469 "InitiatingHeapOccupancyPercent"); 2470 status = status && verify_min_value(G1RefProcDrainInterval, 1, 2471 "G1RefProcDrainInterval"); 2472 status = status && verify_min_value((intx) G1ConcMarkStepDurationMillis, 1, 2473 "G1ConcMarkStepDurationMillis"); 2474 status = status && verify_interval(G1ConcRSHotCardLimit, 0, max_jubyte, 2475 "G1ConcRSHotCardLimit"); 2476 status = status && verify_interval(G1ConcRSLogCacheSize, 0, 31, 2477 "G1ConcRSLogCacheSize"); 2478 status = status && verify_interval(StringDeduplicationAgeThreshold, 1, markOopDesc::max_age, 2479 "StringDeduplicationAgeThreshold"); 2480 } 2481 if (UseConcMarkSweepGC) { 2482 status = status && verify_min_value(CMSOldPLABNumRefills, 1, "CMSOldPLABNumRefills"); 2483 status = status && verify_min_value(CMSOldPLABToleranceFactor, 1, "CMSOldPLABToleranceFactor"); 2484 status = status && verify_min_value(CMSOldPLABMax, 1, "CMSOldPLABMax"); 2485 status = status && verify_interval(CMSOldPLABMin, 1, CMSOldPLABMax, "CMSOldPLABMin"); 2486 2487 status = status && verify_min_value(CMSYoungGenPerWorker, 1, "CMSYoungGenPerWorker"); 2488 2489 status = status && verify_min_value(CMSSamplingGrain, 1, "CMSSamplingGrain"); 2490 status = status && verify_interval(CMS_SweepWeight, 0, 100, "CMS_SweepWeight"); 2491 status = status && verify_interval(CMS_FLSWeight, 0, 100, "CMS_FLSWeight"); 2492 2493 status = status && verify_interval(FLSCoalescePolicy, 0, 4, "FLSCoalescePolicy"); 2494 2495 status = status && verify_min_value(CMSRescanMultiple, 1, "CMSRescanMultiple"); 2496 status = status && verify_min_value(CMSConcMarkMultiple, 1, "CMSConcMarkMultiple"); 2497 2498 status = status && verify_interval(CMSPrecleanIter, 0, 9, "CMSPrecleanIter"); 2499 status = status && verify_min_value(CMSPrecleanDenominator, 1, "CMSPrecleanDenominator"); 2500 status = status && verify_interval(CMSPrecleanNumerator, 0, CMSPrecleanDenominator - 1, "CMSPrecleanNumerator"); 2501 2502 status = status && verify_percentage(CMSBootstrapOccupancy, "CMSBootstrapOccupancy"); 2503 2504 status = status && verify_min_value(CMSPrecleanThreshold, 100, "CMSPrecleanThreshold"); 2505 2506 status = status && verify_percentage(CMSScheduleRemarkEdenPenetration, "CMSScheduleRemarkEdenPenetration"); 2507 status = status && verify_min_value(CMSScheduleRemarkSamplingRatio, 1, "CMSScheduleRemarkSamplingRatio"); 2508 status = status && verify_min_value(CMSBitMapYieldQuantum, 1, "CMSBitMapYieldQuantum"); 2509 status = status && verify_percentage(CMSTriggerRatio, "CMSTriggerRatio"); 2510 status = status && verify_percentage(CMSIsTooFullPercentage, "CMSIsTooFullPercentage"); 2511 } 2512 2513 if (UseParallelGC || UseParallelOldGC) { 2514 status = status && verify_interval(ParallelOldDeadWoodLimiterMean, 0, 100, "ParallelOldDeadWoodLimiterMean"); 2515 status = status && verify_interval(ParallelOldDeadWoodLimiterStdDev, 0, 100, "ParallelOldDeadWoodLimiterStdDev"); 2516 2517 status = status && verify_percentage(YoungGenerationSizeIncrement, "YoungGenerationSizeIncrement"); 2518 status = status && verify_percentage(TenuredGenerationSizeIncrement, "TenuredGenerationSizeIncrement"); 2519 2520 status = status && verify_min_value(YoungGenerationSizeSupplementDecay, 1, "YoungGenerationSizeSupplementDecay"); 2521 status = status && verify_min_value(TenuredGenerationSizeSupplementDecay, 1, "TenuredGenerationSizeSupplementDecay"); 2522 2523 status = status && verify_min_value(ParGCCardsPerStrideChunk, 1, "ParGCCardsPerStrideChunk"); 2524 2525 status = status && verify_min_value(ParallelOldGCSplitInterval, 0, "ParallelOldGCSplitInterval"); 2526 } 2527 #endif // INCLUDE_ALL_GCS 2528 2529 status = status && verify_interval(RefDiscoveryPolicy, 2530 ReferenceProcessor::DiscoveryPolicyMin, 2531 ReferenceProcessor::DiscoveryPolicyMax, 2532 "RefDiscoveryPolicy"); 2533 2534 // Limit the lower bound of this flag to 1 as it is used in a division 2535 // expression. 2536 status = status && verify_interval(TLABWasteTargetPercent, 2537 1, 100, "TLABWasteTargetPercent"); 2538 2539 status = status && verify_object_alignment(); 2540 2541 status = status && verify_interval(CompressedClassSpaceSize, 1 * M, 3 * G, 2542 "CompressedClassSpaceSize"); 2543 2544 status = status && verify_interval(MarkStackSizeMax, 2545 1, (max_jint - 1), "MarkStackSizeMax"); 2546 status = status && verify_interval(NUMAChunkResizeWeight, 0, 100, "NUMAChunkResizeWeight"); 2547 2548 status = status && verify_min_value(LogEventsBufferEntries, 1, "LogEventsBufferEntries"); 2549 2550 status = status && verify_min_value(HeapSizePerGCThread, (uintx) os::vm_page_size(), "HeapSizePerGCThread"); 2551 2552 status = status && verify_min_value(GCTaskTimeStampEntries, 1, "GCTaskTimeStampEntries"); 2553 2554 status = status && verify_percentage(ParallelGCBufferWastePct, "ParallelGCBufferWastePct"); 2555 status = status && verify_interval(TargetPLABWastePct, 1, 100, "TargetPLABWastePct"); 2556 2557 status = status && verify_min_value(ParGCStridesPerThread, 1, "ParGCStridesPerThread"); 2558 2559 status = status && verify_min_value(MinRAMFraction, 1, "MinRAMFraction"); 2560 status = status && verify_min_value(InitialRAMFraction, 1, "InitialRAMFraction"); 2561 status = status && verify_min_value(MaxRAMFraction, 1, "MaxRAMFraction"); 2562 2563 status = status && verify_interval(AdaptiveTimeWeight, 0, 100, "AdaptiveTimeWeight"); 2564 status = status && verify_min_value(AdaptiveSizeDecrementScaleFactor, 1, "AdaptiveSizeDecrementScaleFactor"); 2565 2566 status = status && verify_interval(TLABAllocationWeight, 0, 100, "TLABAllocationWeight"); 2567 status = status && verify_min_value(MinTLABSize, 1, "MinTLABSize"); 2568 status = status && verify_min_value(TLABRefillWasteFraction, 1, "TLABRefillWasteFraction"); 2569 2570 status = status && verify_percentage(YoungGenerationSizeSupplement, "YoungGenerationSizeSupplement"); 2571 status = status && verify_percentage(TenuredGenerationSizeSupplement, "TenuredGenerationSizeSupplement"); 2572 2573 status = status && verify_interval(MaxTenuringThreshold, 0, markOopDesc::max_age + 1, "MaxTenuringThreshold"); 2574 status = status && verify_interval(InitialTenuringThreshold, 0, MaxTenuringThreshold, "InitialTenuringThreshold"); 2575 status = status && verify_percentage(TargetSurvivorRatio, "TargetSurvivorRatio"); 2576 status = status && verify_percentage(MarkSweepDeadRatio, "MarkSweepDeadRatio"); 2577 2578 status = status && verify_min_value(MarkSweepAlwaysCompactCount, 1, "MarkSweepAlwaysCompactCount"); 2579 #ifdef COMPILER1 2580 status = status && verify_min_value(ValueMapInitialSize, 1, "ValueMapInitialSize"); 2581 #endif 2582 status = status && verify_min_value(HeapSearchSteps, 1, "HeapSearchSteps"); 2583 2584 if (PrintNMTStatistics) { 2585 #if INCLUDE_NMT 2586 if (MemTracker::tracking_level() == NMT_off) { 2587 #endif // INCLUDE_NMT 2588 warning("PrintNMTStatistics is disabled, because native memory tracking is not enabled"); 2589 PrintNMTStatistics = false; 2590 #if INCLUDE_NMT 2591 } 2592 #endif 2593 } 2594 2595 // Need to limit the extent of the padding to reasonable size. 2596 // 8K is well beyond the reasonable HW cache line size, even with the 2597 // aggressive prefetching, while still leaving the room for segregating 2598 // among the distinct pages. 2599 if (ContendedPaddingWidth < 0 || ContendedPaddingWidth > 8192) { 2600 jio_fprintf(defaultStream::error_stream(), 2601 "ContendedPaddingWidth=" INTX_FORMAT " must be in between %d and %d\n", 2602 ContendedPaddingWidth, 0, 8192); 2603 status = false; 2604 } 2605 2606 // Need to enforce the padding not to break the existing field alignments. 2607 // It is sufficient to check against the largest type size. 2608 if ((ContendedPaddingWidth % BytesPerLong) != 0) { 2609 jio_fprintf(defaultStream::error_stream(), 2610 "ContendedPaddingWidth=" INTX_FORMAT " must be a multiple of %d\n", 2611 ContendedPaddingWidth, BytesPerLong); 2612 status = false; 2613 } 2614 2615 // Check lower bounds of the code cache 2616 // Template Interpreter code is approximately 3X larger in debug builds. 2617 uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3); 2618 if (InitialCodeCacheSize < (uintx) os::vm_page_size()) { 2619 jio_fprintf(defaultStream::error_stream(), 2620 "Invalid InitialCodeCacheSize=%dK. Must be at least %dK.\n", InitialCodeCacheSize / K, 2621 os::vm_page_size() / K); 2622 status = false; 2623 } else if (ReservedCodeCacheSize < InitialCodeCacheSize) { 2624 jio_fprintf(defaultStream::error_stream(), 2625 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n", 2626 ReservedCodeCacheSize / K, InitialCodeCacheSize / K); 2627 status = false; 2628 } else if (ReservedCodeCacheSize < min_code_cache_size) { 2629 jio_fprintf(defaultStream::error_stream(), 2630 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize / K, 2631 min_code_cache_size / K); 2632 status = false; 2633 } else if (ReservedCodeCacheSize > 2 * G) { 2634 // Code cache size larger than MAXINT is not supported. 2635 jio_fprintf(defaultStream::error_stream(), 2636 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize / M, 2637 (2 * G) / M); 2638 status = false; 2639 } else if (NonNMethodCodeHeapSize < min_code_cache_size) { 2640 jio_fprintf(defaultStream::error_stream(), 2641 "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize / K, 2642 min_code_cache_size / K); 2643 status = false; 2644 } else if ((!FLAG_IS_DEFAULT(NonNMethodCodeHeapSize) || !FLAG_IS_DEFAULT(ProfiledCodeHeapSize) || !FLAG_IS_DEFAULT(NonProfiledCodeHeapSize)) 2645 && (NonNMethodCodeHeapSize + NonProfiledCodeHeapSize + ProfiledCodeHeapSize) != ReservedCodeCacheSize) { 2646 jio_fprintf(defaultStream::error_stream(), 2647 "Invalid code heap sizes: NonNMethodCodeHeapSize(%dK) + ProfiledCodeHeapSize(%dK) + NonProfiledCodeHeapSize(%dK) = %dK. Must be equal to ReservedCodeCacheSize = %uK.\n", 2648 NonNMethodCodeHeapSize / K, ProfiledCodeHeapSize / K, NonProfiledCodeHeapSize / K, 2649 (NonNMethodCodeHeapSize + ProfiledCodeHeapSize + NonProfiledCodeHeapSize) / K, ReservedCodeCacheSize / K); 2650 status = false; 2651 } 2652 2653 status &= verify_interval(NmethodSweepActivity, 0, 2000, "NmethodSweepActivity"); 2654 status &= verify_interval(CodeCacheMinBlockLength, 1, 100, "CodeCacheMinBlockLength"); 2655 status &= verify_interval(CodeCacheSegmentSize, 1, 1024, "CodeCacheSegmentSize"); 2656 status &= verify_interval(StartAggressiveSweepingAt, 0, 100, "StartAggressiveSweepingAt"); 2657 2658 2659 int min_number_of_compiler_threads = get_min_number_of_compiler_threads(); 2660 // The default CICompilerCount's value is CI_COMPILER_COUNT. 2661 assert(min_number_of_compiler_threads <= CI_COMPILER_COUNT, "minimum should be less or equal default number"); 2662 // Check the minimum number of compiler threads 2663 status &= verify_min_value(CICompilerCount, min_number_of_compiler_threads, "CICompilerCount"); 2664 2665 if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) { 2666 warning("The VM option CICompilerCountPerCPU overrides CICompilerCount."); 2667 } 2668 2669 return status; 2670 } 2671 2672 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore, 2673 const char* option_type) { 2674 if (ignore) return false; 2675 2676 const char* spacer = " "; 2677 if (option_type == NULL) { 2678 option_type = ++spacer; // Set both to the empty string. 2679 } 2680 2681 if (os::obsolete_option(option)) { 2682 jio_fprintf(defaultStream::error_stream(), 2683 "Obsolete %s%soption: %s\n", option_type, spacer, 2684 option->optionString); 2685 return false; 2686 } else { 2687 jio_fprintf(defaultStream::error_stream(), 2688 "Unrecognized %s%soption: %s\n", option_type, spacer, 2689 option->optionString); 2690 return true; 2691 } 2692 } 2693 2694 static const char* user_assertion_options[] = { 2695 "-da", "-ea", "-disableassertions", "-enableassertions", 0 2696 }; 2697 2698 static const char* system_assertion_options[] = { 2699 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0 2700 }; 2701 2702 bool Arguments::parse_uintx(const char* value, 2703 uintx* uintx_arg, 2704 uintx min_size) { 2705 2706 // Check the sign first since atomull() parses only unsigned values. 2707 bool value_is_positive = !(*value == '-'); 2708 2709 if (value_is_positive) { 2710 julong n; 2711 bool good_return = atomull(value, &n); 2712 if (good_return) { 2713 bool above_minimum = n >= min_size; 2714 bool value_is_too_large = n > max_uintx; 2715 2716 if (above_minimum && !value_is_too_large) { 2717 *uintx_arg = n; 2718 return true; 2719 } 2720 } 2721 } 2722 return false; 2723 } 2724 2725 Arguments::ArgsRange Arguments::parse_memory_size(const char* s, 2726 julong* long_arg, 2727 julong min_size) { 2728 if (!atomull(s, long_arg)) return arg_unreadable; 2729 return check_memory_size(*long_arg, min_size); 2730 } 2731 2732 // Parse JavaVMInitArgs structure 2733 2734 jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) { 2735 // For components of the system classpath. 2736 SysClassPath scp(Arguments::get_sysclasspath()); 2737 bool scp_assembly_required = false; 2738 2739 // Save default settings for some mode flags 2740 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 2741 Arguments::_UseOnStackReplacement = UseOnStackReplacement; 2742 Arguments::_ClipInlining = ClipInlining; 2743 Arguments::_BackgroundCompilation = BackgroundCompilation; 2744 2745 // Setup flags for mixed which is the default 2746 set_mode_flags(_mixed); 2747 2748 // Parse JAVA_TOOL_OPTIONS environment variable (if present) 2749 jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required); 2750 if (result != JNI_OK) { 2751 return result; 2752 } 2753 2754 // Parse JavaVMInitArgs structure passed in 2755 result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, Flag::COMMAND_LINE); 2756 if (result != JNI_OK) { 2757 return result; 2758 } 2759 2760 // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM) 2761 result = parse_java_options_environment_variable(&scp, &scp_assembly_required); 2762 if (result != JNI_OK) { 2763 return result; 2764 } 2765 2766 // Do final processing now that all arguments have been parsed 2767 result = finalize_vm_init_args(&scp, scp_assembly_required); 2768 if (result != JNI_OK) { 2769 return result; 2770 } 2771 2772 return JNI_OK; 2773 } 2774 2775 // Checks if name in command-line argument -agent{lib,path}:name[=options] 2776 // represents a valid HPROF of JDWP agent. is_path==true denotes that we 2777 // are dealing with -agentpath (case where name is a path), otherwise with 2778 // -agentlib 2779 2780 bool valid_hprof_or_jdwp_agent(char *name, bool is_path) { 2781 char *_name; 2782 const char *_hprof = "hprof", *_jdwp = "jdwp"; 2783 size_t _len_hprof, _len_jdwp, _len_prefix; 2784 2785 if (is_path) { 2786 if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) { 2787 return false; 2788 } 2789 2790 _name++; // skip past last path separator 2791 _len_prefix = strlen(JNI_LIB_PREFIX); 2792 2793 if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) { 2794 return false; 2795 } 2796 2797 _name += _len_prefix; 2798 _len_hprof = strlen(_hprof); 2799 _len_jdwp = strlen(_jdwp); 2800 2801 if (strncmp(_name, _hprof, _len_hprof) == 0) { 2802 _name += _len_hprof; 2803 } else if (strncmp(_name, _jdwp, _len_jdwp) == 0) { 2804 _name += _len_jdwp; 2805 } else { 2806 return false; 2807 } 2808 2809 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) { 2810 return false; 2811 } 2812 2813 return true; 2814 } 2815 2816 if (strcmp(name, _hprof) == 0 || strcmp(name, _jdwp) == 0) { 2817 return true; 2818 } 2819 2820 return false; 2821 } 2822 2823 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, 2824 SysClassPath* scp_p, 2825 bool* scp_assembly_required_p, 2826 Flag::Flags origin) { 2827 // Remaining part of option string 2828 const char* tail; 2829 2830 // iterate over arguments 2831 for (int index = 0; index < args->nOptions; index++) { 2832 bool is_absolute_path = false; // for -agentpath vs -agentlib 2833 2834 const JavaVMOption* option = args->options + index; 2835 2836 if (!match_option(option, "-Djava.class.path", &tail) && 2837 !match_option(option, "-Dsun.java.command", &tail) && 2838 !match_option(option, "-Dsun.java.launcher", &tail)) { 2839 2840 // add all jvm options to the jvm_args string. This string 2841 // is used later to set the java.vm.args PerfData string constant. 2842 // the -Djava.class.path and the -Dsun.java.command options are 2843 // omitted from jvm_args string as each have their own PerfData 2844 // string constant object. 2845 build_jvm_args(option->optionString); 2846 } 2847 2848 // -verbose:[class/gc/jni] 2849 if (match_option(option, "-verbose", &tail)) { 2850 if (!strcmp(tail, ":class") || !strcmp(tail, "")) { 2851 FLAG_SET_CMDLINE(bool, TraceClassLoading, true); 2852 FLAG_SET_CMDLINE(bool, TraceClassUnloading, true); 2853 } else if (!strcmp(tail, ":gc")) { 2854 FLAG_SET_CMDLINE(bool, PrintGC, true); 2855 } else if (!strcmp(tail, ":jni")) { 2856 FLAG_SET_CMDLINE(bool, PrintJNIResolving, true); 2857 } 2858 // -da / -ea / -disableassertions / -enableassertions 2859 // These accept an optional class/package name separated by a colon, e.g., 2860 // -da:java.lang.Thread. 2861 } else if (match_option(option, user_assertion_options, &tail, true)) { 2862 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2863 if (*tail == '\0') { 2864 JavaAssertions::setUserClassDefault(enable); 2865 } else { 2866 assert(*tail == ':', "bogus match by match_option()"); 2867 JavaAssertions::addOption(tail + 1, enable); 2868 } 2869 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions 2870 } else if (match_option(option, system_assertion_options, &tail, false)) { 2871 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2872 JavaAssertions::setSystemClassDefault(enable); 2873 // -bootclasspath: 2874 } else if (match_option(option, "-Xbootclasspath:", &tail)) { 2875 scp_p->reset_path(tail); 2876 *scp_assembly_required_p = true; 2877 // -bootclasspath/a: 2878 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) { 2879 scp_p->add_suffix(tail); 2880 *scp_assembly_required_p = true; 2881 // -bootclasspath/p: 2882 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) { 2883 scp_p->add_prefix(tail); 2884 *scp_assembly_required_p = true; 2885 // -Xrun 2886 } else if (match_option(option, "-Xrun", &tail)) { 2887 if (tail != NULL) { 2888 const char* pos = strchr(tail, ':'); 2889 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2890 char* name = (char*) memcpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len); 2891 name[len] = '\0'; 2892 2893 char *options = NULL; 2894 if (pos != NULL) { 2895 size_t len2 = strlen(pos + 1) + 1; // options start after ':'. Final zero must be copied. 2896 options = (char*) memcpy(NEW_C_HEAP_ARRAY(char, len2, mtInternal), pos + 1, len2); 2897 } 2898 #if !INCLUDE_JVMTI 2899 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) { 2900 jio_fprintf(defaultStream::error_stream(), 2901 "Profiling and debugging agents are not supported in this VM\n"); 2902 return JNI_ERR; 2903 } 2904 #endif // !INCLUDE_JVMTI 2905 add_init_library(name, options); 2906 } 2907 // -agentlib and -agentpath 2908 } else if (match_option(option, "-agentlib:", &tail) || 2909 (is_absolute_path = match_option(option, "-agentpath:", &tail))) { 2910 if (tail != NULL) { 2911 const char* pos = strchr(tail, '='); 2912 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2913 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len); 2914 name[len] = '\0'; 2915 2916 char *options = NULL; 2917 if (pos != NULL) { 2918 options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1, mtInternal), pos + 1); 2919 } 2920 #if !INCLUDE_JVMTI 2921 if (valid_hprof_or_jdwp_agent(name, is_absolute_path)) { 2922 jio_fprintf(defaultStream::error_stream(), 2923 "Profiling and debugging agents are not supported in this VM\n"); 2924 return JNI_ERR; 2925 } 2926 #endif // !INCLUDE_JVMTI 2927 add_init_agent(name, options, is_absolute_path); 2928 } 2929 // -javaagent 2930 } else if (match_option(option, "-javaagent:", &tail)) { 2931 #if !INCLUDE_JVMTI 2932 jio_fprintf(defaultStream::error_stream(), 2933 "Instrumentation agents are not supported in this VM\n"); 2934 return JNI_ERR; 2935 #else 2936 if (tail != NULL) { 2937 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtInternal), tail); 2938 add_init_agent("instrument", options, false); 2939 } 2940 #endif // !INCLUDE_JVMTI 2941 // -Xnoclassgc 2942 } else if (match_option(option, "-Xnoclassgc")) { 2943 FLAG_SET_CMDLINE(bool, ClassUnloading, false); 2944 // -Xconcgc 2945 } else if (match_option(option, "-Xconcgc")) { 2946 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true); 2947 // -Xnoconcgc 2948 } else if (match_option(option, "-Xnoconcgc")) { 2949 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false); 2950 // -Xbatch 2951 } else if (match_option(option, "-Xbatch")) { 2952 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); 2953 // -Xmn for compatibility with other JVM vendors 2954 } else if (match_option(option, "-Xmn", &tail)) { 2955 julong long_initial_young_size = 0; 2956 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1); 2957 if (errcode != arg_in_range) { 2958 jio_fprintf(defaultStream::error_stream(), 2959 "Invalid initial young generation size: %s\n", option->optionString); 2960 describe_range_error(errcode); 2961 return JNI_EINVAL; 2962 } 2963 FLAG_SET_CMDLINE(uintx, MaxNewSize, (uintx) long_initial_young_size); 2964 FLAG_SET_CMDLINE(uintx, NewSize, (uintx) long_initial_young_size); 2965 // -Xms 2966 } else if (match_option(option, "-Xms", &tail)) { 2967 julong long_initial_heap_size = 0; 2968 // an initial heap size of 0 means automatically determine 2969 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0); 2970 if (errcode != arg_in_range) { 2971 jio_fprintf(defaultStream::error_stream(), 2972 "Invalid initial heap size: %s\n", option->optionString); 2973 describe_range_error(errcode); 2974 return JNI_EINVAL; 2975 } 2976 set_min_heap_size((uintx) long_initial_heap_size); 2977 // Currently the minimum size and the initial heap sizes are the same. 2978 // Can be overridden with -XX:InitialHeapSize. 2979 FLAG_SET_CMDLINE(uintx, InitialHeapSize, (uintx) long_initial_heap_size); 2980 // -Xmx 2981 } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) { 2982 julong long_max_heap_size = 0; 2983 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1); 2984 if (errcode != arg_in_range) { 2985 jio_fprintf(defaultStream::error_stream(), 2986 "Invalid maximum heap size: %s\n", option->optionString); 2987 describe_range_error(errcode); 2988 return JNI_EINVAL; 2989 } 2990 FLAG_SET_CMDLINE(uintx, MaxHeapSize, (uintx) long_max_heap_size); 2991 // Xmaxf 2992 } else if (match_option(option, "-Xmaxf", &tail)) { 2993 char* err; 2994 int maxf = (int) (strtod(tail, &err) * 100); 2995 if (*err != '\0' || *tail == '\0' || maxf < 0 || maxf > 100) { 2996 jio_fprintf(defaultStream::error_stream(), 2997 "Bad max heap free percentage size: %s\n", 2998 option->optionString); 2999 return JNI_EINVAL; 3000 } else { 3001 FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf); 3002 } 3003 // Xminf 3004 } else if (match_option(option, "-Xminf", &tail)) { 3005 char* err; 3006 int minf = (int) (strtod(tail, &err) * 100); 3007 if (*err != '\0' || *tail == '\0' || minf < 0 || minf > 100) { 3008 jio_fprintf(defaultStream::error_stream(), 3009 "Bad min heap free percentage size: %s\n", 3010 option->optionString); 3011 return JNI_EINVAL; 3012 } else { 3013 FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf); 3014 } 3015 // -Xss 3016 } else if (match_option(option, "-Xss", &tail)) { 3017 julong long_ThreadStackSize = 0; 3018 ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000); 3019 if (errcode != arg_in_range) { 3020 jio_fprintf(defaultStream::error_stream(), 3021 "Invalid thread stack size: %s\n", option->optionString); 3022 describe_range_error(errcode); 3023 return JNI_EINVAL; 3024 } 3025 // Internally track ThreadStackSize in units of 1024 bytes. 3026 FLAG_SET_CMDLINE(intx, ThreadStackSize, 3027 round_to((int) long_ThreadStackSize, K) / K); 3028 // -Xoss 3029 } else if (match_option(option, "-Xoss", &tail)) { 3030 // HotSpot does not have separate native and Java stacks, ignore silently for compatibility 3031 } else if (match_option(option, "-XX:CodeCacheExpansionSize=", &tail)) { 3032 julong long_CodeCacheExpansionSize = 0; 3033 ArgsRange errcode = parse_memory_size(tail, &long_CodeCacheExpansionSize, os::vm_page_size()); 3034 if (errcode != arg_in_range) { 3035 jio_fprintf(defaultStream::error_stream(), 3036 "Invalid argument: %s. Must be at least %luK.\n", option->optionString, 3037 os::vm_page_size() / K); 3038 return JNI_EINVAL; 3039 } 3040 FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx) long_CodeCacheExpansionSize); 3041 } else if (match_option(option, "-Xmaxjitcodesize", &tail) || 3042 match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) { 3043 julong long_ReservedCodeCacheSize = 0; 3044 3045 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1); 3046 if (errcode != arg_in_range) { 3047 jio_fprintf(defaultStream::error_stream(), 3048 "Invalid maximum code cache size: %s.\n", option->optionString); 3049 return JNI_EINVAL; 3050 } 3051 FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx) long_ReservedCodeCacheSize); 3052 // -XX:NonNMethodCodeHeapSize= 3053 } else if (match_option(option, "-XX:NonNMethodCodeHeapSize=", &tail)) { 3054 julong long_NonNMethodCodeHeapSize = 0; 3055 3056 ArgsRange errcode = parse_memory_size(tail, &long_NonNMethodCodeHeapSize, 1); 3057 if (errcode != arg_in_range) { 3058 jio_fprintf(defaultStream::error_stream(), 3059 "Invalid maximum non-nmethod code heap size: %s.\n", option->optionString); 3060 return JNI_EINVAL; 3061 } 3062 FLAG_SET_CMDLINE(uintx, NonNMethodCodeHeapSize, (uintx) long_NonNMethodCodeHeapSize); 3063 // -XX:ProfiledCodeHeapSize= 3064 } else if (match_option(option, "-XX:ProfiledCodeHeapSize=", &tail)) { 3065 julong long_ProfiledCodeHeapSize = 0; 3066 3067 ArgsRange errcode = parse_memory_size(tail, &long_ProfiledCodeHeapSize, 1); 3068 if (errcode != arg_in_range) { 3069 jio_fprintf(defaultStream::error_stream(), 3070 "Invalid maximum profiled code heap size: %s.\n", option->optionString); 3071 return JNI_EINVAL; 3072 } 3073 FLAG_SET_CMDLINE(uintx, ProfiledCodeHeapSize, (uintx) long_ProfiledCodeHeapSize); 3074 // -XX:NonProfiledCodeHeapSizee= 3075 } else if (match_option(option, "-XX:NonProfiledCodeHeapSize=", &tail)) { 3076 julong long_NonProfiledCodeHeapSize = 0; 3077 3078 ArgsRange errcode = parse_memory_size(tail, &long_NonProfiledCodeHeapSize, 1); 3079 if (errcode != arg_in_range) { 3080 jio_fprintf(defaultStream::error_stream(), 3081 "Invalid maximum non-profiled code heap size: %s.\n", option->optionString); 3082 return JNI_EINVAL; 3083 } 3084 FLAG_SET_CMDLINE(uintx, NonProfiledCodeHeapSize, (uintx) long_NonProfiledCodeHeapSize); 3085 //-XX:IncreaseFirstTierCompileThresholdAt= 3086 } else if (match_option(option, "-XX:IncreaseFirstTierCompileThresholdAt=", &tail)) { 3087 uintx uint_IncreaseFirstTierCompileThresholdAt = 0; 3088 if (!parse_uintx(tail, &uint_IncreaseFirstTierCompileThresholdAt, 0) || uint_IncreaseFirstTierCompileThresholdAt > 99) { 3089 jio_fprintf(defaultStream::error_stream(), 3090 "Invalid value for IncreaseFirstTierCompileThresholdAt: %s. Should be between 0 and 99.\n", 3091 option->optionString); 3092 return JNI_EINVAL; 3093 } 3094 FLAG_SET_CMDLINE(uintx, IncreaseFirstTierCompileThresholdAt, (uintx) uint_IncreaseFirstTierCompileThresholdAt); 3095 // -green 3096 } else if (match_option(option, "-green")) { 3097 jio_fprintf(defaultStream::error_stream(), 3098 "Green threads support not available\n"); 3099 return JNI_EINVAL; 3100 // -native 3101 } else if (match_option(option, "-native")) { 3102 // HotSpot always uses native threads, ignore silently for compatibility 3103 // -Xsqnopause 3104 } else if (match_option(option, "-Xsqnopause")) { 3105 // EVM option, ignore silently for compatibility 3106 // -Xrs 3107 } else if (match_option(option, "-Xrs")) { 3108 // Classic/EVM option, new functionality 3109 FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true); 3110 } else if (match_option(option, "-Xusealtsigs")) { 3111 // change default internal VM signals used - lower case for back compat 3112 FLAG_SET_CMDLINE(bool, UseAltSigs, true); 3113 // -Xoptimize 3114 } else if (match_option(option, "-Xoptimize")) { 3115 // EVM option, ignore silently for compatibility 3116 // -Xprof 3117 } else if (match_option(option, "-Xprof")) { 3118 #if INCLUDE_FPROF 3119 _has_profile = true; 3120 #else // INCLUDE_FPROF 3121 jio_fprintf(defaultStream::error_stream(), 3122 "Flat profiling is not supported in this VM.\n"); 3123 return JNI_ERR; 3124 #endif // INCLUDE_FPROF 3125 // -Xconcurrentio 3126 } else if (match_option(option, "-Xconcurrentio")) { 3127 FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true); 3128 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); 3129 FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1); 3130 FLAG_SET_CMDLINE(bool, UseTLAB, false); 3131 FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K); // 20Kb per thread added to new generation 3132 3133 // -Xinternalversion 3134 } else if (match_option(option, "-Xinternalversion")) { 3135 jio_fprintf(defaultStream::output_stream(), "%s\n", 3136 VM_Version::internal_vm_info_string()); 3137 vm_exit(0); 3138 #ifndef PRODUCT 3139 // -Xprintflags 3140 } else if (match_option(option, "-Xprintflags")) { 3141 CommandLineFlags::printFlags(tty, false); 3142 vm_exit(0); 3143 #endif 3144 // -D 3145 } else if (match_option(option, "-D", &tail)) { 3146 const char* value; 3147 if (match_option(option, "-Djava.endorsed.dirs=", &value) && 3148 *value != '\0' && strcmp(value, "\"\"") != 0) { 3149 // abort if -Djava.endorsed.dirs is set 3150 jio_fprintf(defaultStream::output_stream(), 3151 "-Djava.endorsed.dirs=%s is not supported. Endorsed standards and standalone APIs\n" 3152 "in modular form will be supported via the concept of upgradeable modules.\n", value); 3153 return JNI_EINVAL; 3154 } 3155 if (match_option(option, "-Djava.ext.dirs=", &value) && 3156 *value != '\0' && strcmp(value, "\"\"") != 0) { 3157 // abort if -Djava.ext.dirs is set 3158 jio_fprintf(defaultStream::output_stream(), 3159 "-Djava.ext.dirs=%s is not supported. Use -classpath instead.\n", value); 3160 return JNI_EINVAL; 3161 } 3162 3163 if (!add_property(tail)) { 3164 return JNI_ENOMEM; 3165 } 3166 // Out of the box management support 3167 if (match_option(option, "-Dcom.sun.management", &tail)) { 3168 #if INCLUDE_MANAGEMENT 3169 FLAG_SET_CMDLINE(bool, ManagementServer, true); 3170 #else 3171 jio_fprintf(defaultStream::output_stream(), 3172 "-Dcom.sun.management is not supported in this VM.\n"); 3173 return JNI_ERR; 3174 #endif 3175 } 3176 // -Xint 3177 } else if (match_option(option, "-Xint")) { 3178 set_mode_flags(_int); 3179 // -Xmixed 3180 } else if (match_option(option, "-Xmixed")) { 3181 set_mode_flags(_mixed); 3182 // -Xcomp 3183 } else if (match_option(option, "-Xcomp")) { 3184 // for testing the compiler; turn off all flags that inhibit compilation 3185 set_mode_flags(_comp); 3186 // -Xshare:dump 3187 } else if (match_option(option, "-Xshare:dump")) { 3188 FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true); 3189 set_mode_flags(_int); // Prevent compilation, which creates objects 3190 // -Xshare:on 3191 } else if (match_option(option, "-Xshare:on")) { 3192 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); 3193 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true); 3194 // -Xshare:auto 3195 } else if (match_option(option, "-Xshare:auto")) { 3196 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); 3197 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false); 3198 // -Xshare:off 3199 } else if (match_option(option, "-Xshare:off")) { 3200 FLAG_SET_CMDLINE(bool, UseSharedSpaces, false); 3201 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false); 3202 // -Xverify 3203 } else if (match_option(option, "-Xverify", &tail)) { 3204 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) { 3205 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true); 3206 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true); 3207 } else if (strcmp(tail, ":remote") == 0) { 3208 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false); 3209 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true); 3210 } else if (strcmp(tail, ":none") == 0) { 3211 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false); 3212 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false); 3213 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) { 3214 return JNI_EINVAL; 3215 } 3216 // -Xdebug 3217 } else if (match_option(option, "-Xdebug")) { 3218 // note this flag has been used, then ignore 3219 set_xdebug_mode(true); 3220 // -Xnoagent 3221 } else if (match_option(option, "-Xnoagent")) { 3222 // For compatibility with classic. HotSpot refuses to load the old style agent.dll. 3223 } else if (match_option(option, "-Xboundthreads")) { 3224 // Bind user level threads to kernel threads (Solaris only) 3225 FLAG_SET_CMDLINE(bool, UseBoundThreads, true); 3226 } else if (match_option(option, "-Xloggc:", &tail)) { 3227 // Redirect GC output to the file. -Xloggc:<filename> 3228 // ostream_init_log(), when called will use this filename 3229 // to initialize a fileStream. 3230 _gc_log_filename = os::strdup_check_oom(tail); 3231 if (!is_filename_valid(_gc_log_filename)) { 3232 jio_fprintf(defaultStream::output_stream(), 3233 "Invalid file name for use with -Xloggc: Filename can only contain the " 3234 "characters [A-Z][a-z][0-9]-_.%%[p|t] but it has been %s\n" 3235 "Note %%p or %%t can only be used once\n", _gc_log_filename); 3236 return JNI_EINVAL; 3237 } 3238 FLAG_SET_CMDLINE(bool, PrintGC, true); 3239 FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true); 3240 3241 // JNI hooks 3242 } else if (match_option(option, "-Xcheck", &tail)) { 3243 if (!strcmp(tail, ":jni")) { 3244 #if !INCLUDE_JNI_CHECK 3245 warning("JNI CHECKING is not supported in this VM"); 3246 #else 3247 CheckJNICalls = true; 3248 #endif // INCLUDE_JNI_CHECK 3249 } else if (is_bad_option(option, args->ignoreUnrecognized, 3250 "check")) { 3251 return JNI_EINVAL; 3252 } 3253 } else if (match_option(option, "vfprintf")) { 3254 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo); 3255 } else if (match_option(option, "exit")) { 3256 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo); 3257 } else if (match_option(option, "abort")) { 3258 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo); 3259 // -XX:+AggressiveHeap 3260 } else if (match_option(option, "-XX:+AggressiveHeap")) { 3261 3262 // This option inspects the machine and attempts to set various 3263 // parameters to be optimal for long-running, memory allocation 3264 // intensive jobs. It is intended for machines with large 3265 // amounts of cpu and memory. 3266 3267 // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit 3268 // VM, but we may not be able to represent the total physical memory 3269 // available (like having 8gb of memory on a box but using a 32bit VM). 3270 // Thus, we need to make sure we're using a julong for intermediate 3271 // calculations. 3272 julong initHeapSize; 3273 julong total_memory = os::physical_memory(); 3274 3275 if (total_memory < (julong) 256 * M) { 3276 jio_fprintf(defaultStream::error_stream(), 3277 "You need at least 256mb of memory to use -XX:+AggressiveHeap\n"); 3278 vm_exit(1); 3279 } 3280 3281 // The heap size is half of available memory, or (at most) 3282 // all of possible memory less 160mb (leaving room for the OS 3283 // when using ISM). This is the maximum; because adaptive sizing 3284 // is turned on below, the actual space used may be smaller. 3285 3286 initHeapSize = MIN2(total_memory / (julong) 2, 3287 total_memory - (julong) 160 * M); 3288 3289 initHeapSize = limit_by_allocatable_memory(initHeapSize); 3290 3291 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 3292 FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize); 3293 FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize); 3294 // Currently the minimum size and the initial heap sizes are the same. 3295 set_min_heap_size(initHeapSize); 3296 } 3297 if (FLAG_IS_DEFAULT(NewSize)) { 3298 // Make the young generation 3/8ths of the total heap. 3299 FLAG_SET_CMDLINE(uintx, NewSize, 3300 ((julong) MaxHeapSize / (julong) 8) * (julong) 3); 3301 FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize); 3302 } 3303 3304 #ifndef _ALLBSD_SOURCE // UseLargePages is not yet supported on BSD. 3305 FLAG_SET_DEFAULT(UseLargePages, true); 3306 #endif 3307 3308 // Increase some data structure sizes for efficiency 3309 FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize); 3310 FLAG_SET_CMDLINE(bool, ResizeTLAB, false); 3311 FLAG_SET_CMDLINE(uintx, TLABSize, 256 * K); 3312 3313 // See the OldPLABSize comment below, but replace 'after promotion' 3314 // with 'after copying'. YoungPLABSize is the size of the survivor 3315 // space per-gc-thread buffers. The default is 4kw. 3316 FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256 * K); // Note: this is in words 3317 3318 // OldPLABSize is the size of the buffers in the old gen that 3319 // UseParallelGC uses to promote live data that doesn't fit in the 3320 // survivor spaces. At any given time, there's one for each gc thread. 3321 // The default size is 1kw. These buffers are rarely used, since the 3322 // survivor spaces are usually big enough. For specjbb, however, there 3323 // are occasions when there's lots of live data in the young gen 3324 // and we end up promoting some of it. We don't have a definite 3325 // explanation for why bumping OldPLABSize helps, but the theory 3326 // is that a bigger PLAB results in retaining something like the 3327 // original allocation order after promotion, which improves mutator 3328 // locality. A minor effect may be that larger PLABs reduce the 3329 // number of PLAB allocation events during gc. The value of 8kw 3330 // was arrived at by experimenting with specjbb. 3331 FLAG_SET_CMDLINE(uintx, OldPLABSize, 8 * K); // Note: this is in words 3332 3333 // Enable parallel GC and adaptive generation sizing 3334 FLAG_SET_CMDLINE(bool, UseParallelGC, true); 3335 FLAG_SET_DEFAULT(ParallelGCThreads, 3336 Abstract_VM_Version::parallel_worker_threads()); 3337 3338 // Encourage steady state memory management 3339 FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100); 3340 3341 // This appears to improve mutator locality 3342 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false); 3343 3344 // Get around early Solaris scheduling bug 3345 // (affinity vs other jobs on system) 3346 // but disallow DR and offlining (5008695). 3347 FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true); 3348 3349 // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure; 3350 // and the last option wins. 3351 } else if (match_option(option, "-XX:+NeverTenure")) { 3352 FLAG_SET_CMDLINE(bool, NeverTenure, true); 3353 FLAG_SET_CMDLINE(bool, AlwaysTenure, false); 3354 FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1); 3355 } else if (match_option(option, "-XX:+AlwaysTenure")) { 3356 FLAG_SET_CMDLINE(bool, NeverTenure, false); 3357 FLAG_SET_CMDLINE(bool, AlwaysTenure, true); 3358 FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0); 3359 } else if (match_option(option, "-XX:MaxTenuringThreshold=", &tail)) { 3360 uintx max_tenuring_thresh = 0; 3361 if (!parse_uintx(tail, &max_tenuring_thresh, 0)) { 3362 jio_fprintf(defaultStream::error_stream(), 3363 "Invalid MaxTenuringThreshold: %s\n", option->optionString); 3364 } 3365 FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, max_tenuring_thresh); 3366 3367 if (MaxTenuringThreshold == 0) { 3368 FLAG_SET_CMDLINE(bool, NeverTenure, false); 3369 FLAG_SET_CMDLINE(bool, AlwaysTenure, true); 3370 } else { 3371 FLAG_SET_CMDLINE(bool, NeverTenure, false); 3372 FLAG_SET_CMDLINE(bool, AlwaysTenure, false); 3373 } 3374 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr")) { 3375 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false); 3376 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true); 3377 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout")) { 3378 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false); 3379 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true); 3380 } else if (match_option(option, "-XX:+ExtendedDTraceProbes")) { 3381 #if defined(DTRACE_ENABLED) 3382 FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true); 3383 FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true); 3384 FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true); 3385 FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true); 3386 #else // defined(DTRACE_ENABLED) 3387 jio_fprintf(defaultStream::error_stream(), 3388 "ExtendedDTraceProbes flag is not applicable for this configuration\n"); 3389 return JNI_EINVAL; 3390 #endif // defined(DTRACE_ENABLED) 3391 #ifdef ASSERT 3392 } else if (match_option(option, "-XX:+FullGCALot")) { 3393 FLAG_SET_CMDLINE(bool, FullGCALot, true); 3394 // disable scavenge before parallel mark-compact 3395 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false); 3396 #endif 3397 } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) { 3398 julong max_direct_memory_size = 0; 3399 ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0); 3400 if (errcode != arg_in_range) { 3401 jio_fprintf(defaultStream::error_stream(), 3402 "Invalid maximum direct memory size: %s\n", 3403 option->optionString); 3404 describe_range_error(errcode); 3405 return JNI_EINVAL; 3406 } 3407 FLAG_SET_CMDLINE(uintx, MaxDirectMemorySize, max_direct_memory_size); 3408 #if !INCLUDE_MANAGEMENT 3409 } else if (match_option(option, "-XX:+ManagementServer")) { 3410 jio_fprintf(defaultStream::error_stream(), 3411 "ManagementServer is not supported in this VM.\n"); 3412 return JNI_ERR; 3413 #endif // INCLUDE_MANAGEMENT 3414 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 3415 // Skip -XX:Flags= since that case has already been handled 3416 if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) { 3417 if (!process_argument(tail, args->ignoreUnrecognized, origin)) { 3418 return JNI_EINVAL; 3419 } 3420 } 3421 // Unknown option 3422 } else if (is_bad_option(option, args->ignoreUnrecognized)) { 3423 return JNI_ERR; 3424 } 3425 } 3426 3427 // PrintSharedArchiveAndExit will turn on 3428 // -Xshare:on 3429 // -XX:+TraceClassPaths 3430 if (PrintSharedArchiveAndExit) { 3431 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); 3432 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true); 3433 FLAG_SET_CMDLINE(bool, TraceClassPaths, true); 3434 } 3435 3436 // Change the default value for flags which have different default values 3437 // when working with older JDKs. 3438 #ifdef LINUX 3439 if (JDK_Version::current().compare_major(6) <= 0 && 3440 FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) { 3441 FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false); 3442 } 3443 #endif // LINUX 3444 fix_appclasspath(); 3445 return JNI_OK; 3446 } 3447 3448 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled) 3449 // 3450 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar 3451 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar". 3452 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty 3453 // path is treated as the current directory. 3454 // 3455 // This causes problems with CDS, which requires that all directories specified in the classpath 3456 // must be empty. In most cases, applications do NOT want to load classes from the current 3457 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up 3458 // scripts compatible with CDS. 3459 3460 void Arguments::fix_appclasspath() { 3461 if (IgnoreEmptyClassPaths) { 3462 const char separator = *os::path_separator(); 3463 const char* src = _java_class_path->value(); 3464 3465 // skip over all the leading empty paths 3466 while (*src == separator) { 3467 src++; 3468 } 3469 3470 char* copy = AllocateHeap(strlen(src) + 1, mtInternal); 3471 strncpy(copy, src, strlen(src) + 1); 3472 3473 // trim all trailing empty paths 3474 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) { 3475 *tail = '\0'; 3476 } 3477 3478 char from[3] = {separator, separator, '\0'}; 3479 char to [2] = {separator, '\0'}; 3480 while (StringUtils::replace_no_expand(copy, from, to) > 0) { 3481 // Keep replacing "::" -> ":" until we have no more "::" (non-windows) 3482 // Keep replacing ";;" -> ";" until we have no more ";;" (windows) 3483 } 3484 3485 _java_class_path->set_value(copy); 3486 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore 3487 } 3488 3489 if (!PrintSharedArchiveAndExit) { 3490 ClassLoader::trace_class_path("[classpath: ", _java_class_path->value()); 3491 } 3492 } 3493 3494 static bool has_jar_files(const char* directory) { 3495 DIR* dir = os::opendir(directory); 3496 if (dir == NULL) return false; 3497 3498 struct dirent *entry; 3499 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal); 3500 bool hasJarFile = false; 3501 while (!hasJarFile && (entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { 3502 const char* name = entry->d_name; 3503 const char* ext = name + strlen(name) - 4; 3504 hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0); 3505 } 3506 FREE_C_HEAP_ARRAY(char, dbuf); 3507 os::closedir(dir); 3508 return hasJarFile; 3509 } 3510 3511 static int check_non_empty_dirs(const char* path) { 3512 const char separator = *os::path_separator(); 3513 const char* const end = path + strlen(path); 3514 int nonEmptyDirs = 0; 3515 while (path < end) { 3516 const char* tmp_end = strchr(path, separator); 3517 if (tmp_end == NULL) { 3518 if (has_jar_files(path)) { 3519 nonEmptyDirs++; 3520 jio_fprintf(defaultStream::output_stream(), 3521 "Non-empty directory: %s\n", path); 3522 } 3523 path = end; 3524 } else { 3525 char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtInternal); 3526 memcpy(dirpath, path, tmp_end - path); 3527 dirpath[tmp_end - path] = '\0'; 3528 if (has_jar_files(dirpath)) { 3529 nonEmptyDirs++; 3530 jio_fprintf(defaultStream::output_stream(), 3531 "Non-empty directory: %s\n", dirpath); 3532 } 3533 FREE_C_HEAP_ARRAY(char, dirpath); 3534 path = tmp_end + 1; 3535 } 3536 } 3537 return nonEmptyDirs; 3538 } 3539 3540 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) { 3541 // check if the default lib/endorsed directory exists; if so, error 3542 char path[JVM_MAXPATHLEN]; 3543 const char* fileSep = os::file_separator(); 3544 sprintf(path, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep); 3545 3546 if (CheckEndorsedAndExtDirs) { 3547 int nonEmptyDirs = 0; 3548 // check endorsed directory 3549 nonEmptyDirs += check_non_empty_dirs(path); 3550 // check the extension directories 3551 nonEmptyDirs += check_non_empty_dirs(Arguments::get_ext_dirs()); 3552 if (nonEmptyDirs > 0) { 3553 return JNI_ERR; 3554 } 3555 } 3556 3557 DIR* dir = os::opendir(path); 3558 if (dir != NULL) { 3559 jio_fprintf(defaultStream::output_stream(), 3560 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n" 3561 "in modular form will be supported via the concept of upgradeable modules.\n"); 3562 os::closedir(dir); 3563 return JNI_ERR; 3564 } 3565 3566 sprintf(path, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep); 3567 dir = os::opendir(path); 3568 if (dir != NULL) { 3569 jio_fprintf(defaultStream::output_stream(), 3570 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; " 3571 "Use -classpath instead.\n."); 3572 os::closedir(dir); 3573 return JNI_ERR; 3574 } 3575 3576 if (scp_assembly_required) { 3577 // Assemble the bootclasspath elements into the final path. 3578 Arguments::set_sysclasspath(scp_p->combined_path()); 3579 } 3580 3581 // This must be done after all arguments have been processed. 3582 // java_compiler() true means set to "NONE" or empty. 3583 if (java_compiler() && !xdebug_mode()) { 3584 // For backwards compatibility, we switch to interpreted mode if 3585 // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was 3586 // not specified. 3587 set_mode_flags(_int); 3588 } 3589 3590 if ((TieredCompilation && CompileThresholdScaling == 0) 3591 || (!TieredCompilation && get_scaled_compile_threshold(CompileThreshold) == 0)) { 3592 set_mode_flags(_int); 3593 } 3594 3595 // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set 3596 if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) { 3597 FLAG_SET_ERGO(uintx, InitialTenuringThreshold, MaxTenuringThreshold); 3598 } 3599 3600 #ifndef COMPILER2 3601 // Don't degrade server performance for footprint 3602 if (FLAG_IS_DEFAULT(UseLargePages) && 3603 MaxHeapSize < LargePageHeapSizeThreshold) { 3604 // No need for large granularity pages w/small heaps. 3605 // Note that large pages are enabled/disabled for both the 3606 // Java heap and the code cache. 3607 FLAG_SET_DEFAULT(UseLargePages, false); 3608 } 3609 3610 #else 3611 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) { 3612 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment - 1); 3613 } 3614 #endif 3615 3616 #ifndef TIERED 3617 // Tiered compilation is undefined. 3618 UNSUPPORTED_OPTION(TieredCompilation, "TieredCompilation"); 3619 #endif 3620 3621 // If we are running in a headless jre, force java.awt.headless property 3622 // to be true unless the property has already been set. 3623 // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state. 3624 if (os::is_headless_jre()) { 3625 const char* headless = Arguments::get_property("java.awt.headless"); 3626 if (headless == NULL) { 3627 char envbuffer[128]; 3628 if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof (envbuffer))) { 3629 if (!add_property("java.awt.headless=true")) { 3630 return JNI_ENOMEM; 3631 } 3632 } else { 3633 char buffer[256]; 3634 strcpy(buffer, "java.awt.headless="); 3635 strcat(buffer, envbuffer); 3636 if (!add_property(buffer)) { 3637 return JNI_ENOMEM; 3638 } 3639 } 3640 } 3641 } 3642 3643 if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) { 3644 // CMS can only be used with ParNew 3645 FLAG_SET_ERGO(bool, UseParNewGC, true); 3646 } 3647 3648 if (!check_vm_args_consistency()) { 3649 return JNI_ERR; 3650 } 3651 3652 return JNI_OK; 3653 } 3654 3655 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) { 3656 return parse_options_environment_variable("_JAVA_OPTIONS", scp_p, 3657 scp_assembly_required_p); 3658 } 3659 3660 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) { 3661 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p, 3662 scp_assembly_required_p); 3663 } 3664 3665 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) { 3666 const int N_MAX_OPTIONS = 64; 3667 const int OPTION_BUFFER_SIZE = 1024; 3668 char buffer[OPTION_BUFFER_SIZE]; 3669 3670 // The variable will be ignored if it exceeds the length of the buffer. 3671 // Don't check this variable if user has special privileges 3672 // (e.g. unix su command). 3673 if (os::getenv(name, buffer, sizeof (buffer)) && 3674 !os::have_special_privileges()) { 3675 JavaVMOption options[N_MAX_OPTIONS]; // Construct option array 3676 jio_fprintf(defaultStream::error_stream(), 3677 "Picked up %s: %s\n", name, buffer); 3678 char* rd = buffer; // pointer to the input string (rd) 3679 int i; 3680 for (i = 0; i < N_MAX_OPTIONS;) { // repeat for all options in the input string 3681 while (isspace(*rd)) rd++; // skip whitespace 3682 if (*rd == 0) break; // we re done when the input string is read completely 3683 3684 // The output, option string, overwrites the input string. 3685 // Because of quoting, the pointer to the option string (wrt) may lag the pointer to 3686 // input string (rd). 3687 char* wrt = rd; 3688 3689 options[i++].optionString = wrt; // Fill in option 3690 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL 3691 if (*rd == '\'' || *rd == '"') { // handle a quoted string 3692 int quote = *rd; // matching quote to look for 3693 rd++; // don't copy open quote 3694 while (*rd != quote) { // include everything (even spaces) up until quote 3695 if (*rd == 0) { // string termination means unmatched string 3696 jio_fprintf(defaultStream::error_stream(), 3697 "Unmatched quote in %s\n", name); 3698 return JNI_ERR; 3699 } 3700 *wrt++ = *rd++; // copy to option string 3701 } 3702 rd++; // don't copy close quote 3703 } else { 3704 *wrt++ = *rd++; // copy to option string 3705 } 3706 } 3707 // Need to check if we're done before writing a NULL, 3708 // because the write could be to the byte that rd is pointing to. 3709 if (*rd++ == 0) { 3710 *wrt = 0; 3711 break; 3712 } 3713 *wrt = 0; // Zero terminate option 3714 } 3715 // Construct JavaVMInitArgs structure and parse as if it was part of the command line 3716 JavaVMInitArgs vm_args; 3717 vm_args.version = JNI_VERSION_1_2; 3718 vm_args.options = options; 3719 vm_args.nOptions = i; 3720 vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; 3721 3722 if (PrintVMOptions) { 3723 const char* tail; 3724 for (int i = 0; i < vm_args.nOptions; i++) { 3725 const JavaVMOption *option = vm_args.options + i; 3726 if (match_option(option, "-XX:", &tail)) { 3727 logOption(tail); 3728 } 3729 } 3730 } 3731 3732 return (parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, Flag::ENVIRON_VAR)); 3733 } 3734 return JNI_OK; 3735 } 3736 3737 void Arguments::set_shared_spaces_flags() { 3738 if (DumpSharedSpaces) { 3739 if (RequireSharedSpaces) { 3740 warning("cannot dump shared archive while using shared archive"); 3741 } 3742 UseSharedSpaces = false; 3743 #ifdef _LP64 3744 if (!UseCompressedOops || !UseCompressedClassPointers) { 3745 vm_exit_during_initialization( 3746 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); 3747 } 3748 } else { 3749 if (!UseCompressedOops || !UseCompressedClassPointers) { 3750 no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces."); 3751 } 3752 #endif 3753 } 3754 } 3755 3756 #if !INCLUDE_ALL_GCS 3757 3758 static void force_serial_gc() { 3759 FLAG_SET_DEFAULT(UseSerialGC, true); 3760 UNSUPPORTED_GC_OPTION(UseG1GC); 3761 UNSUPPORTED_GC_OPTION(UseParallelGC); 3762 UNSUPPORTED_GC_OPTION(UseParallelOldGC); 3763 UNSUPPORTED_GC_OPTION(UseConcMarkSweepGC); 3764 UNSUPPORTED_GC_OPTION(UseParNewGC); 3765 } 3766 #endif // INCLUDE_ALL_GCS 3767 3768 // Sharing support 3769 // Construct the path to the archive 3770 3771 static char* get_shared_archive_path() { 3772 char *shared_archive_path; 3773 if (SharedArchiveFile == NULL) { 3774 char jvm_path[JVM_MAXPATHLEN]; 3775 os::jvm_path(jvm_path, sizeof (jvm_path)); 3776 char *end = strrchr(jvm_path, *os::file_separator()); 3777 if (end != NULL) *end = '\0'; 3778 size_t jvm_path_len = strlen(jvm_path); 3779 size_t file_sep_len = strlen(os::file_separator()); 3780 shared_archive_path = NEW_C_HEAP_ARRAY(char, jvm_path_len + 3781 file_sep_len + 20, mtInternal); 3782 if (shared_archive_path != NULL) { 3783 strncpy(shared_archive_path, jvm_path, jvm_path_len + 1); 3784 strncat(shared_archive_path, os::file_separator(), file_sep_len); 3785 strncat(shared_archive_path, "classes.jsa", 11); 3786 } 3787 } else { 3788 shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(SharedArchiveFile) + 1, mtInternal); 3789 if (shared_archive_path != NULL) { 3790 strncpy(shared_archive_path, SharedArchiveFile, strlen(SharedArchiveFile) + 1); 3791 } 3792 } 3793 return shared_archive_path; 3794 } 3795 3796 #ifndef PRODUCT 3797 // Determine whether LogVMOutput should be implicitly turned on. 3798 3799 static bool use_vm_log() { 3800 if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) || 3801 PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods || 3802 PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers || 3803 PrintAssembly || TraceDeoptimization || TraceDependencies || 3804 (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) { 3805 return true; 3806 } 3807 3808 #ifdef COMPILER1 3809 if (PrintC1Statistics) { 3810 return true; 3811 } 3812 #endif // COMPILER1 3813 3814 #ifdef COMPILER2 3815 if (PrintOptoAssembly || PrintOptoStatistics) { 3816 return true; 3817 } 3818 #endif // COMPILER2 3819 3820 return false; 3821 } 3822 #endif // PRODUCT 3823 3824 // Parse entry point called from JNI_CreateJavaVM 3825 3826 jint Arguments::parse(const JavaVMInitArgs* args) { 3827 3828 // Remaining part of option string 3829 const char* tail; 3830 3831 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. 3832 const char* hotspotrc = ".hotspotrc"; 3833 bool settings_file_specified = false; 3834 bool needs_hotspotrc_warning = false; 3835 3836 const char* flags_file; 3837 int index; 3838 for (index = 0; index < args->nOptions; index++) { 3839 const JavaVMOption *option = args->options + index; 3840 if (ArgumentsExt::process_options(option)) { 3841 continue; 3842 } 3843 if (match_option(option, "-XX:Flags=", &tail)) { 3844 flags_file = tail; 3845 settings_file_specified = true; 3846 continue; 3847 } 3848 if (match_option(option, "-XX:+PrintVMOptions")) { 3849 PrintVMOptions = true; 3850 continue; 3851 } 3852 if (match_option(option, "-XX:-PrintVMOptions")) { 3853 PrintVMOptions = false; 3854 continue; 3855 } 3856 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) { 3857 IgnoreUnrecognizedVMOptions = true; 3858 continue; 3859 } 3860 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) { 3861 IgnoreUnrecognizedVMOptions = false; 3862 continue; 3863 } 3864 if (match_option(option, "-XX:+PrintFlagsInitial")) { 3865 CommandLineFlags::printFlags(tty, false); 3866 vm_exit(0); 3867 } 3868 #if INCLUDE_NMT 3869 if (match_option(option, "-XX:NativeMemoryTracking", &tail)) { 3870 // The launcher did not setup nmt environment variable properly. 3871 if (!MemTracker::check_launcher_nmt_support(tail)) { 3872 warning("Native Memory Tracking did not setup properly, using wrong launcher?"); 3873 } 3874 3875 // Verify if nmt option is valid. 3876 if (MemTracker::verify_nmt_option()) { 3877 // Late initialization, still in single-threaded mode. 3878 if (MemTracker::tracking_level() >= NMT_summary) { 3879 MemTracker::init(); 3880 } 3881 } else { 3882 vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL); 3883 } 3884 continue; 3885 } 3886 #endif 3887 3888 3889 #ifndef PRODUCT 3890 if (match_option(option, "-XX:+PrintFlagsWithComments")) { 3891 CommandLineFlags::printFlags(tty, true); 3892 vm_exit(0); 3893 } 3894 #endif 3895 } 3896 3897 if (IgnoreUnrecognizedVMOptions) { 3898 // uncast const to modify the flag args->ignoreUnrecognized 3899 *(jboolean*) (&args->ignoreUnrecognized) = true; 3900 } 3901 3902 // Parse specified settings file 3903 if (settings_file_specified) { 3904 if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) { 3905 return JNI_EINVAL; 3906 } 3907 } else { 3908 #ifdef ASSERT 3909 // Parse default .hotspotrc settings file 3910 if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) { 3911 return JNI_EINVAL; 3912 } 3913 #else 3914 struct stat buf; 3915 if (os::stat(hotspotrc, &buf) == 0) { 3916 needs_hotspotrc_warning = true; 3917 } 3918 #endif 3919 } 3920 3921 if (PrintVMOptions) { 3922 for (index = 0; index < args->nOptions; index++) { 3923 const JavaVMOption *option = args->options + index; 3924 if (match_option(option, "-XX:", &tail)) { 3925 logOption(tail); 3926 } 3927 } 3928 } 3929 3930 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS 3931 jint result = parse_vm_init_args(args); 3932 if (result != JNI_OK) { 3933 return result; 3934 } 3935 3936 // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed. 3937 SharedArchivePath = get_shared_archive_path(); 3938 if (SharedArchivePath == NULL) { 3939 return JNI_ENOMEM; 3940 } 3941 3942 // Set up VerifySharedSpaces 3943 if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) { 3944 VerifySharedSpaces = true; 3945 } 3946 3947 // Delay warning until here so that we've had a chance to process 3948 // the -XX:-PrintWarnings flag 3949 if (needs_hotspotrc_warning) { 3950 warning("%s file is present but has been ignored. " 3951 "Run with -XX:Flags=%s to load the file.", 3952 hotspotrc, hotspotrc); 3953 } 3954 3955 #ifdef _ALLBSD_SOURCE // UseLargePages is not yet supported on BSD. 3956 UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages"); 3957 #endif 3958 3959 #if INCLUDE_ALL_GCS 3960 #if (defined JAVASE_EMBEDDED || defined ARM) 3961 UNSUPPORTED_OPTION(UseG1GC, "G1 GC"); 3962 #endif 3963 #endif 3964 3965 #ifndef PRODUCT 3966 if (TraceBytecodesAt != 0) { 3967 TraceBytecodes = true; 3968 } 3969 if (CountCompiledCalls) { 3970 if (UseCounterDecay) { 3971 warning("UseCounterDecay disabled because CountCalls is set"); 3972 UseCounterDecay = false; 3973 } 3974 } 3975 #endif // PRODUCT 3976 3977 if (ScavengeRootsInCode == 0) { 3978 if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) { 3979 warning("forcing ScavengeRootsInCode non-zero"); 3980 } 3981 ScavengeRootsInCode = 1; 3982 } 3983 3984 if (PrintGCDetails) { 3985 // Turn on -verbose:gc options as well 3986 PrintGC = true; 3987 } 3988 3989 // Set object alignment values. 3990 set_object_alignment(); 3991 3992 #if !INCLUDE_ALL_GCS 3993 force_serial_gc(); 3994 #endif // INCLUDE_ALL_GCS 3995 #if !INCLUDE_CDS 3996 if (DumpSharedSpaces || RequireSharedSpaces) { 3997 jio_fprintf(defaultStream::error_stream(), 3998 "Shared spaces are not supported in this VM\n"); 3999 return JNI_ERR; 4000 } 4001 if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) { 4002 warning("Shared spaces are not supported in this VM"); 4003 FLAG_SET_DEFAULT(UseSharedSpaces, false); 4004 FLAG_SET_DEFAULT(PrintSharedSpaces, false); 4005 } 4006 no_shared_spaces("CDS Disabled"); 4007 #endif // INCLUDE_CDS 4008 4009 return JNI_OK; 4010 } 4011 4012 jint Arguments::apply_ergo() { 4013 4014 // Set flags based on ergonomics. 4015 set_ergonomics_flags(); 4016 4017 set_shared_spaces_flags(); 4018 4019 // Check the GC selections again. 4020 if (!ArgumentsExt::check_gc_consistency_ergo()) { 4021 return JNI_EINVAL; 4022 } 4023 4024 if (TieredCompilation) { 4025 set_tiered_flags(); 4026 } else { 4027 // Check if the policy is valid. Policies 0 and 1 are valid for non-tiered setup. 4028 if (CompilationPolicyChoice >= 2) { 4029 vm_exit_during_initialization( 4030 "Incompatible compilation policy selected", NULL); 4031 } 4032 // Scale CompileThreshold 4033 if (!FLAG_IS_DEFAULT(CompileThresholdScaling)) { 4034 FLAG_SET_ERGO(intx, CompileThreshold, get_scaled_compile_threshold(CompileThreshold)); 4035 } 4036 } 4037 4038 #ifdef COMPILER2 4039 #ifndef PRODUCT 4040 if (PrintIdealGraphLevel > 0) { 4041 FLAG_SET_ERGO(bool, PrintIdealGraph, true); 4042 } 4043 #endif 4044 #endif 4045 4046 // Set heap size based on available physical memory 4047 set_heap_size(); 4048 4049 ArgumentsExt::set_gc_specific_flags(); 4050 4051 // Initialize Metaspace flags and alignments 4052 Metaspace::ergo_initialize(); 4053 4054 // Set bytecode rewriting flags 4055 set_bytecode_flags(); 4056 4057 // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled 4058 set_aggressive_opts_flags(); 4059 4060 // Turn off biased locking for locking debug mode flags, 4061 // which are subtly different from each other but neither works with 4062 // biased locking 4063 if (UseHeavyMonitors 4064 #ifdef COMPILER1 4065 || !UseFastLocking 4066 #endif // COMPILER1 4067 ) { 4068 if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) { 4069 // flag set to true on command line; warn the user that they 4070 // can't enable biased locking here 4071 warning("Biased Locking is not supported with locking debug flags" 4072 "; ignoring UseBiasedLocking flag."); 4073 } 4074 UseBiasedLocking = false; 4075 } 4076 4077 #ifdef ZERO 4078 // Clear flags not supported on zero. 4079 FLAG_SET_DEFAULT(ProfileInterpreter, false); 4080 FLAG_SET_DEFAULT(UseBiasedLocking, false); 4081 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false)); 4082 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedClassPointers, false)); 4083 #endif // CC_INTERP 4084 4085 #ifdef COMPILER2 4086 if (!EliminateLocks) { 4087 EliminateNestedLocks = false; 4088 } 4089 if (!Inline) { 4090 IncrementalInline = false; 4091 } 4092 #ifndef PRODUCT 4093 if (!IncrementalInline) { 4094 AlwaysIncrementalInline = false; 4095 } 4096 #endif 4097 if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) { 4098 // nothing to use the profiling, turn if off 4099 FLAG_SET_DEFAULT(TypeProfileLevel, 0); 4100 } 4101 #endif 4102 4103 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) { 4104 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output"); 4105 DebugNonSafepoints = true; 4106 } 4107 4108 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) { 4109 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used"); 4110 } 4111 4112 #ifndef PRODUCT 4113 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) { 4114 if (use_vm_log()) { 4115 LogVMOutput = true; 4116 } 4117 } 4118 #endif // PRODUCT 4119 4120 if (PrintCommandLineFlags) { 4121 CommandLineFlags::printSetFlags(tty); 4122 } 4123 4124 // Apply CPU specific policy for the BiasedLocking 4125 if (UseBiasedLocking) { 4126 if (!VM_Version::use_biased_locking() && 4127 !(FLAG_IS_CMDLINE(UseBiasedLocking))) { 4128 UseBiasedLocking = false; 4129 } 4130 } 4131 #ifdef COMPILER2 4132 if (!UseBiasedLocking || EmitSync != 0) { 4133 UseOptoBiasInlining = false; 4134 } 4135 #endif 4136 4137 return JNI_OK; 4138 } 4139 4140 jint Arguments::adjust_after_os() { 4141 if (UseNUMA) { 4142 if (UseParallelGC || UseParallelOldGC) { 4143 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) { 4144 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64 * M); 4145 } 4146 } 4147 // UseNUMAInterleaving is set to ON for all collectors and 4148 // platforms when UseNUMA is set to ON. NUMA-aware collectors 4149 // such as the parallel collector for Linux and Solaris will 4150 // interleave old gen and survivor spaces on top of NUMA 4151 // allocation policy for the eden space. 4152 // Non NUMA-aware collectors such as CMS, G1 and Serial-GC on 4153 // all platforms and ParallelGC on Windows will interleave all 4154 // of the heap spaces across NUMA nodes. 4155 if (FLAG_IS_DEFAULT(UseNUMAInterleaving)) { 4156 FLAG_SET_ERGO(bool, UseNUMAInterleaving, true); 4157 } 4158 } 4159 return JNI_OK; 4160 } 4161 4162 int Arguments::PropertyList_count(SystemProperty* pl) { 4163 int count = 0; 4164 while (pl != NULL) { 4165 count++; 4166 pl = pl->next(); 4167 } 4168 return count; 4169 } 4170 4171 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) { 4172 assert(key != NULL, "just checking"); 4173 SystemProperty* prop; 4174 for (prop = pl; prop != NULL; prop = prop->next()) { 4175 if (strcmp(key, prop->key()) == 0) return prop->value(); 4176 } 4177 return NULL; 4178 } 4179 4180 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) { 4181 int count = 0; 4182 const char* ret_val = NULL; 4183 4184 while (pl != NULL) { 4185 if (count >= index) { 4186 ret_val = pl->key(); 4187 break; 4188 } 4189 count++; 4190 pl = pl->next(); 4191 } 4192 4193 return ret_val; 4194 } 4195 4196 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) { 4197 int count = 0; 4198 char* ret_val = NULL; 4199 4200 while (pl != NULL) { 4201 if (count >= index) { 4202 ret_val = pl->value(); 4203 break; 4204 } 4205 count++; 4206 pl = pl->next(); 4207 } 4208 4209 return ret_val; 4210 } 4211 4212 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) { 4213 SystemProperty* p = *plist; 4214 if (p == NULL) { 4215 *plist = new_p; 4216 } else { 4217 while (p->next() != NULL) { 4218 p = p->next(); 4219 } 4220 p->set_next(new_p); 4221 } 4222 } 4223 4224 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) { 4225 if (plist == NULL) 4226 return; 4227 4228 SystemProperty* new_p = new SystemProperty(k, v, true); 4229 PropertyList_add(plist, new_p); 4230 } 4231 4232 void Arguments::PropertyList_add(SystemProperty *element) { 4233 PropertyList_add(&_system_properties, element); 4234 } 4235 4236 // This add maintains unique property key in the list. 4237 4238 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append) { 4239 if (plist == NULL) 4240 return; 4241 4242 // If property key exist then update with new value. 4243 SystemProperty* prop; 4244 for (prop = *plist; prop != NULL; prop = prop->next()) { 4245 if (strcmp(k, prop->key()) == 0) { 4246 if (append) { 4247 prop->append_value(v); 4248 } else { 4249 prop->set_value(v); 4250 } 4251 return; 4252 } 4253 } 4254 4255 PropertyList_add(plist, k, v); 4256 } 4257 4258 // Copies src into buf, replacing "%%" with "%" and "%p" with pid 4259 // Returns true if all of the source pointed by src has been copied over to 4260 // the destination buffer pointed by buf. Otherwise, returns false. 4261 // Notes: 4262 // 1. If the length (buflen) of the destination buffer excluding the 4263 // NULL terminator character is not long enough for holding the expanded 4264 // pid characters, it also returns false instead of returning the partially 4265 // expanded one. 4266 // 2. The passed in "buflen" should be large enough to hold the null terminator. 4267 4268 bool Arguments::copy_expand_pid(const char* src, size_t srclen, 4269 char* buf, size_t buflen) { 4270 const char* p = src; 4271 char* b = buf; 4272 const char* src_end = &src[srclen]; 4273 char* buf_end = &buf[buflen - 1]; 4274 4275 while (p < src_end && b < buf_end) { 4276 if (*p == '%') { 4277 switch (*(++p)) { 4278 case '%': // "%%" ==> "%" 4279 *b++ = *p++; 4280 break; 4281 case 'p': 4282 { // "%p" ==> current process id 4283 // buf_end points to the character before the last character so 4284 // that we could write '\0' to the end of the buffer. 4285 size_t buf_sz = buf_end - b + 1; 4286 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id()); 4287 4288 // if jio_snprintf fails or the buffer is not long enough to hold 4289 // the expanded pid, returns false. 4290 if (ret < 0 || ret >= (int) buf_sz) { 4291 return false; 4292 } else { 4293 b += ret; 4294 assert(*b == '\0', "fail in copy_expand_pid"); 4295 if (p == src_end && b == buf_end + 1) { 4296 // reach the end of the buffer. 4297 return true; 4298 } 4299 } 4300 p++; 4301 break; 4302 } 4303 default: 4304 *b++ = '%'; 4305 } 4306 } else { 4307 *b++ = *p++; 4308 } 4309 } 4310 *b = '\0'; 4311 return (p == src_end); // return false if not all of the source was copied 4312 }