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