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