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