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