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 char* key; 989 // ns must be static--its address may be stored in a SystemProperty object. 990 const static char ns[1] = {0}; 991 char* value = (char *)ns; 992 993 size_t key_len = (eq == NULL) ? strlen(prop) : (eq - prop); 994 key = AllocateHeap(key_len + 1, mtInternal); 995 strncpy(key, prop, key_len); 996 key[key_len] = '\0'; 997 998 if (eq != NULL) { 999 size_t value_len = strlen(prop) - key_len - 1; 1000 value = AllocateHeap(value_len + 1, mtInternal); 1001 strncpy(value, &prop[key_len + 1], value_len + 1); 1002 } 1003 1004 if (strcmp(key, "java.compiler") == 0) { 1005 process_java_compiler_argument(value); 1006 FreeHeap(key); 1007 if (eq != NULL) { 1008 FreeHeap(value); 1009 } 1010 return true; 1011 } else if (strcmp(key, "sun.java.command") == 0) { 1012 _java_command = value; 1013 1014 // Record value in Arguments, but let it get passed to Java. 1015 } else if (strcmp(key, "sun.java.launcher.is_altjvm") == 0 || 1016 strcmp(key, "sun.java.launcher.pid") == 0) { 1017 // sun.java.launcher.is_altjvm and sun.java.launcher.pid property are 1018 // private and are processed in process_sun_java_launcher_properties(); 1019 // the sun.java.launcher property is passed on to the java application 1020 FreeHeap(key); 1021 if (eq != NULL) { 1022 FreeHeap(value); 1023 } 1024 return true; 1025 } else if (strcmp(key, "java.vendor.url.bug") == 0) { 1026 // save it in _java_vendor_url_bug, so JVM fatal error handler can access 1027 // its value without going through the property list or making a Java call. 1028 _java_vendor_url_bug = value; 1029 } else if (strcmp(key, "sun.boot.library.path") == 0) { 1030 PropertyList_unique_add(&_system_properties, key, value, true); 1031 return true; 1032 } 1033 // Create new property and add at the end of the list 1034 PropertyList_unique_add(&_system_properties, key, value); 1035 return true; 1036 } 1037 1038 //=========================================================================================================== 1039 // Setting int/mixed/comp mode flags 1040 1041 void Arguments::set_mode_flags(Mode mode) { 1042 // Set up default values for all flags. 1043 // If you add a flag to any of the branches below, 1044 // add a default value for it here. 1045 set_java_compiler(false); 1046 _mode = mode; 1047 1048 // Ensure Agent_OnLoad has the correct initial values. 1049 // This may not be the final mode; mode may change later in onload phase. 1050 PropertyList_unique_add(&_system_properties, "java.vm.info", 1051 (char*)VM_Version::vm_info_string(), false); 1052 1053 UseInterpreter = true; 1054 UseCompiler = true; 1055 UseLoopCounter = true; 1056 1057 // Default values may be platform/compiler dependent - 1058 // use the saved values 1059 ClipInlining = Arguments::_ClipInlining; 1060 AlwaysCompileLoopMethods = Arguments::_AlwaysCompileLoopMethods; 1061 UseOnStackReplacement = Arguments::_UseOnStackReplacement; 1062 BackgroundCompilation = Arguments::_BackgroundCompilation; 1063 if (TieredCompilation) { 1064 if (FLAG_IS_DEFAULT(Tier3InvokeNotifyFreqLog)) { 1065 Tier3InvokeNotifyFreqLog = Arguments::_Tier3InvokeNotifyFreqLog; 1066 } 1067 if (FLAG_IS_DEFAULT(Tier4InvocationThreshold)) { 1068 Tier4InvocationThreshold = Arguments::_Tier4InvocationThreshold; 1069 } 1070 } 1071 1072 // Change from defaults based on mode 1073 switch (mode) { 1074 default: 1075 ShouldNotReachHere(); 1076 break; 1077 case _int: 1078 UseCompiler = false; 1079 UseLoopCounter = false; 1080 AlwaysCompileLoopMethods = false; 1081 UseOnStackReplacement = false; 1082 break; 1083 case _mixed: 1084 // same as default 1085 break; 1086 case _comp: 1087 UseInterpreter = false; 1088 BackgroundCompilation = false; 1089 ClipInlining = false; 1090 // Be much more aggressive in tiered mode with -Xcomp and exercise C2 more. 1091 // We will first compile a level 3 version (C1 with full profiling), then do one invocation of it and 1092 // compile a level 4 (C2) and then continue executing it. 1093 if (TieredCompilation) { 1094 Tier3InvokeNotifyFreqLog = 0; 1095 Tier4InvocationThreshold = 0; 1096 } 1097 break; 1098 } 1099 } 1100 1101 #if defined(COMPILER2) || defined(_LP64) || !INCLUDE_CDS 1102 // Conflict: required to use shared spaces (-Xshare:on), but 1103 // incompatible command line options were chosen. 1104 1105 static void no_shared_spaces(const char* message) { 1106 if (RequireSharedSpaces) { 1107 jio_fprintf(defaultStream::error_stream(), 1108 "Class data sharing is inconsistent with other specified options.\n"); 1109 vm_exit_during_initialization("Unable to use shared archive.", message); 1110 } else { 1111 FLAG_SET_DEFAULT(UseSharedSpaces, false); 1112 } 1113 } 1114 #endif 1115 1116 // Returns threshold scaled with the value of scale. 1117 // If scale < 0.0, threshold is returned without scaling. 1118 intx Arguments::scaled_compile_threshold(intx threshold, double scale) { 1119 if (scale == 1.0 || scale < 0.0) { 1120 return threshold; 1121 } else { 1122 return (intx)(threshold * scale); 1123 } 1124 } 1125 1126 // Returns freq_log scaled with the value of scale. 1127 // Returned values are in the range of [0, InvocationCounter::number_of_count_bits + 1]. 1128 // If scale < 0.0, freq_log is returned without scaling. 1129 intx Arguments::scaled_freq_log(intx freq_log, double scale) { 1130 // Check if scaling is necessary or if negative value was specified. 1131 if (scale == 1.0 || scale < 0.0) { 1132 return freq_log; 1133 } 1134 // Check values to avoid calculating log2 of 0. 1135 if (scale == 0.0 || freq_log == 0) { 1136 return 0; 1137 } 1138 // Determine the maximum notification frequency value currently supported. 1139 // The largest mask value that the interpreter/C1 can handle is 1140 // of length InvocationCounter::number_of_count_bits. Mask values are always 1141 // one bit shorter then the value of the notification frequency. Set 1142 // max_freq_bits accordingly. 1143 intx max_freq_bits = InvocationCounter::number_of_count_bits + 1; 1144 intx scaled_freq = scaled_compile_threshold((intx)1 << freq_log, scale); 1145 if (scaled_freq == 0) { 1146 // Return 0 right away to avoid calculating log2 of 0. 1147 return 0; 1148 } else if (scaled_freq > nth_bit(max_freq_bits)) { 1149 return max_freq_bits; 1150 } else { 1151 return log2_intptr(scaled_freq); 1152 } 1153 } 1154 1155 void Arguments::set_tiered_flags() { 1156 // With tiered, set default policy to AdvancedThresholdPolicy, which is 3. 1157 if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) { 1158 FLAG_SET_DEFAULT(CompilationPolicyChoice, 3); 1159 } 1160 if (CompilationPolicyChoice < 2) { 1161 vm_exit_during_initialization( 1162 "Incompatible compilation policy selected", NULL); 1163 } 1164 // Increase the code cache size - tiered compiles a lot more. 1165 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { 1166 FLAG_SET_ERGO(uintx, ReservedCodeCacheSize, 1167 MIN2(CODE_CACHE_DEFAULT_LIMIT, ReservedCodeCacheSize * 5)); 1168 } 1169 // Enable SegmentedCodeCache if TieredCompilation is enabled and ReservedCodeCacheSize >= 240M 1170 if (FLAG_IS_DEFAULT(SegmentedCodeCache) && ReservedCodeCacheSize >= 240*M) { 1171 FLAG_SET_ERGO(bool, SegmentedCodeCache, true); 1172 1173 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { 1174 // Multiply sizes by 5 but fix NonNMethodCodeHeapSize (distribute among non-profiled and profiled code heap) 1175 if (FLAG_IS_DEFAULT(ProfiledCodeHeapSize)) { 1176 FLAG_SET_ERGO(uintx, ProfiledCodeHeapSize, ProfiledCodeHeapSize * 5 + NonNMethodCodeHeapSize * 2); 1177 } 1178 if (FLAG_IS_DEFAULT(NonProfiledCodeHeapSize)) { 1179 FLAG_SET_ERGO(uintx, NonProfiledCodeHeapSize, NonProfiledCodeHeapSize * 5 + NonNMethodCodeHeapSize * 2); 1180 } 1181 // Check consistency of code heap sizes 1182 if ((NonNMethodCodeHeapSize + NonProfiledCodeHeapSize + ProfiledCodeHeapSize) != ReservedCodeCacheSize) { 1183 jio_fprintf(defaultStream::error_stream(), 1184 "Invalid code heap sizes: NonNMethodCodeHeapSize(%dK) + ProfiledCodeHeapSize(%dK) + NonProfiledCodeHeapSize(%dK) = %dK. Must be equal to ReservedCodeCacheSize = %uK.\n", 1185 NonNMethodCodeHeapSize/K, ProfiledCodeHeapSize/K, NonProfiledCodeHeapSize/K, 1186 (NonNMethodCodeHeapSize + ProfiledCodeHeapSize + NonProfiledCodeHeapSize)/K, ReservedCodeCacheSize/K); 1187 vm_exit(1); 1188 } 1189 } 1190 } 1191 if (!UseInterpreter) { // -Xcomp 1192 Tier3InvokeNotifyFreqLog = 0; 1193 Tier4InvocationThreshold = 0; 1194 } 1195 1196 if (CompileThresholdScaling < 0) { 1197 vm_exit_during_initialization("Negative value specified for CompileThresholdScaling", NULL); 1198 } 1199 1200 // Scale tiered compilation thresholds. 1201 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves compilation thresholds unchanged. 1202 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) { 1203 FLAG_SET_ERGO(intx, Tier0InvokeNotifyFreqLog, scaled_freq_log(Tier0InvokeNotifyFreqLog)); 1204 FLAG_SET_ERGO(intx, Tier0BackedgeNotifyFreqLog, scaled_freq_log(Tier0BackedgeNotifyFreqLog)); 1205 1206 FLAG_SET_ERGO(intx, Tier3InvocationThreshold, scaled_compile_threshold(Tier3InvocationThreshold)); 1207 FLAG_SET_ERGO(intx, Tier3MinInvocationThreshold, scaled_compile_threshold(Tier3MinInvocationThreshold)); 1208 FLAG_SET_ERGO(intx, Tier3CompileThreshold, scaled_compile_threshold(Tier3CompileThreshold)); 1209 FLAG_SET_ERGO(intx, Tier3BackEdgeThreshold, scaled_compile_threshold(Tier3BackEdgeThreshold)); 1210 1211 // Tier2{Invocation,MinInvocation,Compile,Backedge}Threshold should be scaled here 1212 // once these thresholds become supported. 1213 1214 FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog)); 1215 FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog)); 1216 1217 FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog)); 1218 FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog)); 1219 1220 FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog)); 1221 1222 FLAG_SET_ERGO(intx, Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold)); 1223 FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold)); 1224 FLAG_SET_ERGO(intx, Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold)); 1225 FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold)); 1226 } 1227 } 1228 1229 #if INCLUDE_ALL_GCS 1230 static void disable_adaptive_size_policy(const char* collector_name) { 1231 if (UseAdaptiveSizePolicy) { 1232 if (FLAG_IS_CMDLINE(UseAdaptiveSizePolicy)) { 1233 warning("disabling UseAdaptiveSizePolicy; it is incompatible with %s.", 1234 collector_name); 1235 } 1236 FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false); 1237 } 1238 } 1239 1240 void Arguments::set_parnew_gc_flags() { 1241 assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC, 1242 "control point invariant"); 1243 assert(UseConcMarkSweepGC, "CMS is expected to be on here"); 1244 assert(UseParNewGC, "ParNew should always be used with CMS"); 1245 1246 if (FLAG_IS_DEFAULT(ParallelGCThreads)) { 1247 FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads()); 1248 assert(ParallelGCThreads > 0, "We should always have at least one thread by default"); 1249 } else if (ParallelGCThreads == 0) { 1250 jio_fprintf(defaultStream::error_stream(), 1251 "The ParNew GC can not be combined with -XX:ParallelGCThreads=0\n"); 1252 vm_exit(1); 1253 } 1254 1255 // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 respectively, 1256 // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration 1257 // we set them to 1024 and 1024. 1258 // See CR 6362902. 1259 if (FLAG_IS_DEFAULT(YoungPLABSize)) { 1260 FLAG_SET_DEFAULT(YoungPLABSize, (intx)1024); 1261 } 1262 if (FLAG_IS_DEFAULT(OldPLABSize)) { 1263 FLAG_SET_DEFAULT(OldPLABSize, (intx)1024); 1264 } 1265 1266 // When using compressed oops, we use local overflow stacks, 1267 // rather than using a global overflow list chained through 1268 // the klass word of the object's pre-image. 1269 if (UseCompressedOops && !ParGCUseLocalOverflow) { 1270 if (!FLAG_IS_DEFAULT(ParGCUseLocalOverflow)) { 1271 warning("Forcing +ParGCUseLocalOverflow: needed if using compressed references"); 1272 } 1273 FLAG_SET_DEFAULT(ParGCUseLocalOverflow, true); 1274 } 1275 assert(ParGCUseLocalOverflow || !UseCompressedOops, "Error"); 1276 } 1277 1278 // Adjust some sizes to suit CMS and/or ParNew needs; these work well on 1279 // sparc/solaris for certain applications, but would gain from 1280 // further optimization and tuning efforts, and would almost 1281 // certainly gain from analysis of platform and environment. 1282 void Arguments::set_cms_and_parnew_gc_flags() { 1283 assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error"); 1284 assert(UseConcMarkSweepGC, "CMS is expected to be on here"); 1285 assert(UseParNewGC, "ParNew should always be used with CMS"); 1286 1287 // Turn off AdaptiveSizePolicy by default for cms until it is complete. 1288 disable_adaptive_size_policy("UseConcMarkSweepGC"); 1289 1290 set_parnew_gc_flags(); 1291 1292 size_t max_heap = align_size_down(MaxHeapSize, 1293 CardTableRS::ct_max_alignment_constraint()); 1294 1295 // Now make adjustments for CMS 1296 intx tenuring_default = (intx)6; 1297 size_t young_gen_per_worker = CMSYoungGenPerWorker; 1298 1299 // Preferred young gen size for "short" pauses: 1300 // upper bound depends on # of threads and NewRatio. 1301 const size_t preferred_max_new_size_unaligned = 1302 MIN2(max_heap/(NewRatio+1), ScaleForWordSize(young_gen_per_worker * ParallelGCThreads)); 1303 size_t preferred_max_new_size = 1304 align_size_up(preferred_max_new_size_unaligned, os::vm_page_size()); 1305 1306 // Unless explicitly requested otherwise, size young gen 1307 // for "short" pauses ~ CMSYoungGenPerWorker*ParallelGCThreads 1308 1309 // If either MaxNewSize or NewRatio is set on the command line, 1310 // assume the user is trying to set the size of the young gen. 1311 if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) { 1312 1313 // Set MaxNewSize to our calculated preferred_max_new_size unless 1314 // NewSize was set on the command line and it is larger than 1315 // preferred_max_new_size. 1316 if (!FLAG_IS_DEFAULT(NewSize)) { // NewSize explicitly set at command-line 1317 FLAG_SET_ERGO(size_t, MaxNewSize, MAX2(NewSize, preferred_max_new_size)); 1318 } else { 1319 FLAG_SET_ERGO(size_t, MaxNewSize, preferred_max_new_size); 1320 } 1321 if (PrintGCDetails && Verbose) { 1322 // Too early to use gclog_or_tty 1323 tty->print_cr("CMS ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize); 1324 } 1325 1326 // Code along this path potentially sets NewSize and OldSize 1327 if (PrintGCDetails && Verbose) { 1328 // Too early to use gclog_or_tty 1329 tty->print_cr("CMS set min_heap_size: " SIZE_FORMAT 1330 " initial_heap_size: " SIZE_FORMAT 1331 " max_heap: " SIZE_FORMAT, 1332 min_heap_size(), InitialHeapSize, max_heap); 1333 } 1334 size_t min_new = preferred_max_new_size; 1335 if (FLAG_IS_CMDLINE(NewSize)) { 1336 min_new = NewSize; 1337 } 1338 if (max_heap > min_new && min_heap_size() > min_new) { 1339 // Unless explicitly requested otherwise, make young gen 1340 // at least min_new, and at most preferred_max_new_size. 1341 if (FLAG_IS_DEFAULT(NewSize)) { 1342 FLAG_SET_ERGO(size_t, NewSize, MAX2(NewSize, min_new)); 1343 FLAG_SET_ERGO(size_t, NewSize, MIN2(preferred_max_new_size, NewSize)); 1344 if (PrintGCDetails && Verbose) { 1345 // Too early to use gclog_or_tty 1346 tty->print_cr("CMS ergo set NewSize: " SIZE_FORMAT, NewSize); 1347 } 1348 } 1349 // Unless explicitly requested otherwise, size old gen 1350 // so it's NewRatio x of NewSize. 1351 if (FLAG_IS_DEFAULT(OldSize)) { 1352 if (max_heap > NewSize) { 1353 FLAG_SET_ERGO(size_t, OldSize, MIN2(NewRatio*NewSize, max_heap - NewSize)); 1354 if (PrintGCDetails && Verbose) { 1355 // Too early to use gclog_or_tty 1356 tty->print_cr("CMS ergo set OldSize: " SIZE_FORMAT, OldSize); 1357 } 1358 } 1359 } 1360 } 1361 } 1362 // Unless explicitly requested otherwise, definitely 1363 // promote all objects surviving "tenuring_default" scavenges. 1364 if (FLAG_IS_DEFAULT(MaxTenuringThreshold) && 1365 FLAG_IS_DEFAULT(SurvivorRatio)) { 1366 FLAG_SET_ERGO(uintx, MaxTenuringThreshold, tenuring_default); 1367 } 1368 // If we decided above (or user explicitly requested) 1369 // `promote all' (via MaxTenuringThreshold := 0), 1370 // prefer minuscule survivor spaces so as not to waste 1371 // space for (non-existent) survivors 1372 if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) { 1373 FLAG_SET_ERGO(uintx, SurvivorRatio, MAX2((uintx)1024, SurvivorRatio)); 1374 } 1375 1376 // OldPLABSize is interpreted in CMS as not the size of the PLAB in words, 1377 // but rather the number of free blocks of a given size that are used when 1378 // replenishing the local per-worker free list caches. 1379 if (FLAG_IS_DEFAULT(OldPLABSize)) { 1380 if (!FLAG_IS_DEFAULT(ResizeOldPLAB) && !ResizeOldPLAB) { 1381 // OldPLAB sizing manually turned off: Use a larger default setting, 1382 // unless it was manually specified. This is because a too-low value 1383 // will slow down scavenges. 1384 FLAG_SET_ERGO(size_t, OldPLABSize, CFLS_LAB::_default_static_old_plab_size); // default value before 6631166 1385 } else { 1386 FLAG_SET_DEFAULT(OldPLABSize, CFLS_LAB::_default_dynamic_old_plab_size); // old CMSParPromoteBlocksToClaim default 1387 } 1388 } 1389 1390 // If either of the static initialization defaults have changed, note this 1391 // modification. 1392 if (!FLAG_IS_DEFAULT(OldPLABSize) || !FLAG_IS_DEFAULT(OldPLABWeight)) { 1393 CFLS_LAB::modify_initialization(OldPLABSize, OldPLABWeight); 1394 } 1395 1396 if (!ClassUnloading) { 1397 FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false); 1398 FLAG_SET_CMDLINE(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false); 1399 } 1400 1401 if (PrintGCDetails && Verbose) { 1402 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk", 1403 (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K)); 1404 tty->print_cr("ConcGCThreads: %u", ConcGCThreads); 1405 } 1406 } 1407 #endif // INCLUDE_ALL_GCS 1408 1409 void set_object_alignment() { 1410 // Object alignment. 1411 assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2"); 1412 MinObjAlignmentInBytes = ObjectAlignmentInBytes; 1413 assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small"); 1414 MinObjAlignment = MinObjAlignmentInBytes / HeapWordSize; 1415 assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect"); 1416 MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1; 1417 1418 LogMinObjAlignmentInBytes = exact_log2(ObjectAlignmentInBytes); 1419 LogMinObjAlignment = LogMinObjAlignmentInBytes - LogHeapWordSize; 1420 1421 // Oop encoding heap max 1422 OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes; 1423 1424 if (SurvivorAlignmentInBytes == 0) { 1425 SurvivorAlignmentInBytes = ObjectAlignmentInBytes; 1426 } 1427 1428 #if INCLUDE_ALL_GCS 1429 // Set CMS global values 1430 CompactibleFreeListSpace::set_cms_values(); 1431 #endif // INCLUDE_ALL_GCS 1432 } 1433 1434 size_t Arguments::max_heap_for_compressed_oops() { 1435 // Avoid sign flip. 1436 assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size"); 1437 // We need to fit both the NULL page and the heap into the memory budget, while 1438 // keeping alignment constraints of the heap. To guarantee the latter, as the 1439 // NULL page is located before the heap, we pad the NULL page to the conservative 1440 // maximum alignment that the GC may ever impose upon the heap. 1441 size_t displacement_due_to_null_page = align_size_up_(os::vm_page_size(), 1442 _conservative_max_heap_alignment); 1443 1444 LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page); 1445 NOT_LP64(ShouldNotReachHere(); return 0); 1446 } 1447 1448 bool Arguments::should_auto_select_low_pause_collector() { 1449 if (UseAutoGCSelectPolicy && 1450 !FLAG_IS_DEFAULT(MaxGCPauseMillis) && 1451 (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) { 1452 if (PrintGCDetails) { 1453 // Cannot use gclog_or_tty yet. 1454 tty->print_cr("Automatic selection of the low pause collector" 1455 " based on pause goal of %d (ms)", (int) MaxGCPauseMillis); 1456 } 1457 return true; 1458 } 1459 return false; 1460 } 1461 1462 void Arguments::set_use_compressed_oops() { 1463 #ifndef ZERO 1464 #ifdef _LP64 1465 // MaxHeapSize is not set up properly at this point, but 1466 // the only value that can override MaxHeapSize if we are 1467 // to use UseCompressedOops is InitialHeapSize. 1468 size_t max_heap_size = MAX2(MaxHeapSize, InitialHeapSize); 1469 1470 if (max_heap_size <= max_heap_for_compressed_oops()) { 1471 #if !defined(COMPILER1) || defined(TIERED) 1472 if (FLAG_IS_DEFAULT(UseCompressedOops)) { 1473 FLAG_SET_ERGO(bool, UseCompressedOops, true); 1474 } 1475 #endif 1476 } else { 1477 if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) { 1478 warning("Max heap size too large for Compressed Oops"); 1479 FLAG_SET_DEFAULT(UseCompressedOops, false); 1480 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1481 } 1482 } 1483 #endif // _LP64 1484 #endif // ZERO 1485 } 1486 1487 1488 // NOTE: set_use_compressed_klass_ptrs() must be called after calling 1489 // set_use_compressed_oops(). 1490 void Arguments::set_use_compressed_klass_ptrs() { 1491 #ifndef ZERO 1492 #ifdef _LP64 1493 // UseCompressedOops must be on for UseCompressedClassPointers to be on. 1494 if (!UseCompressedOops) { 1495 if (UseCompressedClassPointers) { 1496 warning("UseCompressedClassPointers requires UseCompressedOops"); 1497 } 1498 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1499 } else { 1500 // Turn on UseCompressedClassPointers too 1501 if (FLAG_IS_DEFAULT(UseCompressedClassPointers)) { 1502 FLAG_SET_ERGO(bool, UseCompressedClassPointers, true); 1503 } 1504 // Check the CompressedClassSpaceSize to make sure we use compressed klass ptrs. 1505 if (UseCompressedClassPointers) { 1506 if (CompressedClassSpaceSize > KlassEncodingMetaspaceMax) { 1507 warning("CompressedClassSpaceSize is too large for UseCompressedClassPointers"); 1508 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1509 } 1510 } 1511 } 1512 #endif // _LP64 1513 #endif // !ZERO 1514 } 1515 1516 void Arguments::set_conservative_max_heap_alignment() { 1517 // The conservative maximum required alignment for the heap is the maximum of 1518 // the alignments imposed by several sources: any requirements from the heap 1519 // itself, the collector policy and the maximum page size we may run the VM 1520 // with. 1521 size_t heap_alignment = GenCollectedHeap::conservative_max_heap_alignment(); 1522 #if INCLUDE_ALL_GCS 1523 if (UseParallelGC) { 1524 heap_alignment = ParallelScavengeHeap::conservative_max_heap_alignment(); 1525 } else if (UseG1GC) { 1526 heap_alignment = G1CollectedHeap::conservative_max_heap_alignment(); 1527 } 1528 #endif // INCLUDE_ALL_GCS 1529 _conservative_max_heap_alignment = MAX4(heap_alignment, 1530 (size_t)os::vm_allocation_granularity(), 1531 os::max_page_size(), 1532 CollectorPolicy::compute_heap_alignment()); 1533 } 1534 1535 void Arguments::select_gc_ergonomically() { 1536 if (os::is_server_class_machine()) { 1537 if (should_auto_select_low_pause_collector()) { 1538 FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true); 1539 } else { 1540 #if defined(JAVASE_EMBEDDED) 1541 FLAG_SET_ERGO(bool, UseParallelGC, true); 1542 #else 1543 FLAG_SET_ERGO(bool, UseG1GC, true); 1544 #endif 1545 } 1546 } else { 1547 FLAG_SET_ERGO(bool, UseSerialGC, true); 1548 } 1549 } 1550 1551 void Arguments::select_gc() { 1552 if (!gc_selected()) { 1553 select_gc_ergonomically(); 1554 guarantee(gc_selected(), "No GC selected"); 1555 } 1556 } 1557 1558 void Arguments::set_ergonomics_flags() { 1559 select_gc(); 1560 1561 #ifdef COMPILER2 1562 // Shared spaces work fine with other GCs but causes bytecode rewriting 1563 // to be disabled, which hurts interpreter performance and decreases 1564 // server performance. When -server is specified, keep the default off 1565 // unless it is asked for. Future work: either add bytecode rewriting 1566 // at link time, or rewrite bytecodes in non-shared methods. 1567 if (!DumpSharedSpaces && !RequireSharedSpaces && 1568 (FLAG_IS_DEFAULT(UseSharedSpaces) || !UseSharedSpaces)) { 1569 no_shared_spaces("COMPILER2 default: -Xshare:auto | off, have to manually setup to on."); 1570 } 1571 #endif 1572 1573 set_conservative_max_heap_alignment(); 1574 1575 #ifndef ZERO 1576 #ifdef _LP64 1577 set_use_compressed_oops(); 1578 1579 // set_use_compressed_klass_ptrs() must be called after calling 1580 // set_use_compressed_oops(). 1581 set_use_compressed_klass_ptrs(); 1582 1583 // Also checks that certain machines are slower with compressed oops 1584 // in vm_version initialization code. 1585 #endif // _LP64 1586 #endif // !ZERO 1587 1588 // Set up runtime image flags. 1589 set_runtime_image_flags(); 1590 1591 CodeCacheExtensions::set_ergonomics_flags(); 1592 } 1593 1594 void Arguments::set_parallel_gc_flags() { 1595 assert(UseParallelGC || UseParallelOldGC, "Error"); 1596 // Enable ParallelOld unless it was explicitly disabled (cmd line or rc file). 1597 if (FLAG_IS_DEFAULT(UseParallelOldGC)) { 1598 FLAG_SET_DEFAULT(UseParallelOldGC, true); 1599 } 1600 FLAG_SET_DEFAULT(UseParallelGC, true); 1601 1602 // If no heap maximum was requested explicitly, use some reasonable fraction 1603 // of the physical memory, up to a maximum of 1GB. 1604 FLAG_SET_DEFAULT(ParallelGCThreads, 1605 Abstract_VM_Version::parallel_worker_threads()); 1606 if (ParallelGCThreads == 0) { 1607 jio_fprintf(defaultStream::error_stream(), 1608 "The Parallel GC can not be combined with -XX:ParallelGCThreads=0\n"); 1609 vm_exit(1); 1610 } 1611 1612 if (UseAdaptiveSizePolicy) { 1613 // We don't want to limit adaptive heap sizing's freedom to adjust the heap 1614 // unless the user actually sets these flags. 1615 if (FLAG_IS_DEFAULT(MinHeapFreeRatio)) { 1616 FLAG_SET_DEFAULT(MinHeapFreeRatio, 0); 1617 } 1618 if (FLAG_IS_DEFAULT(MaxHeapFreeRatio)) { 1619 FLAG_SET_DEFAULT(MaxHeapFreeRatio, 100); 1620 } 1621 } 1622 1623 // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the 1624 // SurvivorRatio has been set, reset their default values to SurvivorRatio + 1625 // 2. By doing this we make SurvivorRatio also work for Parallel Scavenger. 1626 // See CR 6362902 for details. 1627 if (!FLAG_IS_DEFAULT(SurvivorRatio)) { 1628 if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) { 1629 FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2); 1630 } 1631 if (FLAG_IS_DEFAULT(MinSurvivorRatio)) { 1632 FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2); 1633 } 1634 } 1635 1636 if (UseParallelOldGC) { 1637 // Par compact uses lower default values since they are treated as 1638 // minimums. These are different defaults because of the different 1639 // interpretation and are not ergonomically set. 1640 if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) { 1641 FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1); 1642 } 1643 } 1644 } 1645 1646 void Arguments::set_g1_gc_flags() { 1647 assert(UseG1GC, "Error"); 1648 #ifdef COMPILER1 1649 FastTLABRefill = false; 1650 #endif 1651 FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads()); 1652 if (ParallelGCThreads == 0) { 1653 assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0."); 1654 vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL); 1655 } 1656 1657 #if INCLUDE_ALL_GCS 1658 if (G1ConcRefinementThreads == 0) { 1659 FLAG_SET_DEFAULT(G1ConcRefinementThreads, ParallelGCThreads); 1660 } 1661 #endif 1662 1663 // MarkStackSize will be set (if it hasn't been set by the user) 1664 // when concurrent marking is initialized. 1665 // Its value will be based upon the number of parallel marking threads. 1666 // But we do set the maximum mark stack size here. 1667 if (FLAG_IS_DEFAULT(MarkStackSizeMax)) { 1668 FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE); 1669 } 1670 1671 if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) { 1672 // In G1, we want the default GC overhead goal to be higher than 1673 // say in PS. So we set it here to 10%. Otherwise the heap might 1674 // be expanded more aggressively than we would like it to. In 1675 // fact, even 10% seems to not be high enough in some cases 1676 // (especially small GC stress tests that the main thing they do 1677 // is allocation). We might consider increase it further. 1678 FLAG_SET_DEFAULT(GCTimeRatio, 9); 1679 } 1680 1681 if (PrintGCDetails && Verbose) { 1682 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk", 1683 (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K)); 1684 tty->print_cr("ConcGCThreads: %u", ConcGCThreads); 1685 } 1686 } 1687 1688 #if !INCLUDE_ALL_GCS 1689 #ifdef ASSERT 1690 static bool verify_serial_gc_flags() { 1691 return (UseSerialGC && 1692 !(UseParNewGC || (UseConcMarkSweepGC) || UseG1GC || 1693 UseParallelGC || UseParallelOldGC)); 1694 } 1695 #endif // ASSERT 1696 #endif // INCLUDE_ALL_GCS 1697 1698 void Arguments::set_gc_specific_flags() { 1699 #if INCLUDE_ALL_GCS 1700 // Set per-collector flags 1701 if (UseParallelGC || UseParallelOldGC) { 1702 set_parallel_gc_flags(); 1703 } else if (UseConcMarkSweepGC) { 1704 set_cms_and_parnew_gc_flags(); 1705 } else if (UseG1GC) { 1706 set_g1_gc_flags(); 1707 } 1708 check_deprecated_gc_flags(); 1709 if (AssumeMP && !UseSerialGC) { 1710 if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) { 1711 warning("If the number of processors is expected to increase from one, then" 1712 " you should configure the number of parallel GC threads appropriately" 1713 " using -XX:ParallelGCThreads=N"); 1714 } 1715 } 1716 if (MinHeapFreeRatio == 100) { 1717 // Keeping the heap 100% free is hard ;-) so limit it to 99%. 1718 FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99); 1719 } 1720 #else // INCLUDE_ALL_GCS 1721 assert(verify_serial_gc_flags(), "SerialGC unset"); 1722 #endif // INCLUDE_ALL_GCS 1723 } 1724 1725 julong Arguments::limit_by_allocatable_memory(julong limit) { 1726 julong max_allocatable; 1727 julong result = limit; 1728 if (os::has_allocatable_memory_limit(&max_allocatable)) { 1729 result = MIN2(result, max_allocatable / MaxVirtMemFraction); 1730 } 1731 return result; 1732 } 1733 1734 // Use static initialization to get the default before parsing 1735 static const size_t DefaultHeapBaseMinAddress = HeapBaseMinAddress; 1736 1737 void Arguments::set_heap_size() { 1738 if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) { 1739 // Deprecated flag 1740 FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction); 1741 } 1742 1743 const julong phys_mem = 1744 FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM) 1745 : (julong)MaxRAM; 1746 1747 // If the maximum heap size has not been set with -Xmx, 1748 // then set it as fraction of the size of physical memory, 1749 // respecting the maximum and minimum sizes of the heap. 1750 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 1751 julong reasonable_max = phys_mem / MaxRAMFraction; 1752 1753 if (phys_mem <= MaxHeapSize * MinRAMFraction) { 1754 // Small physical memory, so use a minimum fraction of it for the heap 1755 reasonable_max = phys_mem / MinRAMFraction; 1756 } else { 1757 // Not-small physical memory, so require a heap at least 1758 // as large as MaxHeapSize 1759 reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize); 1760 } 1761 if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) { 1762 // Limit the heap size to ErgoHeapSizeLimit 1763 reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit); 1764 } 1765 if (UseCompressedOops) { 1766 // Limit the heap size to the maximum possible when using compressed oops 1767 julong max_coop_heap = (julong)max_heap_for_compressed_oops(); 1768 1769 // HeapBaseMinAddress can be greater than default but not less than. 1770 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress)) { 1771 if (HeapBaseMinAddress < DefaultHeapBaseMinAddress) { 1772 // matches compressed oops printing flags 1773 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) { 1774 jio_fprintf(defaultStream::error_stream(), 1775 "HeapBaseMinAddress must be at least " SIZE_FORMAT 1776 " (" SIZE_FORMAT "G) which is greater than value given " 1777 SIZE_FORMAT "\n", 1778 DefaultHeapBaseMinAddress, 1779 DefaultHeapBaseMinAddress/G, 1780 HeapBaseMinAddress); 1781 } 1782 FLAG_SET_ERGO(size_t, HeapBaseMinAddress, DefaultHeapBaseMinAddress); 1783 } 1784 } 1785 1786 if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) { 1787 // Heap should be above HeapBaseMinAddress to get zero based compressed oops 1788 // but it should be not less than default MaxHeapSize. 1789 max_coop_heap -= HeapBaseMinAddress; 1790 } 1791 reasonable_max = MIN2(reasonable_max, max_coop_heap); 1792 } 1793 reasonable_max = limit_by_allocatable_memory(reasonable_max); 1794 1795 if (!FLAG_IS_DEFAULT(InitialHeapSize)) { 1796 // An initial heap size was specified on the command line, 1797 // so be sure that the maximum size is consistent. Done 1798 // after call to limit_by_allocatable_memory because that 1799 // method might reduce the allocation size. 1800 reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize); 1801 } 1802 1803 if (PrintGCDetails && Verbose) { 1804 // Cannot use gclog_or_tty yet. 1805 tty->print_cr(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max); 1806 } 1807 FLAG_SET_ERGO(size_t, MaxHeapSize, (size_t)reasonable_max); 1808 } 1809 1810 // If the minimum or initial heap_size have not been set or requested to be set 1811 // ergonomically, set them accordingly. 1812 if (InitialHeapSize == 0 || min_heap_size() == 0) { 1813 julong reasonable_minimum = (julong)(OldSize + NewSize); 1814 1815 reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize); 1816 1817 reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum); 1818 1819 if (InitialHeapSize == 0) { 1820 julong reasonable_initial = phys_mem / InitialRAMFraction; 1821 1822 reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size()); 1823 reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize); 1824 1825 reasonable_initial = limit_by_allocatable_memory(reasonable_initial); 1826 1827 if (PrintGCDetails && Verbose) { 1828 // Cannot use gclog_or_tty yet. 1829 tty->print_cr(" Initial heap size " SIZE_FORMAT, (size_t)reasonable_initial); 1830 } 1831 FLAG_SET_ERGO(size_t, InitialHeapSize, (size_t)reasonable_initial); 1832 } 1833 // If the minimum heap size has not been set (via -Xms), 1834 // synchronize with InitialHeapSize to avoid errors with the default value. 1835 if (min_heap_size() == 0) { 1836 set_min_heap_size(MIN2((size_t)reasonable_minimum, InitialHeapSize)); 1837 if (PrintGCDetails && Verbose) { 1838 // Cannot use gclog_or_tty yet. 1839 tty->print_cr(" Minimum heap size " SIZE_FORMAT, min_heap_size()); 1840 } 1841 } 1842 } 1843 } 1844 1845 // Set up runtime image flags 1846 void Arguments::set_runtime_image_flags() { 1847 #ifdef _LP64 1848 // Memory map image file by default on 64 bit machines. 1849 if (FLAG_IS_DEFAULT(MemoryMapImage)) { 1850 FLAG_SET_ERGO(bool, MemoryMapImage, true); 1851 } 1852 #endif 1853 } 1854 1855 // This must be called after ergonomics. 1856 void Arguments::set_bytecode_flags() { 1857 if (!RewriteBytecodes) { 1858 FLAG_SET_DEFAULT(RewriteFrequentPairs, false); 1859 } 1860 } 1861 1862 // Aggressive optimization flags -XX:+AggressiveOpts 1863 void Arguments::set_aggressive_opts_flags() { 1864 #ifdef COMPILER2 1865 if (AggressiveUnboxing) { 1866 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 1867 FLAG_SET_DEFAULT(EliminateAutoBox, true); 1868 } else if (!EliminateAutoBox) { 1869 // warning("AggressiveUnboxing is disabled because EliminateAutoBox is disabled"); 1870 AggressiveUnboxing = false; 1871 } 1872 if (FLAG_IS_DEFAULT(DoEscapeAnalysis)) { 1873 FLAG_SET_DEFAULT(DoEscapeAnalysis, true); 1874 } else if (!DoEscapeAnalysis) { 1875 // warning("AggressiveUnboxing is disabled because DoEscapeAnalysis is disabled"); 1876 AggressiveUnboxing = false; 1877 } 1878 } 1879 if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) { 1880 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 1881 FLAG_SET_DEFAULT(EliminateAutoBox, true); 1882 } 1883 if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) { 1884 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000); 1885 } 1886 1887 // Feed the cache size setting into the JDK 1888 char buffer[1024]; 1889 sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax); 1890 add_property(buffer); 1891 } 1892 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) { 1893 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500); 1894 } 1895 #endif 1896 1897 if (AggressiveOpts) { 1898 // Sample flag setting code 1899 // if (FLAG_IS_DEFAULT(EliminateZeroing)) { 1900 // FLAG_SET_DEFAULT(EliminateZeroing, true); 1901 // } 1902 } 1903 } 1904 1905 //=========================================================================================================== 1906 // Parsing of java.compiler property 1907 1908 void Arguments::process_java_compiler_argument(char* arg) { 1909 // For backwards compatibility, Djava.compiler=NONE or "" 1910 // causes us to switch to -Xint mode UNLESS -Xdebug 1911 // is also specified. 1912 if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) { 1913 set_java_compiler(true); // "-Djava.compiler[=...]" most recently seen. 1914 } 1915 } 1916 1917 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) { 1918 _sun_java_launcher = os::strdup_check_oom(launcher); 1919 } 1920 1921 bool Arguments::created_by_java_launcher() { 1922 assert(_sun_java_launcher != NULL, "property must have value"); 1923 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0; 1924 } 1925 1926 bool Arguments::sun_java_launcher_is_altjvm() { 1927 return _sun_java_launcher_is_altjvm; 1928 } 1929 1930 //=========================================================================================================== 1931 // Parsing of main arguments 1932 1933 // check if do gclog rotation 1934 // +UseGCLogFileRotation is a must, 1935 // no gc log rotation when log file not supplied or 1936 // NumberOfGCLogFiles is 0 1937 void check_gclog_consistency() { 1938 if (UseGCLogFileRotation) { 1939 if ((Arguments::gc_log_filename() == NULL) || (NumberOfGCLogFiles == 0)) { 1940 jio_fprintf(defaultStream::output_stream(), 1941 "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files>\n" 1942 "where num_of_file > 0\n" 1943 "GC log rotation is turned off\n"); 1944 UseGCLogFileRotation = false; 1945 } 1946 } 1947 1948 if (UseGCLogFileRotation && (GCLogFileSize != 0) && (GCLogFileSize < 8*K)) { 1949 if (FLAG_SET_CMDLINE(size_t, GCLogFileSize, 8*K) == Flag::SUCCESS) { 1950 jio_fprintf(defaultStream::output_stream(), 1951 "GCLogFileSize changed to minimum 8K\n"); 1952 } 1953 } 1954 } 1955 1956 // This function is called for -Xloggc:<filename>, it can be used 1957 // to check if a given file name(or string) conforms to the following 1958 // specification: 1959 // A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]" 1960 // %p and %t only allowed once. We only limit usage of filename not path 1961 bool is_filename_valid(const char *file_name) { 1962 const char* p = file_name; 1963 char file_sep = os::file_separator()[0]; 1964 const char* cp; 1965 // skip prefix path 1966 for (cp = file_name; *cp != '\0'; cp++) { 1967 if (*cp == '/' || *cp == file_sep) { 1968 p = cp + 1; 1969 } 1970 } 1971 1972 int count_p = 0; 1973 int count_t = 0; 1974 while (*p != '\0') { 1975 if ((*p >= '0' && *p <= '9') || 1976 (*p >= 'A' && *p <= 'Z') || 1977 (*p >= 'a' && *p <= 'z') || 1978 *p == '-' || 1979 *p == '_' || 1980 *p == '.') { 1981 p++; 1982 continue; 1983 } 1984 if (*p == '%') { 1985 if(*(p + 1) == 'p') { 1986 p += 2; 1987 count_p ++; 1988 continue; 1989 } 1990 if (*(p + 1) == 't') { 1991 p += 2; 1992 count_t ++; 1993 continue; 1994 } 1995 } 1996 return false; 1997 } 1998 return count_p < 2 && count_t < 2; 1999 } 2000 2001 // Check consistency of GC selection 2002 bool Arguments::check_gc_consistency() { 2003 check_gclog_consistency(); 2004 // Ensure that the user has not selected conflicting sets 2005 // of collectors. 2006 uint i = 0; 2007 if (UseSerialGC) i++; 2008 if (UseConcMarkSweepGC) i++; 2009 if (UseParallelGC || UseParallelOldGC) i++; 2010 if (UseG1GC) i++; 2011 if (i > 1) { 2012 jio_fprintf(defaultStream::error_stream(), 2013 "Conflicting collector combinations in option list; " 2014 "please refer to the release notes for the combinations " 2015 "allowed\n"); 2016 return false; 2017 } 2018 2019 if (UseConcMarkSweepGC && !UseParNewGC) { 2020 jio_fprintf(defaultStream::error_stream(), 2021 "It is not possible to combine the DefNew young collector with the CMS collector.\n"); 2022 return false; 2023 } 2024 2025 if (UseParNewGC && !UseConcMarkSweepGC) { 2026 jio_fprintf(defaultStream::error_stream(), 2027 "It is not possible to combine the ParNew young collector with any collector other than CMS.\n"); 2028 return false; 2029 } 2030 2031 return true; 2032 } 2033 2034 void Arguments::check_deprecated_gc_flags() { 2035 if (FLAG_IS_CMDLINE(UseParNewGC)) { 2036 warning("The UseParNewGC flag is deprecated and will likely be removed in a future release"); 2037 } 2038 if (FLAG_IS_CMDLINE(MaxGCMinorPauseMillis)) { 2039 warning("Using MaxGCMinorPauseMillis as minor pause goal is deprecated" 2040 "and will likely be removed in future release"); 2041 } 2042 if (FLAG_IS_CMDLINE(DefaultMaxRAMFraction)) { 2043 warning("DefaultMaxRAMFraction is deprecated and will likely be removed in a future release. " 2044 "Use MaxRAMFraction instead."); 2045 } 2046 } 2047 2048 // Check the consistency of vm_init_args 2049 bool Arguments::check_vm_args_consistency() { 2050 // Method for adding checks for flag consistency. 2051 // The intent is to warn the user of all possible conflicts, 2052 // before returning an error. 2053 // Note: Needs platform-dependent factoring. 2054 bool status = true; 2055 2056 if (TLABRefillWasteFraction == 0) { 2057 jio_fprintf(defaultStream::error_stream(), 2058 "TLABRefillWasteFraction should be a denominator, " 2059 "not " SIZE_FORMAT "\n", 2060 TLABRefillWasteFraction); 2061 status = false; 2062 } 2063 2064 if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) { 2065 MarkSweepAlwaysCompactCount = 1; // Move objects every gc. 2066 } 2067 2068 if (UseParallelOldGC && ParallelOldGCSplitALot) { 2069 // Settings to encourage splitting. 2070 if (!FLAG_IS_CMDLINE(NewRatio)) { 2071 if (FLAG_SET_CMDLINE(uintx, NewRatio, 2) != Flag::SUCCESS) { 2072 status = false; 2073 } 2074 } 2075 if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) { 2076 if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { 2077 status = false; 2078 } 2079 } 2080 } 2081 2082 if (!(UseParallelGC || UseParallelOldGC) && FLAG_IS_DEFAULT(ScavengeBeforeFullGC)) { 2083 FLAG_SET_DEFAULT(ScavengeBeforeFullGC, false); 2084 } 2085 2086 if (GCTimeLimit == 100) { 2087 // Turn off gc-overhead-limit-exceeded checks 2088 FLAG_SET_DEFAULT(UseGCOverheadLimit, false); 2089 } 2090 2091 status = status && check_gc_consistency(); 2092 2093 // CMS space iteration, which FLSVerifyAllHeapreferences entails, 2094 // insists that we hold the requisite locks so that the iteration is 2095 // MT-safe. For the verification at start-up and shut-down, we don't 2096 // yet have a good way of acquiring and releasing these locks, 2097 // which are not visible at the CollectedHeap level. We want to 2098 // be able to acquire these locks and then do the iteration rather 2099 // than just disable the lock verification. This will be fixed under 2100 // bug 4788986. 2101 if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) { 2102 if (VerifyDuringStartup) { 2103 warning("Heap verification at start-up disabled " 2104 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2105 VerifyDuringStartup = false; // Disable verification at start-up 2106 } 2107 2108 if (VerifyBeforeExit) { 2109 warning("Heap verification at shutdown disabled " 2110 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2111 VerifyBeforeExit = false; // Disable verification at shutdown 2112 } 2113 } 2114 2115 // Note: only executed in non-PRODUCT mode 2116 if (!UseAsyncConcMarkSweepGC && 2117 (ExplicitGCInvokesConcurrent || 2118 ExplicitGCInvokesConcurrentAndUnloadsClasses)) { 2119 jio_fprintf(defaultStream::error_stream(), 2120 "error: +ExplicitGCInvokesConcurrent[AndUnloadsClasses] conflicts" 2121 " with -UseAsyncConcMarkSweepGC"); 2122 status = false; 2123 } 2124 2125 if (PrintNMTStatistics) { 2126 #if INCLUDE_NMT 2127 if (MemTracker::tracking_level() == NMT_off) { 2128 #endif // INCLUDE_NMT 2129 warning("PrintNMTStatistics is disabled, because native memory tracking is not enabled"); 2130 PrintNMTStatistics = false; 2131 #if INCLUDE_NMT 2132 } 2133 #endif 2134 } 2135 2136 // Check lower bounds of the code cache 2137 // Template Interpreter code is approximately 3X larger in debug builds. 2138 uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3); 2139 if (InitialCodeCacheSize < (uintx)os::vm_page_size()) { 2140 jio_fprintf(defaultStream::error_stream(), 2141 "Invalid InitialCodeCacheSize=%dK. Must be at least %dK.\n", InitialCodeCacheSize/K, 2142 os::vm_page_size()/K); 2143 status = false; 2144 } else if (ReservedCodeCacheSize < InitialCodeCacheSize) { 2145 jio_fprintf(defaultStream::error_stream(), 2146 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n", 2147 ReservedCodeCacheSize/K, InitialCodeCacheSize/K); 2148 status = false; 2149 } else if (ReservedCodeCacheSize < min_code_cache_size) { 2150 jio_fprintf(defaultStream::error_stream(), 2151 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K, 2152 min_code_cache_size/K); 2153 status = false; 2154 } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) { 2155 // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported. 2156 jio_fprintf(defaultStream::error_stream(), 2157 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M, 2158 CODE_CACHE_SIZE_LIMIT/M); 2159 status = false; 2160 } else if (NonNMethodCodeHeapSize < min_code_cache_size){ 2161 jio_fprintf(defaultStream::error_stream(), 2162 "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K, 2163 min_code_cache_size/K); 2164 status = false; 2165 } else if ((!FLAG_IS_DEFAULT(NonNMethodCodeHeapSize) || !FLAG_IS_DEFAULT(ProfiledCodeHeapSize) || !FLAG_IS_DEFAULT(NonProfiledCodeHeapSize)) 2166 && (NonNMethodCodeHeapSize + NonProfiledCodeHeapSize + ProfiledCodeHeapSize) != ReservedCodeCacheSize) { 2167 jio_fprintf(defaultStream::error_stream(), 2168 "Invalid code heap sizes: NonNMethodCodeHeapSize(%dK) + ProfiledCodeHeapSize(%dK) + NonProfiledCodeHeapSize(%dK) = %dK. Must be equal to ReservedCodeCacheSize = %uK.\n", 2169 NonNMethodCodeHeapSize/K, ProfiledCodeHeapSize/K, NonProfiledCodeHeapSize/K, 2170 (NonNMethodCodeHeapSize + ProfiledCodeHeapSize + NonProfiledCodeHeapSize)/K, ReservedCodeCacheSize/K); 2171 status = false; 2172 } 2173 2174 if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) { 2175 warning("The VM option CICompilerCountPerCPU overrides CICompilerCount."); 2176 } 2177 2178 return status; 2179 } 2180 2181 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore, 2182 const char* option_type) { 2183 if (ignore) return false; 2184 2185 const char* spacer = " "; 2186 if (option_type == NULL) { 2187 option_type = ++spacer; // Set both to the empty string. 2188 } 2189 2190 if (os::obsolete_option(option)) { 2191 jio_fprintf(defaultStream::error_stream(), 2192 "Obsolete %s%soption: %s\n", option_type, spacer, 2193 option->optionString); 2194 return false; 2195 } else { 2196 jio_fprintf(defaultStream::error_stream(), 2197 "Unrecognized %s%soption: %s\n", option_type, spacer, 2198 option->optionString); 2199 return true; 2200 } 2201 } 2202 2203 static const char* user_assertion_options[] = { 2204 "-da", "-ea", "-disableassertions", "-enableassertions", 0 2205 }; 2206 2207 static const char* system_assertion_options[] = { 2208 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0 2209 }; 2210 2211 bool Arguments::parse_uintx(const char* value, 2212 uintx* uintx_arg, 2213 uintx min_size) { 2214 2215 // Check the sign first since atomull() parses only unsigned values. 2216 bool value_is_positive = !(*value == '-'); 2217 2218 if (value_is_positive) { 2219 julong n; 2220 bool good_return = atomull(value, &n); 2221 if (good_return) { 2222 bool above_minimum = n >= min_size; 2223 bool value_is_too_large = n > max_uintx; 2224 2225 if (above_minimum && !value_is_too_large) { 2226 *uintx_arg = n; 2227 return true; 2228 } 2229 } 2230 } 2231 return false; 2232 } 2233 2234 Arguments::ArgsRange Arguments::parse_memory_size(const char* s, 2235 julong* long_arg, 2236 julong min_size) { 2237 if (!atomull(s, long_arg)) return arg_unreadable; 2238 return check_memory_size(*long_arg, min_size); 2239 } 2240 2241 // Parse JavaVMInitArgs structure 2242 2243 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args, 2244 const JavaVMInitArgs *java_options_args, 2245 const JavaVMInitArgs *cmd_line_args) { 2246 // For components of the system classpath. 2247 SysClassPath scp(Arguments::get_sysclasspath()); 2248 bool scp_assembly_required = false; 2249 2250 // Save default settings for some mode flags 2251 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 2252 Arguments::_UseOnStackReplacement = UseOnStackReplacement; 2253 Arguments::_ClipInlining = ClipInlining; 2254 Arguments::_BackgroundCompilation = BackgroundCompilation; 2255 if (TieredCompilation) { 2256 Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog; 2257 Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold; 2258 } 2259 2260 // Setup flags for mixed which is the default 2261 set_mode_flags(_mixed); 2262 2263 // Parse args structure generated from JAVA_TOOL_OPTIONS environment 2264 // variable (if present). 2265 jint result = parse_each_vm_init_arg( 2266 java_tool_options_args, &scp, &scp_assembly_required, Flag::ENVIRON_VAR); 2267 if (result != JNI_OK) { 2268 return result; 2269 } 2270 2271 // Parse args structure generated from the command line flags. 2272 result = parse_each_vm_init_arg(cmd_line_args, &scp, &scp_assembly_required, 2273 Flag::COMMAND_LINE); 2274 if (result != JNI_OK) { 2275 return result; 2276 } 2277 2278 // Parse args structure generated from the _JAVA_OPTIONS environment 2279 // variable (if present) (mimics classic VM) 2280 result = parse_each_vm_init_arg( 2281 java_options_args, &scp, &scp_assembly_required, Flag::ENVIRON_VAR); 2282 if (result != JNI_OK) { 2283 return result; 2284 } 2285 2286 // Do final processing now that all arguments have been parsed 2287 result = finalize_vm_init_args(&scp, scp_assembly_required); 2288 if (result != JNI_OK) { 2289 return result; 2290 } 2291 2292 return JNI_OK; 2293 } 2294 2295 // Checks if name in command-line argument -agent{lib,path}:name[=options] 2296 // represents a valid JDWP agent. is_path==true denotes that we 2297 // are dealing with -agentpath (case where name is a path), otherwise with 2298 // -agentlib 2299 bool valid_jdwp_agent(char *name, bool is_path) { 2300 char *_name; 2301 const char *_jdwp = "jdwp"; 2302 size_t _len_jdwp, _len_prefix; 2303 2304 if (is_path) { 2305 if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) { 2306 return false; 2307 } 2308 2309 _name++; // skip past last path separator 2310 _len_prefix = strlen(JNI_LIB_PREFIX); 2311 2312 if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) { 2313 return false; 2314 } 2315 2316 _name += _len_prefix; 2317 _len_jdwp = strlen(_jdwp); 2318 2319 if (strncmp(_name, _jdwp, _len_jdwp) == 0) { 2320 _name += _len_jdwp; 2321 } 2322 else { 2323 return false; 2324 } 2325 2326 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) { 2327 return false; 2328 } 2329 2330 return true; 2331 } 2332 2333 if (strcmp(name, _jdwp) == 0) { 2334 return true; 2335 } 2336 2337 return false; 2338 } 2339 2340 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, 2341 SysClassPath* scp_p, 2342 bool* scp_assembly_required_p, 2343 Flag::Flags origin) { 2344 // Remaining part of option string 2345 const char* tail; 2346 2347 // iterate over arguments 2348 for (int index = 0; index < args->nOptions; index++) { 2349 bool is_absolute_path = false; // for -agentpath vs -agentlib 2350 2351 const JavaVMOption* option = args->options + index; 2352 2353 if (!match_option(option, "-Djava.class.path", &tail) && 2354 !match_option(option, "-Dsun.java.command", &tail) && 2355 !match_option(option, "-Dsun.java.launcher", &tail)) { 2356 2357 // add all jvm options to the jvm_args string. This string 2358 // is used later to set the java.vm.args PerfData string constant. 2359 // the -Djava.class.path and the -Dsun.java.command options are 2360 // omitted from jvm_args string as each have their own PerfData 2361 // string constant object. 2362 build_jvm_args(option->optionString); 2363 } 2364 2365 // -verbose:[class/gc/jni] 2366 if (match_option(option, "-verbose", &tail)) { 2367 if (!strcmp(tail, ":class") || !strcmp(tail, "")) { 2368 if (FLAG_SET_CMDLINE(bool, TraceClassLoading, true) != Flag::SUCCESS) { 2369 return JNI_EINVAL; 2370 } 2371 if (FLAG_SET_CMDLINE(bool, TraceClassUnloading, true) != Flag::SUCCESS) { 2372 return JNI_EINVAL; 2373 } 2374 } else if (!strcmp(tail, ":gc")) { 2375 if (FLAG_SET_CMDLINE(bool, PrintGC, true) != Flag::SUCCESS) { 2376 return JNI_EINVAL; 2377 } 2378 } else if (!strcmp(tail, ":jni")) { 2379 if (FLAG_SET_CMDLINE(bool, PrintJNIResolving, true) != Flag::SUCCESS) { 2380 return JNI_EINVAL; 2381 } 2382 } 2383 // -da / -ea / -disableassertions / -enableassertions 2384 // These accept an optional class/package name separated by a colon, e.g., 2385 // -da:java.lang.Thread. 2386 } else if (match_option(option, user_assertion_options, &tail, true)) { 2387 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2388 if (*tail == '\0') { 2389 JavaAssertions::setUserClassDefault(enable); 2390 } else { 2391 assert(*tail == ':', "bogus match by match_option()"); 2392 JavaAssertions::addOption(tail + 1, enable); 2393 } 2394 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions 2395 } else if (match_option(option, system_assertion_options, &tail, false)) { 2396 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2397 JavaAssertions::setSystemClassDefault(enable); 2398 // -bootclasspath: 2399 } else if (match_option(option, "-Xbootclasspath:", &tail)) { 2400 scp_p->reset_path(tail); 2401 *scp_assembly_required_p = true; 2402 // -bootclasspath/a: 2403 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) { 2404 scp_p->add_suffix(tail); 2405 *scp_assembly_required_p = true; 2406 // -bootclasspath/p: 2407 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) { 2408 scp_p->add_prefix(tail); 2409 *scp_assembly_required_p = true; 2410 // -Xrun 2411 } else if (match_option(option, "-Xrun", &tail)) { 2412 if (tail != NULL) { 2413 const char* pos = strchr(tail, ':'); 2414 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2415 char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len); 2416 name[len] = '\0'; 2417 2418 char *options = NULL; 2419 if(pos != NULL) { 2420 size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied. 2421 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2, mtInternal), pos+1, len2); 2422 } 2423 #if !INCLUDE_JVMTI 2424 if (strcmp(name, "jdwp") == 0) { 2425 jio_fprintf(defaultStream::error_stream(), 2426 "Debugging agents are not supported in this VM\n"); 2427 return JNI_ERR; 2428 } 2429 #endif // !INCLUDE_JVMTI 2430 add_init_library(name, options); 2431 } 2432 // -agentlib and -agentpath 2433 } else if (match_option(option, "-agentlib:", &tail) || 2434 (is_absolute_path = match_option(option, "-agentpath:", &tail))) { 2435 if(tail != NULL) { 2436 const char* pos = strchr(tail, '='); 2437 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2438 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len); 2439 name[len] = '\0'; 2440 2441 char *options = NULL; 2442 if(pos != NULL) { 2443 options = os::strdup_check_oom(pos + 1, mtInternal); 2444 } 2445 #if !INCLUDE_JVMTI 2446 if (valid_jdwp_agent(name, is_absolute_path)) { 2447 jio_fprintf(defaultStream::error_stream(), 2448 "Debugging agents are not supported in this VM\n"); 2449 return JNI_ERR; 2450 } 2451 #endif // !INCLUDE_JVMTI 2452 add_init_agent(name, options, is_absolute_path); 2453 } 2454 // -javaagent 2455 } else if (match_option(option, "-javaagent:", &tail)) { 2456 #if !INCLUDE_JVMTI 2457 jio_fprintf(defaultStream::error_stream(), 2458 "Instrumentation agents are not supported in this VM\n"); 2459 return JNI_ERR; 2460 #else 2461 if(tail != NULL) { 2462 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtInternal), tail); 2463 add_init_agent("instrument", options, false); 2464 } 2465 #endif // !INCLUDE_JVMTI 2466 // -Xnoclassgc 2467 } else if (match_option(option, "-Xnoclassgc")) { 2468 if (FLAG_SET_CMDLINE(bool, ClassUnloading, false) != Flag::SUCCESS) { 2469 return JNI_EINVAL; 2470 } 2471 // -Xconcgc 2472 } else if (match_option(option, "-Xconcgc")) { 2473 if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true) != Flag::SUCCESS) { 2474 return JNI_EINVAL; 2475 } 2476 // -Xnoconcgc 2477 } else if (match_option(option, "-Xnoconcgc")) { 2478 if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false) != Flag::SUCCESS) { 2479 return JNI_EINVAL; 2480 } 2481 // -Xbatch 2482 } else if (match_option(option, "-Xbatch")) { 2483 if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { 2484 return JNI_EINVAL; 2485 } 2486 // -Xmn for compatibility with other JVM vendors 2487 } else if (match_option(option, "-Xmn", &tail)) { 2488 julong long_initial_young_size = 0; 2489 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1); 2490 if (errcode != arg_in_range) { 2491 jio_fprintf(defaultStream::error_stream(), 2492 "Invalid initial young generation size: %s\n", option->optionString); 2493 describe_range_error(errcode); 2494 return JNI_EINVAL; 2495 } 2496 if (FLAG_SET_CMDLINE(size_t, MaxNewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { 2497 return JNI_EINVAL; 2498 } 2499 if (FLAG_SET_CMDLINE(size_t, NewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { 2500 return JNI_EINVAL; 2501 } 2502 // -Xms 2503 } else if (match_option(option, "-Xms", &tail)) { 2504 julong long_initial_heap_size = 0; 2505 // an initial heap size of 0 means automatically determine 2506 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0); 2507 if (errcode != arg_in_range) { 2508 jio_fprintf(defaultStream::error_stream(), 2509 "Invalid initial heap size: %s\n", option->optionString); 2510 describe_range_error(errcode); 2511 return JNI_EINVAL; 2512 } 2513 set_min_heap_size((size_t)long_initial_heap_size); 2514 // Currently the minimum size and the initial heap sizes are the same. 2515 // Can be overridden with -XX:InitialHeapSize. 2516 if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, (size_t)long_initial_heap_size) != Flag::SUCCESS) { 2517 return JNI_EINVAL; 2518 } 2519 // -Xmx 2520 } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) { 2521 julong long_max_heap_size = 0; 2522 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1); 2523 if (errcode != arg_in_range) { 2524 jio_fprintf(defaultStream::error_stream(), 2525 "Invalid maximum heap size: %s\n", option->optionString); 2526 describe_range_error(errcode); 2527 return JNI_EINVAL; 2528 } 2529 if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, (size_t)long_max_heap_size) != Flag::SUCCESS) { 2530 return JNI_EINVAL; 2531 } 2532 // Xmaxf 2533 } else if (match_option(option, "-Xmaxf", &tail)) { 2534 char* err; 2535 int maxf = (int)(strtod(tail, &err) * 100); 2536 if (*err != '\0' || *tail == '\0') { 2537 jio_fprintf(defaultStream::error_stream(), 2538 "Bad max heap free percentage size: %s\n", 2539 option->optionString); 2540 return JNI_EINVAL; 2541 } else { 2542 if (FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf) != Flag::SUCCESS) { 2543 return JNI_EINVAL; 2544 } 2545 } 2546 // Xminf 2547 } else if (match_option(option, "-Xminf", &tail)) { 2548 char* err; 2549 int minf = (int)(strtod(tail, &err) * 100); 2550 if (*err != '\0' || *tail == '\0') { 2551 jio_fprintf(defaultStream::error_stream(), 2552 "Bad min heap free percentage size: %s\n", 2553 option->optionString); 2554 return JNI_EINVAL; 2555 } else { 2556 if (FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf) != Flag::SUCCESS) { 2557 return JNI_EINVAL; 2558 } 2559 } 2560 // -Xss 2561 } else if (match_option(option, "-Xss", &tail)) { 2562 julong long_ThreadStackSize = 0; 2563 ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000); 2564 if (errcode != arg_in_range) { 2565 jio_fprintf(defaultStream::error_stream(), 2566 "Invalid thread stack size: %s\n", option->optionString); 2567 describe_range_error(errcode); 2568 return JNI_EINVAL; 2569 } 2570 // Internally track ThreadStackSize in units of 1024 bytes. 2571 if (FLAG_SET_CMDLINE(intx, ThreadStackSize, 2572 round_to((int)long_ThreadStackSize, K) / K) != Flag::SUCCESS) { 2573 return JNI_EINVAL; 2574 } 2575 // -Xoss, -Xsqnopause, -Xoptimize, -Xboundthreads 2576 } else if (match_option(option, "-Xoss", &tail) || 2577 match_option(option, "-Xsqnopause") || 2578 match_option(option, "-Xoptimize") || 2579 match_option(option, "-Xboundthreads")) { 2580 // All these options are deprecated in JDK 9 and will be removed in a future release 2581 char version[256]; 2582 JDK_Version::jdk(9).to_string(version, sizeof(version)); 2583 warning("ignoring option %s; support was removed in %s", option->optionString, version); 2584 } else if (match_option(option, "-XX:CodeCacheExpansionSize=", &tail)) { 2585 julong long_CodeCacheExpansionSize = 0; 2586 ArgsRange errcode = parse_memory_size(tail, &long_CodeCacheExpansionSize, os::vm_page_size()); 2587 if (errcode != arg_in_range) { 2588 jio_fprintf(defaultStream::error_stream(), 2589 "Invalid argument: %s. Must be at least %luK.\n", option->optionString, 2590 os::vm_page_size()/K); 2591 return JNI_EINVAL; 2592 } 2593 if (FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx)long_CodeCacheExpansionSize) != Flag::SUCCESS) { 2594 return JNI_EINVAL; 2595 } 2596 } else if (match_option(option, "-Xmaxjitcodesize", &tail) || 2597 match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) { 2598 julong long_ReservedCodeCacheSize = 0; 2599 2600 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1); 2601 if (errcode != arg_in_range) { 2602 jio_fprintf(defaultStream::error_stream(), 2603 "Invalid maximum code cache size: %s.\n", option->optionString); 2604 return JNI_EINVAL; 2605 } 2606 if (FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize) != Flag::SUCCESS) { 2607 return JNI_EINVAL; 2608 } 2609 // -XX:NonNMethodCodeHeapSize= 2610 } else if (match_option(option, "-XX:NonNMethodCodeHeapSize=", &tail)) { 2611 julong long_NonNMethodCodeHeapSize = 0; 2612 2613 ArgsRange errcode = parse_memory_size(tail, &long_NonNMethodCodeHeapSize, 1); 2614 if (errcode != arg_in_range) { 2615 jio_fprintf(defaultStream::error_stream(), 2616 "Invalid maximum non-nmethod code heap size: %s.\n", option->optionString); 2617 return JNI_EINVAL; 2618 } 2619 if (FLAG_SET_CMDLINE(uintx, NonNMethodCodeHeapSize, (uintx)long_NonNMethodCodeHeapSize) != Flag::SUCCESS) { 2620 return JNI_EINVAL; 2621 } 2622 // -XX:ProfiledCodeHeapSize= 2623 } else if (match_option(option, "-XX:ProfiledCodeHeapSize=", &tail)) { 2624 julong long_ProfiledCodeHeapSize = 0; 2625 2626 ArgsRange errcode = parse_memory_size(tail, &long_ProfiledCodeHeapSize, 1); 2627 if (errcode != arg_in_range) { 2628 jio_fprintf(defaultStream::error_stream(), 2629 "Invalid maximum profiled code heap size: %s.\n", option->optionString); 2630 return JNI_EINVAL; 2631 } 2632 if (FLAG_SET_CMDLINE(uintx, ProfiledCodeHeapSize, (uintx)long_ProfiledCodeHeapSize) != Flag::SUCCESS) { 2633 return JNI_EINVAL; 2634 } 2635 // -XX:NonProfiledCodeHeapSizee= 2636 } else if (match_option(option, "-XX:NonProfiledCodeHeapSize=", &tail)) { 2637 julong long_NonProfiledCodeHeapSize = 0; 2638 2639 ArgsRange errcode = parse_memory_size(tail, &long_NonProfiledCodeHeapSize, 1); 2640 if (errcode != arg_in_range) { 2641 jio_fprintf(defaultStream::error_stream(), 2642 "Invalid maximum non-profiled code heap size: %s.\n", option->optionString); 2643 return JNI_EINVAL; 2644 } 2645 if (FLAG_SET_CMDLINE(uintx, NonProfiledCodeHeapSize, (uintx)long_NonProfiledCodeHeapSize) != Flag::SUCCESS) { 2646 return JNI_EINVAL; 2647 } 2648 // -green 2649 } else if (match_option(option, "-green")) { 2650 jio_fprintf(defaultStream::error_stream(), 2651 "Green threads support not available\n"); 2652 return JNI_EINVAL; 2653 // -native 2654 } else if (match_option(option, "-native")) { 2655 // HotSpot always uses native threads, ignore silently for compatibility 2656 // -Xrs 2657 } else if (match_option(option, "-Xrs")) { 2658 // Classic/EVM option, new functionality 2659 if (FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true) != Flag::SUCCESS) { 2660 return JNI_EINVAL; 2661 } 2662 } else if (match_option(option, "-Xusealtsigs")) { 2663 // change default internal VM signals used - lower case for back compat 2664 if (FLAG_SET_CMDLINE(bool, UseAltSigs, true) != Flag::SUCCESS) { 2665 return JNI_EINVAL; 2666 } 2667 // -Xprof 2668 } else if (match_option(option, "-Xprof")) { 2669 #if INCLUDE_FPROF 2670 _has_profile = true; 2671 #else // INCLUDE_FPROF 2672 jio_fprintf(defaultStream::error_stream(), 2673 "Flat profiling is not supported in this VM.\n"); 2674 return JNI_ERR; 2675 #endif // INCLUDE_FPROF 2676 // -Xconcurrentio 2677 } else if (match_option(option, "-Xconcurrentio")) { 2678 if (FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true) != Flag::SUCCESS) { 2679 return JNI_EINVAL; 2680 } 2681 if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { 2682 return JNI_EINVAL; 2683 } 2684 if (FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1) != Flag::SUCCESS) { 2685 return JNI_EINVAL; 2686 } 2687 if (FLAG_SET_CMDLINE(bool, UseTLAB, false) != Flag::SUCCESS) { 2688 return JNI_EINVAL; 2689 } 2690 if (FLAG_SET_CMDLINE(size_t, NewSizeThreadIncrease, 16 * K) != Flag::SUCCESS) { // 20Kb per thread added to new generation 2691 return JNI_EINVAL; 2692 } 2693 2694 // -Xinternalversion 2695 } else if (match_option(option, "-Xinternalversion")) { 2696 jio_fprintf(defaultStream::output_stream(), "%s\n", 2697 VM_Version::internal_vm_info_string()); 2698 vm_exit(0); 2699 #ifndef PRODUCT 2700 // -Xprintflags 2701 } else if (match_option(option, "-Xprintflags")) { 2702 CommandLineFlags::printFlags(tty, false); 2703 vm_exit(0); 2704 #endif 2705 // -D 2706 } else if (match_option(option, "-D", &tail)) { 2707 const char* value; 2708 if (match_option(option, "-Djava.endorsed.dirs=", &value) && 2709 *value!= '\0' && strcmp(value, "\"\"") != 0) { 2710 // abort if -Djava.endorsed.dirs is set 2711 jio_fprintf(defaultStream::output_stream(), 2712 "-Djava.endorsed.dirs=%s is not supported. Endorsed standards and standalone APIs\n" 2713 "in modular form will be supported via the concept of upgradeable modules.\n", value); 2714 return JNI_EINVAL; 2715 } 2716 if (match_option(option, "-Djava.ext.dirs=", &value) && 2717 *value != '\0' && strcmp(value, "\"\"") != 0) { 2718 // abort if -Djava.ext.dirs is set 2719 jio_fprintf(defaultStream::output_stream(), 2720 "-Djava.ext.dirs=%s is not supported. Use -classpath instead.\n", value); 2721 return JNI_EINVAL; 2722 } 2723 2724 if (!add_property(tail)) { 2725 return JNI_ENOMEM; 2726 } 2727 // Out of the box management support 2728 if (match_option(option, "-Dcom.sun.management", &tail)) { 2729 #if INCLUDE_MANAGEMENT 2730 if (FLAG_SET_CMDLINE(bool, ManagementServer, true) != Flag::SUCCESS) { 2731 return JNI_EINVAL; 2732 } 2733 #else 2734 jio_fprintf(defaultStream::output_stream(), 2735 "-Dcom.sun.management is not supported in this VM.\n"); 2736 return JNI_ERR; 2737 #endif 2738 } 2739 // -Xint 2740 } else if (match_option(option, "-Xint")) { 2741 set_mode_flags(_int); 2742 // -Xmixed 2743 } else if (match_option(option, "-Xmixed")) { 2744 set_mode_flags(_mixed); 2745 // -Xcomp 2746 } else if (match_option(option, "-Xcomp")) { 2747 // for testing the compiler; turn off all flags that inhibit compilation 2748 set_mode_flags(_comp); 2749 // -Xshare:dump 2750 } else if (match_option(option, "-Xshare:dump")) { 2751 if (FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true) != Flag::SUCCESS) { 2752 return JNI_EINVAL; 2753 } 2754 set_mode_flags(_int); // Prevent compilation, which creates objects 2755 // -Xshare:on 2756 } else if (match_option(option, "-Xshare:on")) { 2757 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 2758 return JNI_EINVAL; 2759 } 2760 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { 2761 return JNI_EINVAL; 2762 } 2763 // -Xshare:auto 2764 } else if (match_option(option, "-Xshare:auto")) { 2765 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 2766 return JNI_EINVAL; 2767 } 2768 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { 2769 return JNI_EINVAL; 2770 } 2771 // -Xshare:off 2772 } else if (match_option(option, "-Xshare:off")) { 2773 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, false) != Flag::SUCCESS) { 2774 return JNI_EINVAL; 2775 } 2776 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { 2777 return JNI_EINVAL; 2778 } 2779 // -Xverify 2780 } else if (match_option(option, "-Xverify", &tail)) { 2781 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) { 2782 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true) != Flag::SUCCESS) { 2783 return JNI_EINVAL; 2784 } 2785 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { 2786 return JNI_EINVAL; 2787 } 2788 } else if (strcmp(tail, ":remote") == 0) { 2789 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { 2790 return JNI_EINVAL; 2791 } 2792 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { 2793 return JNI_EINVAL; 2794 } 2795 } else if (strcmp(tail, ":none") == 0) { 2796 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { 2797 return JNI_EINVAL; 2798 } 2799 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false) != Flag::SUCCESS) { 2800 return JNI_EINVAL; 2801 } 2802 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) { 2803 return JNI_EINVAL; 2804 } 2805 // -Xdebug 2806 } else if (match_option(option, "-Xdebug")) { 2807 // note this flag has been used, then ignore 2808 set_xdebug_mode(true); 2809 // -Xnoagent 2810 } else if (match_option(option, "-Xnoagent")) { 2811 // For compatibility with classic. HotSpot refuses to load the old style agent.dll. 2812 } else if (match_option(option, "-Xloggc:", &tail)) { 2813 // Redirect GC output to the file. -Xloggc:<filename> 2814 // ostream_init_log(), when called will use this filename 2815 // to initialize a fileStream. 2816 _gc_log_filename = os::strdup_check_oom(tail); 2817 if (!is_filename_valid(_gc_log_filename)) { 2818 jio_fprintf(defaultStream::output_stream(), 2819 "Invalid file name for use with -Xloggc: Filename can only contain the " 2820 "characters [A-Z][a-z][0-9]-_.%%[p|t] but it has been %s\n" 2821 "Note %%p or %%t can only be used once\n", _gc_log_filename); 2822 return JNI_EINVAL; 2823 } 2824 if (FLAG_SET_CMDLINE(bool, PrintGC, true) != Flag::SUCCESS) { 2825 return JNI_EINVAL; 2826 } 2827 if (FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true) != Flag::SUCCESS) { 2828 return JNI_EINVAL; 2829 } 2830 // JNI hooks 2831 } else if (match_option(option, "-Xcheck", &tail)) { 2832 if (!strcmp(tail, ":jni")) { 2833 #if !INCLUDE_JNI_CHECK 2834 warning("JNI CHECKING is not supported in this VM"); 2835 #else 2836 CheckJNICalls = true; 2837 #endif // INCLUDE_JNI_CHECK 2838 } else if (is_bad_option(option, args->ignoreUnrecognized, 2839 "check")) { 2840 return JNI_EINVAL; 2841 } 2842 } else if (match_option(option, "vfprintf")) { 2843 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo); 2844 } else if (match_option(option, "exit")) { 2845 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo); 2846 } else if (match_option(option, "abort")) { 2847 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo); 2848 // -XX:+AggressiveHeap 2849 } else if (match_option(option, "-XX:+AggressiveHeap")) { 2850 2851 // This option inspects the machine and attempts to set various 2852 // parameters to be optimal for long-running, memory allocation 2853 // intensive jobs. It is intended for machines with large 2854 // amounts of cpu and memory. 2855 2856 // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit 2857 // VM, but we may not be able to represent the total physical memory 2858 // available (like having 8gb of memory on a box but using a 32bit VM). 2859 // Thus, we need to make sure we're using a julong for intermediate 2860 // calculations. 2861 julong initHeapSize; 2862 julong total_memory = os::physical_memory(); 2863 2864 if (total_memory < (julong)256*M) { 2865 jio_fprintf(defaultStream::error_stream(), 2866 "You need at least 256mb of memory to use -XX:+AggressiveHeap\n"); 2867 vm_exit(1); 2868 } 2869 2870 // The heap size is half of available memory, or (at most) 2871 // all of possible memory less 160mb (leaving room for the OS 2872 // when using ISM). This is the maximum; because adaptive sizing 2873 // is turned on below, the actual space used may be smaller. 2874 2875 initHeapSize = MIN2(total_memory / (julong)2, 2876 total_memory - (julong)160*M); 2877 2878 initHeapSize = limit_by_allocatable_memory(initHeapSize); 2879 2880 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 2881 if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, initHeapSize) != Flag::SUCCESS) { 2882 return JNI_EINVAL; 2883 } 2884 if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, initHeapSize) != Flag::SUCCESS) { 2885 return JNI_EINVAL; 2886 } 2887 // Currently the minimum size and the initial heap sizes are the same. 2888 set_min_heap_size(initHeapSize); 2889 } 2890 if (FLAG_IS_DEFAULT(NewSize)) { 2891 // Make the young generation 3/8ths of the total heap. 2892 if (FLAG_SET_CMDLINE(size_t, NewSize, 2893 ((julong)MaxHeapSize / (julong)8) * (julong)3) != Flag::SUCCESS) { 2894 return JNI_EINVAL; 2895 } 2896 if (FLAG_SET_CMDLINE(size_t, MaxNewSize, NewSize) != Flag::SUCCESS) { 2897 return JNI_EINVAL; 2898 } 2899 } 2900 2901 #if !defined(_ALLBSD_SOURCE) && !defined(AIX) // UseLargePages is not yet supported on BSD and AIX. 2902 FLAG_SET_DEFAULT(UseLargePages, true); 2903 #endif 2904 2905 // Increase some data structure sizes for efficiency 2906 if (FLAG_SET_CMDLINE(size_t, BaseFootPrintEstimate, MaxHeapSize) != Flag::SUCCESS) { 2907 return JNI_EINVAL; 2908 } 2909 if (FLAG_SET_CMDLINE(bool, ResizeTLAB, false) != Flag::SUCCESS) { 2910 return JNI_EINVAL; 2911 } 2912 if (FLAG_SET_CMDLINE(size_t, TLABSize, 256*K) != Flag::SUCCESS) { 2913 return JNI_EINVAL; 2914 } 2915 2916 // See the OldPLABSize comment below, but replace 'after promotion' 2917 // with 'after copying'. YoungPLABSize is the size of the survivor 2918 // space per-gc-thread buffers. The default is 4kw. 2919 if (FLAG_SET_CMDLINE(size_t, YoungPLABSize, 256*K) != Flag::SUCCESS) { // Note: this is in words 2920 return JNI_EINVAL; 2921 } 2922 2923 // OldPLABSize is the size of the buffers in the old gen that 2924 // UseParallelGC uses to promote live data that doesn't fit in the 2925 // survivor spaces. At any given time, there's one for each gc thread. 2926 // The default size is 1kw. These buffers are rarely used, since the 2927 // survivor spaces are usually big enough. For specjbb, however, there 2928 // are occasions when there's lots of live data in the young gen 2929 // and we end up promoting some of it. We don't have a definite 2930 // explanation for why bumping OldPLABSize helps, but the theory 2931 // is that a bigger PLAB results in retaining something like the 2932 // original allocation order after promotion, which improves mutator 2933 // locality. A minor effect may be that larger PLABs reduce the 2934 // number of PLAB allocation events during gc. The value of 8kw 2935 // was arrived at by experimenting with specjbb. 2936 if (FLAG_SET_CMDLINE(size_t, OldPLABSize, 8*K) != Flag::SUCCESS) { // Note: this is in words 2937 return JNI_EINVAL; 2938 } 2939 2940 // Enable parallel GC and adaptive generation sizing 2941 if (FLAG_SET_CMDLINE(bool, UseParallelGC, true) != Flag::SUCCESS) { 2942 return JNI_EINVAL; 2943 } 2944 FLAG_SET_DEFAULT(ParallelGCThreads, 2945 Abstract_VM_Version::parallel_worker_threads()); 2946 2947 // Encourage steady state memory management 2948 if (FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100) != Flag::SUCCESS) { 2949 return JNI_EINVAL; 2950 } 2951 2952 // This appears to improve mutator locality 2953 if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { 2954 return JNI_EINVAL; 2955 } 2956 2957 // Get around early Solaris scheduling bug 2958 // (affinity vs other jobs on system) 2959 // but disallow DR and offlining (5008695). 2960 if (FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true) != Flag::SUCCESS) { 2961 return JNI_EINVAL; 2962 } 2963 2964 // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure; 2965 // and the last option wins. 2966 } else if (match_option(option, "-XX:+NeverTenure")) { 2967 if (FLAG_SET_CMDLINE(bool, NeverTenure, true) != Flag::SUCCESS) { 2968 return JNI_EINVAL; 2969 } 2970 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { 2971 return JNI_EINVAL; 2972 } 2973 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1) != Flag::SUCCESS) { 2974 return JNI_EINVAL; 2975 } 2976 } else if (match_option(option, "-XX:+AlwaysTenure")) { 2977 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 2978 return JNI_EINVAL; 2979 } 2980 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { 2981 return JNI_EINVAL; 2982 } 2983 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0) != Flag::SUCCESS) { 2984 return JNI_EINVAL; 2985 } 2986 } else if (match_option(option, "-XX:MaxTenuringThreshold=", &tail)) { 2987 uintx max_tenuring_thresh = 0; 2988 if (!parse_uintx(tail, &max_tenuring_thresh, 0)) { 2989 jio_fprintf(defaultStream::error_stream(), 2990 "Improperly specified VM option \'MaxTenuringThreshold=%s\'\n", tail); 2991 return JNI_EINVAL; 2992 } 2993 2994 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, max_tenuring_thresh) != Flag::SUCCESS) { 2995 return JNI_EINVAL; 2996 } 2997 2998 if (MaxTenuringThreshold == 0) { 2999 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3000 return JNI_EINVAL; 3001 } 3002 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { 3003 return JNI_EINVAL; 3004 } 3005 } else { 3006 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3007 return JNI_EINVAL; 3008 } 3009 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { 3010 return JNI_EINVAL; 3011 } 3012 } 3013 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr")) { 3014 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false) != Flag::SUCCESS) { 3015 return JNI_EINVAL; 3016 } 3017 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true) != Flag::SUCCESS) { 3018 return JNI_EINVAL; 3019 } 3020 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout")) { 3021 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false) != Flag::SUCCESS) { 3022 return JNI_EINVAL; 3023 } 3024 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true) != Flag::SUCCESS) { 3025 return JNI_EINVAL; 3026 } 3027 } else if (match_option(option, "-XX:+ExtendedDTraceProbes")) { 3028 #if defined(DTRACE_ENABLED) 3029 if (FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true) != Flag::SUCCESS) { 3030 return JNI_EINVAL; 3031 } 3032 if (FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true) != Flag::SUCCESS) { 3033 return JNI_EINVAL; 3034 } 3035 if (FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true) != Flag::SUCCESS) { 3036 return JNI_EINVAL; 3037 } 3038 if (FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true) != Flag::SUCCESS) { 3039 return JNI_EINVAL; 3040 } 3041 #else // defined(DTRACE_ENABLED) 3042 jio_fprintf(defaultStream::error_stream(), 3043 "ExtendedDTraceProbes flag is not applicable for this configuration\n"); 3044 return JNI_EINVAL; 3045 #endif // defined(DTRACE_ENABLED) 3046 #ifdef ASSERT 3047 } else if (match_option(option, "-XX:+FullGCALot")) { 3048 if (FLAG_SET_CMDLINE(bool, FullGCALot, true) != Flag::SUCCESS) { 3049 return JNI_EINVAL; 3050 } 3051 // disable scavenge before parallel mark-compact 3052 if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { 3053 return JNI_EINVAL; 3054 } 3055 #endif 3056 } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) || 3057 match_option(option, "-XX:G1MarkStackSize=", &tail)) { 3058 julong stack_size = 0; 3059 ArgsRange errcode = parse_memory_size(tail, &stack_size, 1); 3060 if (errcode != arg_in_range) { 3061 jio_fprintf(defaultStream::error_stream(), 3062 "Invalid mark stack size: %s\n", option->optionString); 3063 describe_range_error(errcode); 3064 return JNI_EINVAL; 3065 } 3066 jio_fprintf(defaultStream::error_stream(), 3067 "Please use -XX:MarkStackSize in place of " 3068 "-XX:CMSMarkStackSize or -XX:G1MarkStackSize in the future\n"); 3069 if (FLAG_SET_CMDLINE(size_t, MarkStackSize, stack_size) != Flag::SUCCESS) { 3070 return JNI_EINVAL; 3071 } 3072 } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) { 3073 julong max_stack_size = 0; 3074 ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1); 3075 if (errcode != arg_in_range) { 3076 jio_fprintf(defaultStream::error_stream(), 3077 "Invalid maximum mark stack size: %s\n", 3078 option->optionString); 3079 describe_range_error(errcode); 3080 return JNI_EINVAL; 3081 } 3082 jio_fprintf(defaultStream::error_stream(), 3083 "Please use -XX:MarkStackSizeMax in place of " 3084 "-XX:CMSMarkStackSizeMax in the future\n"); 3085 if (FLAG_SET_CMDLINE(size_t, MarkStackSizeMax, max_stack_size) != Flag::SUCCESS) { 3086 return JNI_EINVAL; 3087 } 3088 } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) || 3089 match_option(option, "-XX:ParallelCMSThreads=", &tail)) { 3090 uintx conc_threads = 0; 3091 if (!parse_uintx(tail, &conc_threads, 1)) { 3092 jio_fprintf(defaultStream::error_stream(), 3093 "Invalid concurrent threads: %s\n", option->optionString); 3094 return JNI_EINVAL; 3095 } 3096 jio_fprintf(defaultStream::error_stream(), 3097 "Please use -XX:ConcGCThreads in place of " 3098 "-XX:ParallelMarkingThreads or -XX:ParallelCMSThreads in the future\n"); 3099 if (FLAG_SET_CMDLINE(uint, ConcGCThreads, conc_threads) != Flag::SUCCESS) { 3100 return JNI_EINVAL; 3101 } 3102 } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) { 3103 julong max_direct_memory_size = 0; 3104 ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0); 3105 if (errcode != arg_in_range) { 3106 jio_fprintf(defaultStream::error_stream(), 3107 "Invalid maximum direct memory size: %s\n", 3108 option->optionString); 3109 describe_range_error(errcode); 3110 return JNI_EINVAL; 3111 } 3112 if (FLAG_SET_CMDLINE(size_t, MaxDirectMemorySize, max_direct_memory_size) != Flag::SUCCESS) { 3113 return JNI_EINVAL; 3114 } 3115 #if !INCLUDE_MANAGEMENT 3116 } else if (match_option(option, "-XX:+ManagementServer")) { 3117 jio_fprintf(defaultStream::error_stream(), 3118 "ManagementServer is not supported in this VM.\n"); 3119 return JNI_ERR; 3120 #endif // INCLUDE_MANAGEMENT 3121 // CreateMinidumpOnCrash is removed, and replaced by CreateCoredumpOnCrash 3122 } else if (match_option(option, "-XX:+CreateMinidumpOnCrash")) { 3123 if (FLAG_SET_CMDLINE(bool, CreateCoredumpOnCrash, true) != Flag::SUCCESS) { 3124 return JNI_EINVAL; 3125 } 3126 jio_fprintf(defaultStream::output_stream(), 3127 "CreateMinidumpOnCrash is replaced by CreateCoredumpOnCrash: CreateCoredumpOnCrash is on\n"); 3128 } else if (match_option(option, "-XX:-CreateMinidumpOnCrash")) { 3129 if (FLAG_SET_CMDLINE(bool, CreateCoredumpOnCrash, false) != Flag::SUCCESS) { 3130 return JNI_EINVAL; 3131 } 3132 jio_fprintf(defaultStream::output_stream(), 3133 "CreateMinidumpOnCrash is replaced by CreateCoredumpOnCrash: CreateCoredumpOnCrash is off\n"); 3134 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 3135 // Skip -XX:Flags= since that case has already been handled 3136 if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) { 3137 if (!process_argument(tail, args->ignoreUnrecognized, origin)) { 3138 return JNI_EINVAL; 3139 } 3140 } 3141 // Unknown option 3142 } else if (is_bad_option(option, args->ignoreUnrecognized)) { 3143 return JNI_ERR; 3144 } 3145 } 3146 3147 // PrintSharedArchiveAndExit will turn on 3148 // -Xshare:on 3149 // -XX:+TraceClassPaths 3150 if (PrintSharedArchiveAndExit) { 3151 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 3152 return JNI_EINVAL; 3153 } 3154 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { 3155 return JNI_EINVAL; 3156 } 3157 if (FLAG_SET_CMDLINE(bool, TraceClassPaths, true) != Flag::SUCCESS) { 3158 return JNI_EINVAL; 3159 } 3160 } 3161 3162 // Change the default value for flags which have different default values 3163 // when working with older JDKs. 3164 #ifdef LINUX 3165 if (JDK_Version::current().compare_major(6) <= 0 && 3166 FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) { 3167 FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false); 3168 } 3169 #endif // LINUX 3170 fix_appclasspath(); 3171 return JNI_OK; 3172 } 3173 3174 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled) 3175 // 3176 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar 3177 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar". 3178 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty 3179 // path is treated as the current directory. 3180 // 3181 // This causes problems with CDS, which requires that all directories specified in the classpath 3182 // must be empty. In most cases, applications do NOT want to load classes from the current 3183 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up 3184 // scripts compatible with CDS. 3185 void Arguments::fix_appclasspath() { 3186 if (IgnoreEmptyClassPaths) { 3187 const char separator = *os::path_separator(); 3188 const char* src = _java_class_path->value(); 3189 3190 // skip over all the leading empty paths 3191 while (*src == separator) { 3192 src ++; 3193 } 3194 3195 char* copy = os::strdup_check_oom(src, mtInternal); 3196 3197 // trim all trailing empty paths 3198 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) { 3199 *tail = '\0'; 3200 } 3201 3202 char from[3] = {separator, separator, '\0'}; 3203 char to [2] = {separator, '\0'}; 3204 while (StringUtils::replace_no_expand(copy, from, to) > 0) { 3205 // Keep replacing "::" -> ":" until we have no more "::" (non-windows) 3206 // Keep replacing ";;" -> ";" until we have no more ";;" (windows) 3207 } 3208 3209 _java_class_path->set_value(copy); 3210 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore 3211 } 3212 3213 if (!PrintSharedArchiveAndExit) { 3214 ClassLoader::trace_class_path("[classpath: ", _java_class_path->value()); 3215 } 3216 } 3217 3218 static bool has_jar_files(const char* directory) { 3219 DIR* dir = os::opendir(directory); 3220 if (dir == NULL) return false; 3221 3222 struct dirent *entry; 3223 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal); 3224 bool hasJarFile = false; 3225 while (!hasJarFile && (entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { 3226 const char* name = entry->d_name; 3227 const char* ext = name + strlen(name) - 4; 3228 hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0); 3229 } 3230 FREE_C_HEAP_ARRAY(char, dbuf); 3231 os::closedir(dir); 3232 return hasJarFile ; 3233 } 3234 3235 static int check_non_empty_dirs(const char* path) { 3236 const char separator = *os::path_separator(); 3237 const char* const end = path + strlen(path); 3238 int nonEmptyDirs = 0; 3239 while (path < end) { 3240 const char* tmp_end = strchr(path, separator); 3241 if (tmp_end == NULL) { 3242 if (has_jar_files(path)) { 3243 nonEmptyDirs++; 3244 jio_fprintf(defaultStream::output_stream(), 3245 "Non-empty directory: %s\n", path); 3246 } 3247 path = end; 3248 } else { 3249 char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtInternal); 3250 memcpy(dirpath, path, tmp_end - path); 3251 dirpath[tmp_end - path] = '\0'; 3252 if (has_jar_files(dirpath)) { 3253 nonEmptyDirs++; 3254 jio_fprintf(defaultStream::output_stream(), 3255 "Non-empty directory: %s\n", dirpath); 3256 } 3257 FREE_C_HEAP_ARRAY(char, dirpath); 3258 path = tmp_end + 1; 3259 } 3260 } 3261 return nonEmptyDirs; 3262 } 3263 3264 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) { 3265 // check if the default lib/endorsed directory exists; if so, error 3266 char path[JVM_MAXPATHLEN]; 3267 const char* fileSep = os::file_separator(); 3268 sprintf(path, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep); 3269 3270 if (CheckEndorsedAndExtDirs) { 3271 int nonEmptyDirs = 0; 3272 // check endorsed directory 3273 nonEmptyDirs += check_non_empty_dirs(path); 3274 // check the extension directories 3275 nonEmptyDirs += check_non_empty_dirs(Arguments::get_ext_dirs()); 3276 if (nonEmptyDirs > 0) { 3277 return JNI_ERR; 3278 } 3279 } 3280 3281 DIR* dir = os::opendir(path); 3282 if (dir != NULL) { 3283 jio_fprintf(defaultStream::output_stream(), 3284 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n" 3285 "in modular form will be supported via the concept of upgradeable modules.\n"); 3286 os::closedir(dir); 3287 return JNI_ERR; 3288 } 3289 3290 sprintf(path, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep); 3291 dir = os::opendir(path); 3292 if (dir != NULL) { 3293 jio_fprintf(defaultStream::output_stream(), 3294 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; " 3295 "Use -classpath instead.\n."); 3296 os::closedir(dir); 3297 return JNI_ERR; 3298 } 3299 3300 if (scp_assembly_required) { 3301 // Assemble the bootclasspath elements into the final path. 3302 char *combined_path = scp_p->combined_path(); 3303 Arguments::set_sysclasspath(combined_path); 3304 FREE_C_HEAP_ARRAY(char, combined_path); 3305 } 3306 3307 // This must be done after all arguments have been processed. 3308 // java_compiler() true means set to "NONE" or empty. 3309 if (java_compiler() && !xdebug_mode()) { 3310 // For backwards compatibility, we switch to interpreted mode if 3311 // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was 3312 // not specified. 3313 set_mode_flags(_int); 3314 } 3315 3316 // CompileThresholdScaling == 0.0 is same as -Xint: Disable compilation (enable interpreter-only mode), 3317 // but like -Xint, leave compilation thresholds unaffected. 3318 // With tiered compilation disabled, setting CompileThreshold to 0 disables compilation as well. 3319 if ((CompileThresholdScaling == 0.0) || (!TieredCompilation && CompileThreshold == 0)) { 3320 set_mode_flags(_int); 3321 } 3322 3323 // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set 3324 if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) { 3325 FLAG_SET_ERGO(uintx, InitialTenuringThreshold, MaxTenuringThreshold); 3326 } 3327 3328 #ifndef COMPILER2 3329 // Don't degrade server performance for footprint 3330 if (FLAG_IS_DEFAULT(UseLargePages) && 3331 MaxHeapSize < LargePageHeapSizeThreshold) { 3332 // No need for large granularity pages w/small heaps. 3333 // Note that large pages are enabled/disabled for both the 3334 // Java heap and the code cache. 3335 FLAG_SET_DEFAULT(UseLargePages, false); 3336 } 3337 3338 #else 3339 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) { 3340 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1); 3341 } 3342 #endif 3343 3344 #ifndef TIERED 3345 // Tiered compilation is undefined. 3346 UNSUPPORTED_OPTION(TieredCompilation, "TieredCompilation"); 3347 #endif 3348 3349 // If we are running in a headless jre, force java.awt.headless property 3350 // to be true unless the property has already been set. 3351 // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state. 3352 if (os::is_headless_jre()) { 3353 const char* headless = Arguments::get_property("java.awt.headless"); 3354 if (headless == NULL) { 3355 const char *headless_env = ::getenv("JAVA_AWT_HEADLESS"); 3356 if (headless_env == NULL) { 3357 if (!add_property("java.awt.headless=true")) { 3358 return JNI_ENOMEM; 3359 } 3360 } else { 3361 char buffer[256]; 3362 jio_snprintf(buffer, sizeof(buffer), "java.awt.headless=%s", headless_env); 3363 if (!add_property(buffer)) { 3364 return JNI_ENOMEM; 3365 } 3366 } 3367 } 3368 } 3369 3370 if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) { 3371 // CMS can only be used with ParNew 3372 FLAG_SET_ERGO(bool, UseParNewGC, true); 3373 } 3374 3375 if (!check_vm_args_consistency()) { 3376 return JNI_ERR; 3377 } 3378 3379 return JNI_OK; 3380 } 3381 3382 // Helper class for controlling the lifetime of JavaVMInitArgs 3383 // objects. The contents of the JavaVMInitArgs are guaranteed to be 3384 // deleted on the destruction of the ScopedVMInitArgs object. 3385 class ScopedVMInitArgs : public StackObj { 3386 private: 3387 JavaVMInitArgs _args; 3388 3389 public: 3390 ScopedVMInitArgs() { 3391 _args.version = JNI_VERSION_1_2; 3392 _args.nOptions = 0; 3393 _args.options = NULL; 3394 _args.ignoreUnrecognized = false; 3395 } 3396 3397 // Populates the JavaVMInitArgs object represented by this 3398 // ScopedVMInitArgs object with the arguments in options. The 3399 // allocated memory is deleted by the destructor. If this method 3400 // returns anything other than JNI_OK, then this object is in a 3401 // partially constructed state, and should be abandoned. 3402 jint set_args(GrowableArray<JavaVMOption>* options) { 3403 JavaVMOption* options_arr = NEW_C_HEAP_ARRAY_RETURN_NULL( 3404 JavaVMOption, options->length(), mtInternal); 3405 if (options_arr == NULL) { 3406 return JNI_ENOMEM; 3407 } 3408 _args.options = options_arr; 3409 3410 for (int i = 0; i < options->length(); i++) { 3411 options_arr[i] = options->at(i); 3412 options_arr[i].optionString = os::strdup(options_arr[i].optionString); 3413 if (options_arr[i].optionString == NULL) { 3414 // Rely on the destructor to do cleanup. 3415 _args.nOptions = i; 3416 return JNI_ENOMEM; 3417 } 3418 } 3419 3420 _args.nOptions = options->length(); 3421 _args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; 3422 return JNI_OK; 3423 } 3424 3425 JavaVMInitArgs* get() { return &_args; } 3426 3427 ~ScopedVMInitArgs() { 3428 if (_args.options == NULL) return; 3429 for (int i = 0; i < _args.nOptions; i++) { 3430 os::free(_args.options[i].optionString); 3431 } 3432 FREE_C_HEAP_ARRAY(JavaVMOption, _args.options); 3433 } 3434 }; 3435 3436 jint Arguments::parse_java_options_environment_variable(ScopedVMInitArgs* args) { 3437 return parse_options_environment_variable("_JAVA_OPTIONS", args); 3438 } 3439 3440 jint Arguments::parse_java_tool_options_environment_variable(ScopedVMInitArgs* args) { 3441 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args); 3442 } 3443 3444 jint Arguments::parse_options_environment_variable(const char* name, 3445 ScopedVMInitArgs* vm_args) { 3446 char *buffer = ::getenv(name); 3447 3448 // Don't check this environment variable if user has special privileges 3449 // (e.g. unix su command). 3450 if (buffer == NULL || os::have_special_privileges()) { 3451 return JNI_OK; 3452 } 3453 3454 if ((buffer = os::strdup(buffer)) == NULL) { 3455 return JNI_ENOMEM; 3456 } 3457 3458 GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaVMOption>(2, true); // Construct option array 3459 jio_fprintf(defaultStream::error_stream(), 3460 "Picked up %s: %s\n", name, buffer); 3461 char* rd = buffer; // pointer to the input string (rd) 3462 while (true) { // repeat for all options in the input string 3463 while (isspace(*rd)) rd++; // skip whitespace 3464 if (*rd == 0) break; // we re done when the input string is read completely 3465 3466 // The output, option string, overwrites the input string. 3467 // Because of quoting, the pointer to the option string (wrt) may lag the pointer to 3468 // input string (rd). 3469 char* wrt = rd; 3470 3471 JavaVMOption option; 3472 option.optionString = wrt; 3473 options->append(option); // Fill in option 3474 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL 3475 if (*rd == '\'' || *rd == '"') { // handle a quoted string 3476 int quote = *rd; // matching quote to look for 3477 rd++; // don't copy open quote 3478 while (*rd != quote) { // include everything (even spaces) up until quote 3479 if (*rd == 0) { // string termination means unmatched string 3480 jio_fprintf(defaultStream::error_stream(), 3481 "Unmatched quote in %s\n", name); 3482 delete options; 3483 os::free(buffer); 3484 return JNI_ERR; 3485 } 3486 *wrt++ = *rd++; // copy to option string 3487 } 3488 rd++; // don't copy close quote 3489 } else { 3490 *wrt++ = *rd++; // copy to option string 3491 } 3492 } 3493 if (*rd != 0) { 3494 // In this case, the assignment to wrt below will make *rd nul, 3495 // which will interfere with the next loop iteration. 3496 rd++; 3497 } 3498 *wrt = 0; // Zero terminate option 3499 } 3500 3501 // Fill out JavaVMInitArgs structure. 3502 jint status = vm_args->set_args(options); 3503 3504 delete options; 3505 os::free(buffer); 3506 return status; 3507 } 3508 3509 void Arguments::set_shared_spaces_flags() { 3510 if (DumpSharedSpaces) { 3511 if (RequireSharedSpaces) { 3512 warning("cannot dump shared archive while using shared archive"); 3513 } 3514 UseSharedSpaces = false; 3515 #ifdef _LP64 3516 if (!UseCompressedOops || !UseCompressedClassPointers) { 3517 vm_exit_during_initialization( 3518 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); 3519 } 3520 } else { 3521 if (!UseCompressedOops || !UseCompressedClassPointers) { 3522 no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces."); 3523 } 3524 #endif 3525 } 3526 } 3527 3528 #if !INCLUDE_ALL_GCS 3529 static void force_serial_gc() { 3530 FLAG_SET_DEFAULT(UseSerialGC, true); 3531 UNSUPPORTED_GC_OPTION(UseG1GC); 3532 UNSUPPORTED_GC_OPTION(UseParallelGC); 3533 UNSUPPORTED_GC_OPTION(UseParallelOldGC); 3534 UNSUPPORTED_GC_OPTION(UseConcMarkSweepGC); 3535 UNSUPPORTED_GC_OPTION(UseParNewGC); 3536 } 3537 #endif // INCLUDE_ALL_GCS 3538 3539 // Sharing support 3540 // Construct the path to the archive 3541 static char* get_shared_archive_path() { 3542 char *shared_archive_path; 3543 if (SharedArchiveFile == NULL) { 3544 char jvm_path[JVM_MAXPATHLEN]; 3545 os::jvm_path(jvm_path, sizeof(jvm_path)); 3546 char *end = strrchr(jvm_path, *os::file_separator()); 3547 if (end != NULL) *end = '\0'; 3548 size_t jvm_path_len = strlen(jvm_path); 3549 size_t file_sep_len = strlen(os::file_separator()); 3550 const size_t len = jvm_path_len + file_sep_len + 20; 3551 shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtInternal); 3552 if (shared_archive_path != NULL) { 3553 jio_snprintf(shared_archive_path, len, "%s%sclasses.jsa", 3554 jvm_path, os::file_separator()); 3555 } 3556 } else { 3557 shared_archive_path = os::strdup_check_oom(SharedArchiveFile, mtInternal); 3558 } 3559 return shared_archive_path; 3560 } 3561 3562 #ifndef PRODUCT 3563 // Determine whether LogVMOutput should be implicitly turned on. 3564 static bool use_vm_log() { 3565 if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) || 3566 PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods || 3567 PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers || 3568 PrintAssembly || TraceDeoptimization || TraceDependencies || 3569 (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) { 3570 return true; 3571 } 3572 3573 #ifdef COMPILER1 3574 if (PrintC1Statistics) { 3575 return true; 3576 } 3577 #endif // COMPILER1 3578 3579 #ifdef COMPILER2 3580 if (PrintOptoAssembly || PrintOptoStatistics) { 3581 return true; 3582 } 3583 #endif // COMPILER2 3584 3585 return false; 3586 } 3587 #endif // PRODUCT 3588 3589 static jint match_special_option_and_act(const JavaVMInitArgs* args, 3590 char** flags_file) { 3591 // Remaining part of option string 3592 const char* tail; 3593 3594 for (int index = 0; index < args->nOptions; index++) { 3595 const JavaVMOption* option = args->options + index; 3596 if (ArgumentsExt::process_options(option)) { 3597 continue; 3598 } 3599 if (match_option(option, "-XX:Flags=", &tail)) { 3600 *flags_file = (char *) tail; 3601 continue; 3602 } 3603 if (match_option(option, "-XX:+PrintVMOptions")) { 3604 PrintVMOptions = true; 3605 continue; 3606 } 3607 if (match_option(option, "-XX:-PrintVMOptions")) { 3608 PrintVMOptions = false; 3609 continue; 3610 } 3611 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) { 3612 IgnoreUnrecognizedVMOptions = true; 3613 continue; 3614 } 3615 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) { 3616 IgnoreUnrecognizedVMOptions = false; 3617 continue; 3618 } 3619 if (match_option(option, "-XX:+PrintFlagsInitial")) { 3620 CommandLineFlags::printFlags(tty, false); 3621 vm_exit(0); 3622 } 3623 if (match_option(option, "-XX:NativeMemoryTracking", &tail)) { 3624 #if INCLUDE_NMT 3625 // The launcher did not setup nmt environment variable properly. 3626 if (!MemTracker::check_launcher_nmt_support(tail)) { 3627 warning("Native Memory Tracking did not setup properly, using wrong launcher?"); 3628 } 3629 3630 // Verify if nmt option is valid. 3631 if (MemTracker::verify_nmt_option()) { 3632 // Late initialization, still in single-threaded mode. 3633 if (MemTracker::tracking_level() >= NMT_summary) { 3634 MemTracker::init(); 3635 } 3636 } else { 3637 vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL); 3638 } 3639 continue; 3640 #else 3641 jio_fprintf(defaultStream::error_stream(), 3642 "Native Memory Tracking is not supported in this VM\n"); 3643 return JNI_ERR; 3644 #endif 3645 } 3646 3647 #ifndef PRODUCT 3648 if (match_option(option, "-XX:+PrintFlagsWithComments")) { 3649 CommandLineFlags::printFlags(tty, true); 3650 vm_exit(0); 3651 } 3652 #endif 3653 } 3654 return JNI_OK; 3655 } 3656 3657 static void print_options(const JavaVMInitArgs *args) { 3658 const char* tail; 3659 for (int index = 0; index < args->nOptions; index++) { 3660 const JavaVMOption *option = args->options + index; 3661 if (match_option(option, "-XX:", &tail)) { 3662 logOption(tail); 3663 } 3664 } 3665 } 3666 3667 // Parse entry point called from JNI_CreateJavaVM 3668 3669 jint Arguments::parse(const JavaVMInitArgs* args) { 3670 3671 // Initialize ranges and constraints 3672 CommandLineFlagRangeList::init(); 3673 CommandLineFlagConstraintList::init(); 3674 3675 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. 3676 const char* hotspotrc = ".hotspotrc"; 3677 char* flags_file = NULL; 3678 bool settings_file_specified = false; 3679 bool needs_hotspotrc_warning = false; 3680 ScopedVMInitArgs java_tool_options_args; 3681 ScopedVMInitArgs java_options_args; 3682 3683 jint code = 3684 parse_java_tool_options_environment_variable(&java_tool_options_args); 3685 if (code != JNI_OK) { 3686 return code; 3687 } 3688 3689 code = parse_java_options_environment_variable(&java_options_args); 3690 if (code != JNI_OK) { 3691 return code; 3692 } 3693 3694 code = 3695 match_special_option_and_act(java_tool_options_args.get(), &flags_file); 3696 if (code != JNI_OK) { 3697 return code; 3698 } 3699 3700 code = match_special_option_and_act(args, &flags_file); 3701 if (code != JNI_OK) { 3702 return code; 3703 } 3704 3705 code = match_special_option_and_act(java_options_args.get(), &flags_file); 3706 if (code != JNI_OK) { 3707 return code; 3708 } 3709 3710 settings_file_specified = (flags_file != NULL); 3711 3712 if (IgnoreUnrecognizedVMOptions) { 3713 // uncast const to modify the flag args->ignoreUnrecognized 3714 *(jboolean*)(&args->ignoreUnrecognized) = true; 3715 java_tool_options_args.get()->ignoreUnrecognized = true; 3716 java_options_args.get()->ignoreUnrecognized = true; 3717 } 3718 3719 // Parse specified settings file 3720 if (settings_file_specified) { 3721 if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) { 3722 return JNI_EINVAL; 3723 } 3724 } else { 3725 #ifdef ASSERT 3726 // Parse default .hotspotrc settings file 3727 if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) { 3728 return JNI_EINVAL; 3729 } 3730 #else 3731 struct stat buf; 3732 if (os::stat(hotspotrc, &buf) == 0) { 3733 needs_hotspotrc_warning = true; 3734 } 3735 #endif 3736 } 3737 3738 if (PrintVMOptions) { 3739 print_options(java_tool_options_args.get()); 3740 print_options(args); 3741 print_options(java_options_args.get()); 3742 } 3743 3744 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS 3745 jint result = parse_vm_init_args(java_tool_options_args.get(), 3746 java_options_args.get(), args); 3747 3748 if (result != JNI_OK) { 3749 return result; 3750 } 3751 3752 // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed. 3753 SharedArchivePath = get_shared_archive_path(); 3754 if (SharedArchivePath == NULL) { 3755 return JNI_ENOMEM; 3756 } 3757 3758 // Set up VerifySharedSpaces 3759 if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) { 3760 VerifySharedSpaces = true; 3761 } 3762 3763 // Delay warning until here so that we've had a chance to process 3764 // the -XX:-PrintWarnings flag 3765 if (needs_hotspotrc_warning) { 3766 warning("%s file is present but has been ignored. " 3767 "Run with -XX:Flags=%s to load the file.", 3768 hotspotrc, hotspotrc); 3769 } 3770 3771 #if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX. 3772 UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages"); 3773 #endif 3774 3775 ArgumentsExt::report_unsupported_options(); 3776 3777 #ifndef PRODUCT 3778 if (TraceBytecodesAt != 0) { 3779 TraceBytecodes = true; 3780 } 3781 if (CountCompiledCalls) { 3782 if (UseCounterDecay) { 3783 warning("UseCounterDecay disabled because CountCalls is set"); 3784 UseCounterDecay = false; 3785 } 3786 } 3787 #endif // PRODUCT 3788 3789 if (ScavengeRootsInCode == 0) { 3790 if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) { 3791 warning("forcing ScavengeRootsInCode non-zero"); 3792 } 3793 ScavengeRootsInCode = 1; 3794 } 3795 3796 if (PrintGCDetails) { 3797 // Turn on -verbose:gc options as well 3798 PrintGC = true; 3799 } 3800 3801 // Set object alignment values. 3802 set_object_alignment(); 3803 3804 #if !INCLUDE_ALL_GCS 3805 force_serial_gc(); 3806 #endif // INCLUDE_ALL_GCS 3807 #if !INCLUDE_CDS 3808 if (DumpSharedSpaces || RequireSharedSpaces) { 3809 jio_fprintf(defaultStream::error_stream(), 3810 "Shared spaces are not supported in this VM\n"); 3811 return JNI_ERR; 3812 } 3813 if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) { 3814 warning("Shared spaces are not supported in this VM"); 3815 FLAG_SET_DEFAULT(UseSharedSpaces, false); 3816 FLAG_SET_DEFAULT(PrintSharedSpaces, false); 3817 } 3818 no_shared_spaces("CDS Disabled"); 3819 #endif // INCLUDE_CDS 3820 3821 return JNI_OK; 3822 } 3823 3824 jint Arguments::apply_ergo() { 3825 3826 // Set flags based on ergonomics. 3827 set_ergonomics_flags(); 3828 3829 set_shared_spaces_flags(); 3830 3831 // Check the GC selections again. 3832 if (!check_gc_consistency()) { 3833 return JNI_EINVAL; 3834 } 3835 3836 if (TieredCompilation) { 3837 set_tiered_flags(); 3838 } else { 3839 int max_compilation_policy_choice = 1; 3840 #ifdef COMPILER2 3841 max_compilation_policy_choice = 2; 3842 #endif 3843 // Check if the policy is valid. 3844 if (CompilationPolicyChoice >= max_compilation_policy_choice) { 3845 vm_exit_during_initialization( 3846 "Incompatible compilation policy selected", NULL); 3847 } 3848 // Scale CompileThreshold 3849 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves CompileThreshold unchanged. 3850 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) { 3851 FLAG_SET_ERGO(intx, CompileThreshold, scaled_compile_threshold(CompileThreshold)); 3852 } 3853 } 3854 3855 #ifdef COMPILER2 3856 #ifndef PRODUCT 3857 if (PrintIdealGraphLevel > 0) { 3858 FLAG_SET_ERGO(bool, PrintIdealGraph, true); 3859 } 3860 #endif 3861 #endif 3862 3863 // Set heap size based on available physical memory 3864 set_heap_size(); 3865 3866 ArgumentsExt::set_gc_specific_flags(); 3867 3868 // Initialize Metaspace flags and alignments 3869 Metaspace::ergo_initialize(); 3870 3871 // Set bytecode rewriting flags 3872 set_bytecode_flags(); 3873 3874 // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled 3875 set_aggressive_opts_flags(); 3876 3877 // Turn off biased locking for locking debug mode flags, 3878 // which are subtly different from each other but neither works with 3879 // biased locking 3880 if (UseHeavyMonitors 3881 #ifdef COMPILER1 3882 || !UseFastLocking 3883 #endif // COMPILER1 3884 ) { 3885 if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) { 3886 // flag set to true on command line; warn the user that they 3887 // can't enable biased locking here 3888 warning("Biased Locking is not supported with locking debug flags" 3889 "; ignoring UseBiasedLocking flag." ); 3890 } 3891 UseBiasedLocking = false; 3892 } 3893 3894 #ifdef ZERO 3895 // Clear flags not supported on zero. 3896 FLAG_SET_DEFAULT(ProfileInterpreter, false); 3897 FLAG_SET_DEFAULT(UseBiasedLocking, false); 3898 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false)); 3899 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedClassPointers, false)); 3900 #endif // CC_INTERP 3901 3902 #ifdef COMPILER2 3903 if (!EliminateLocks) { 3904 EliminateNestedLocks = false; 3905 } 3906 if (!Inline) { 3907 IncrementalInline = false; 3908 } 3909 #ifndef PRODUCT 3910 if (!IncrementalInline) { 3911 AlwaysIncrementalInline = false; 3912 } 3913 #endif 3914 if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) { 3915 // nothing to use the profiling, turn if off 3916 FLAG_SET_DEFAULT(TypeProfileLevel, 0); 3917 } 3918 #endif 3919 3920 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) { 3921 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output"); 3922 DebugNonSafepoints = true; 3923 } 3924 3925 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) { 3926 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used"); 3927 } 3928 3929 #ifndef PRODUCT 3930 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) { 3931 if (use_vm_log()) { 3932 LogVMOutput = true; 3933 } 3934 } 3935 #endif // PRODUCT 3936 3937 if (PrintCommandLineFlags) { 3938 CommandLineFlags::printSetFlags(tty); 3939 } 3940 3941 // Apply CPU specific policy for the BiasedLocking 3942 if (UseBiasedLocking) { 3943 if (!VM_Version::use_biased_locking() && 3944 !(FLAG_IS_CMDLINE(UseBiasedLocking))) { 3945 UseBiasedLocking = false; 3946 } 3947 } 3948 #ifdef COMPILER2 3949 if (!UseBiasedLocking || EmitSync != 0) { 3950 UseOptoBiasInlining = false; 3951 } 3952 #endif 3953 3954 return JNI_OK; 3955 } 3956 3957 jint Arguments::adjust_after_os() { 3958 if (UseNUMA) { 3959 if (UseParallelGC || UseParallelOldGC) { 3960 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) { 3961 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M); 3962 } 3963 } 3964 // UseNUMAInterleaving is set to ON for all collectors and 3965 // platforms when UseNUMA is set to ON. NUMA-aware collectors 3966 // such as the parallel collector for Linux and Solaris will 3967 // interleave old gen and survivor spaces on top of NUMA 3968 // allocation policy for the eden space. 3969 // Non NUMA-aware collectors such as CMS, G1 and Serial-GC on 3970 // all platforms and ParallelGC on Windows will interleave all 3971 // of the heap spaces across NUMA nodes. 3972 if (FLAG_IS_DEFAULT(UseNUMAInterleaving)) { 3973 FLAG_SET_ERGO(bool, UseNUMAInterleaving, true); 3974 } 3975 } 3976 return JNI_OK; 3977 } 3978 3979 int Arguments::PropertyList_count(SystemProperty* pl) { 3980 int count = 0; 3981 while(pl != NULL) { 3982 count++; 3983 pl = pl->next(); 3984 } 3985 return count; 3986 } 3987 3988 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) { 3989 assert(key != NULL, "just checking"); 3990 SystemProperty* prop; 3991 for (prop = pl; prop != NULL; prop = prop->next()) { 3992 if (strcmp(key, prop->key()) == 0) return prop->value(); 3993 } 3994 return NULL; 3995 } 3996 3997 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) { 3998 int count = 0; 3999 const char* ret_val = NULL; 4000 4001 while(pl != NULL) { 4002 if(count >= index) { 4003 ret_val = pl->key(); 4004 break; 4005 } 4006 count++; 4007 pl = pl->next(); 4008 } 4009 4010 return ret_val; 4011 } 4012 4013 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) { 4014 int count = 0; 4015 char* ret_val = NULL; 4016 4017 while(pl != NULL) { 4018 if(count >= index) { 4019 ret_val = pl->value(); 4020 break; 4021 } 4022 count++; 4023 pl = pl->next(); 4024 } 4025 4026 return ret_val; 4027 } 4028 4029 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) { 4030 SystemProperty* p = *plist; 4031 if (p == NULL) { 4032 *plist = new_p; 4033 } else { 4034 while (p->next() != NULL) { 4035 p = p->next(); 4036 } 4037 p->set_next(new_p); 4038 } 4039 } 4040 4041 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) { 4042 if (plist == NULL) 4043 return; 4044 4045 SystemProperty* new_p = new SystemProperty(k, v, true); 4046 PropertyList_add(plist, new_p); 4047 } 4048 4049 void Arguments::PropertyList_add(SystemProperty *element) { 4050 PropertyList_add(&_system_properties, element); 4051 } 4052 4053 // This add maintains unique property key in the list. 4054 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append) { 4055 if (plist == NULL) 4056 return; 4057 4058 // If property key exist then update with new value. 4059 SystemProperty* prop; 4060 for (prop = *plist; prop != NULL; prop = prop->next()) { 4061 if (strcmp(k, prop->key()) == 0) { 4062 if (append) { 4063 prop->append_value(v); 4064 } else { 4065 prop->set_value(v); 4066 } 4067 return; 4068 } 4069 } 4070 4071 PropertyList_add(plist, k, v); 4072 } 4073 4074 // Copies src into buf, replacing "%%" with "%" and "%p" with pid 4075 // Returns true if all of the source pointed by src has been copied over to 4076 // the destination buffer pointed by buf. Otherwise, returns false. 4077 // Notes: 4078 // 1. If the length (buflen) of the destination buffer excluding the 4079 // NULL terminator character is not long enough for holding the expanded 4080 // pid characters, it also returns false instead of returning the partially 4081 // expanded one. 4082 // 2. The passed in "buflen" should be large enough to hold the null terminator. 4083 bool Arguments::copy_expand_pid(const char* src, size_t srclen, 4084 char* buf, size_t buflen) { 4085 const char* p = src; 4086 char* b = buf; 4087 const char* src_end = &src[srclen]; 4088 char* buf_end = &buf[buflen - 1]; 4089 4090 while (p < src_end && b < buf_end) { 4091 if (*p == '%') { 4092 switch (*(++p)) { 4093 case '%': // "%%" ==> "%" 4094 *b++ = *p++; 4095 break; 4096 case 'p': { // "%p" ==> current process id 4097 // buf_end points to the character before the last character so 4098 // that we could write '\0' to the end of the buffer. 4099 size_t buf_sz = buf_end - b + 1; 4100 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id()); 4101 4102 // if jio_snprintf fails or the buffer is not long enough to hold 4103 // the expanded pid, returns false. 4104 if (ret < 0 || ret >= (int)buf_sz) { 4105 return false; 4106 } else { 4107 b += ret; 4108 assert(*b == '\0', "fail in copy_expand_pid"); 4109 if (p == src_end && b == buf_end + 1) { 4110 // reach the end of the buffer. 4111 return true; 4112 } 4113 } 4114 p++; 4115 break; 4116 } 4117 default : 4118 *b++ = '%'; 4119 } 4120 } else { 4121 *b++ = *p++; 4122 } 4123 } 4124 *b = '\0'; 4125 return (p == src_end); // return false if not all of the source was copied 4126 }