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