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