annotate src/share/vm/runtime/arguments.cpp @ 196:d1605aabd0a1

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents 790e66e5fbac
children 1fdb98a17101 b0fe4deeb9fb
rev   line source
duke@0 1 /*
xdono@196 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 #include "incls/_precompiled.incl"
duke@0 26 #include "incls/_arguments.cpp.incl"
duke@0 27
duke@0 28 #define DEFAULT_VENDOR_URL_BUG "http://java.sun.com/webapps/bugreport/crash.jsp"
duke@0 29 #define DEFAULT_JAVA_LAUNCHER "generic"
duke@0 30
duke@0 31 char** Arguments::_jvm_flags_array = NULL;
duke@0 32 int Arguments::_num_jvm_flags = 0;
duke@0 33 char** Arguments::_jvm_args_array = NULL;
duke@0 34 int Arguments::_num_jvm_args = 0;
duke@0 35 char* Arguments::_java_command = NULL;
duke@0 36 SystemProperty* Arguments::_system_properties = NULL;
duke@0 37 const char* Arguments::_gc_log_filename = NULL;
duke@0 38 bool Arguments::_has_profile = false;
duke@0 39 bool Arguments::_has_alloc_profile = false;
duke@0 40 uintx Arguments::_initial_heap_size = 0;
duke@0 41 uintx Arguments::_min_heap_size = 0;
duke@0 42 Arguments::Mode Arguments::_mode = _mixed;
duke@0 43 bool Arguments::_java_compiler = false;
duke@0 44 bool Arguments::_xdebug_mode = false;
duke@0 45 const char* Arguments::_java_vendor_url_bug = DEFAULT_VENDOR_URL_BUG;
duke@0 46 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
duke@0 47 int Arguments::_sun_java_launcher_pid = -1;
duke@0 48
duke@0 49 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
duke@0 50 bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
duke@0 51 bool Arguments::_UseOnStackReplacement = UseOnStackReplacement;
duke@0 52 bool Arguments::_BackgroundCompilation = BackgroundCompilation;
duke@0 53 bool Arguments::_ClipInlining = ClipInlining;
duke@0 54 intx Arguments::_Tier2CompileThreshold = Tier2CompileThreshold;
duke@0 55
duke@0 56 char* Arguments::SharedArchivePath = NULL;
duke@0 57
duke@0 58 AgentLibraryList Arguments::_libraryList;
duke@0 59 AgentLibraryList Arguments::_agentList;
duke@0 60
duke@0 61 abort_hook_t Arguments::_abort_hook = NULL;
duke@0 62 exit_hook_t Arguments::_exit_hook = NULL;
duke@0 63 vfprintf_hook_t Arguments::_vfprintf_hook = NULL;
duke@0 64
duke@0 65
duke@0 66 SystemProperty *Arguments::_java_ext_dirs = NULL;
duke@0 67 SystemProperty *Arguments::_java_endorsed_dirs = NULL;
duke@0 68 SystemProperty *Arguments::_sun_boot_library_path = NULL;
duke@0 69 SystemProperty *Arguments::_java_library_path = NULL;
duke@0 70 SystemProperty *Arguments::_java_home = NULL;
duke@0 71 SystemProperty *Arguments::_java_class_path = NULL;
duke@0 72 SystemProperty *Arguments::_sun_boot_class_path = NULL;
duke@0 73
duke@0 74 char* Arguments::_meta_index_path = NULL;
duke@0 75 char* Arguments::_meta_index_dir = NULL;
duke@0 76
duke@0 77 static bool force_client_mode = false;
duke@0 78
duke@0 79 // Check if head of 'option' matches 'name', and sets 'tail' remaining part of option string
duke@0 80
duke@0 81 static bool match_option(const JavaVMOption *option, const char* name,
duke@0 82 const char** tail) {
duke@0 83 int len = (int)strlen(name);
duke@0 84 if (strncmp(option->optionString, name, len) == 0) {
duke@0 85 *tail = option->optionString + len;
duke@0 86 return true;
duke@0 87 } else {
duke@0 88 return false;
duke@0 89 }
duke@0 90 }
duke@0 91
duke@0 92 static void logOption(const char* opt) {
duke@0 93 if (PrintVMOptions) {
duke@0 94 jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
duke@0 95 }
duke@0 96 }
duke@0 97
duke@0 98 // Process java launcher properties.
duke@0 99 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
duke@0 100 // See if sun.java.launcher or sun.java.launcher.pid is defined.
duke@0 101 // Must do this before setting up other system properties,
duke@0 102 // as some of them may depend on launcher type.
duke@0 103 for (int index = 0; index < args->nOptions; index++) {
duke@0 104 const JavaVMOption* option = args->options + index;
duke@0 105 const char* tail;
duke@0 106
duke@0 107 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
duke@0 108 process_java_launcher_argument(tail, option->extraInfo);
duke@0 109 continue;
duke@0 110 }
duke@0 111 if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
duke@0 112 _sun_java_launcher_pid = atoi(tail);
duke@0 113 continue;
duke@0 114 }
duke@0 115 }
duke@0 116 }
duke@0 117
duke@0 118 // Initialize system properties key and value.
duke@0 119 void Arguments::init_system_properties() {
duke@0 120
duke@0 121 PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.version", "1.0", false));
duke@0 122 PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name",
duke@0 123 "Java Virtual Machine Specification", false));
duke@0 124 PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.vendor",
duke@0 125 "Sun Microsystems Inc.", false));
duke@0 126 PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(), false));
duke@0 127 PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(), false));
duke@0 128 PropertyList_add(&_system_properties, new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(), false));
duke@0 129 PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(), true));
duke@0 130
duke@0 131 // following are JVMTI agent writeable properties.
duke@0 132 // Properties values are set to NULL and they are
duke@0 133 // os specific they are initialized in os::init_system_properties_values().
duke@0 134 _java_ext_dirs = new SystemProperty("java.ext.dirs", NULL, true);
duke@0 135 _java_endorsed_dirs = new SystemProperty("java.endorsed.dirs", NULL, true);
duke@0 136 _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL, true);
duke@0 137 _java_library_path = new SystemProperty("java.library.path", NULL, true);
duke@0 138 _java_home = new SystemProperty("java.home", NULL, true);
duke@0 139 _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL, true);
duke@0 140
duke@0 141 _java_class_path = new SystemProperty("java.class.path", "", true);
duke@0 142
duke@0 143 // Add to System Property list.
duke@0 144 PropertyList_add(&_system_properties, _java_ext_dirs);
duke@0 145 PropertyList_add(&_system_properties, _java_endorsed_dirs);
duke@0 146 PropertyList_add(&_system_properties, _sun_boot_library_path);
duke@0 147 PropertyList_add(&_system_properties, _java_library_path);
duke@0 148 PropertyList_add(&_system_properties, _java_home);
duke@0 149 PropertyList_add(&_system_properties, _java_class_path);
duke@0 150 PropertyList_add(&_system_properties, _sun_boot_class_path);
duke@0 151
duke@0 152 // Set OS specific system properties values
duke@0 153 os::init_system_properties_values();
duke@0 154 }
duke@0 155
duke@0 156 // String containing commands that will be ignored and cause a
duke@0 157 // warning to be issued. These commands should be accepted
duke@0 158 // for 1.6 but not 1.7. The string should be cleared at the
duke@0 159 // beginning of 1.7.
duke@0 160 static const char* obsolete_jvm_flags_1_5_0[] = {
duke@0 161 "UseTrainGC",
duke@0 162 "UseSpecialLargeObjectHandling",
duke@0 163 "UseOversizedCarHandling",
duke@0 164 "TraceCarAllocation",
duke@0 165 "PrintTrainGCProcessingStats",
duke@0 166 "LogOfCarSpaceSize",
duke@0 167 "OversizedCarThreshold",
duke@0 168 "MinTickInterval",
duke@0 169 "DefaultTickInterval",
duke@0 170 "MaxTickInterval",
duke@0 171 "DelayTickAdjustment",
duke@0 172 "ProcessingToTenuringRatio",
duke@0 173 "MinTrainLength",
duke@0 174 0};
duke@0 175
duke@0 176 bool Arguments::made_obsolete_in_1_5_0(const char *s) {
duke@0 177 int i = 0;
duke@0 178 while (obsolete_jvm_flags_1_5_0[i] != NULL) {
duke@0 179 // <flag>=xxx form
duke@0 180 // [-|+]<flag> form
duke@0 181 if ((strncmp(obsolete_jvm_flags_1_5_0[i], s,
duke@0 182 strlen(obsolete_jvm_flags_1_5_0[i])) == 0) ||
duke@0 183 ((s[0] == '+' || s[0] == '-') &&
duke@0 184 (strncmp(obsolete_jvm_flags_1_5_0[i], &s[1],
duke@0 185 strlen(obsolete_jvm_flags_1_5_0[i])) == 0))) {
duke@0 186 return true;
duke@0 187 }
duke@0 188 i++;
duke@0 189 }
duke@0 190 return false;
duke@0 191 }
duke@0 192
duke@0 193 // Constructs the system class path (aka boot class path) from the following
duke@0 194 // components, in order:
duke@0 195 //
duke@0 196 // prefix // from -Xbootclasspath/p:...
duke@0 197 // endorsed // the expansion of -Djava.endorsed.dirs=...
duke@0 198 // base // from os::get_system_properties() or -Xbootclasspath=
duke@0 199 // suffix // from -Xbootclasspath/a:...
duke@0 200 //
duke@0 201 // java.endorsed.dirs is a list of directories; any jar or zip files in the
duke@0 202 // directories are added to the sysclasspath just before the base.
duke@0 203 //
duke@0 204 // This could be AllStatic, but it isn't needed after argument processing is
duke@0 205 // complete.
duke@0 206 class SysClassPath: public StackObj {
duke@0 207 public:
duke@0 208 SysClassPath(const char* base);
duke@0 209 ~SysClassPath();
duke@0 210
duke@0 211 inline void set_base(const char* base);
duke@0 212 inline void add_prefix(const char* prefix);
duke@0 213 inline void add_suffix(const char* suffix);
duke@0 214 inline void reset_path(const char* base);
duke@0 215
duke@0 216 // Expand the jar/zip files in each directory listed by the java.endorsed.dirs
duke@0 217 // property. Must be called after all command-line arguments have been
duke@0 218 // processed (in particular, -Djava.endorsed.dirs=...) and before calling
duke@0 219 // combined_path().
duke@0 220 void expand_endorsed();
duke@0 221
duke@0 222 inline const char* get_base() const { return _items[_scp_base]; }
duke@0 223 inline const char* get_prefix() const { return _items[_scp_prefix]; }
duke@0 224 inline const char* get_suffix() const { return _items[_scp_suffix]; }
duke@0 225 inline const char* get_endorsed() const { return _items[_scp_endorsed]; }
duke@0 226
duke@0 227 // Combine all the components into a single c-heap-allocated string; caller
duke@0 228 // must free the string if/when no longer needed.
duke@0 229 char* combined_path();
duke@0 230
duke@0 231 private:
duke@0 232 // Utility routines.
duke@0 233 static char* add_to_path(const char* path, const char* str, bool prepend);
duke@0 234 static char* add_jars_to_path(char* path, const char* directory);
duke@0 235
duke@0 236 inline void reset_item_at(int index);
duke@0 237
duke@0 238 // Array indices for the items that make up the sysclasspath. All except the
duke@0 239 // base are allocated in the C heap and freed by this class.
duke@0 240 enum {
duke@0 241 _scp_prefix, // from -Xbootclasspath/p:...
duke@0 242 _scp_endorsed, // the expansion of -Djava.endorsed.dirs=...
duke@0 243 _scp_base, // the default sysclasspath
duke@0 244 _scp_suffix, // from -Xbootclasspath/a:...
duke@0 245 _scp_nitems // the number of items, must be last.
duke@0 246 };
duke@0 247
duke@0 248 const char* _items[_scp_nitems];
duke@0 249 DEBUG_ONLY(bool _expansion_done;)
duke@0 250 };
duke@0 251
duke@0 252 SysClassPath::SysClassPath(const char* base) {
duke@0 253 memset(_items, 0, sizeof(_items));
duke@0 254 _items[_scp_base] = base;
duke@0 255 DEBUG_ONLY(_expansion_done = false;)
duke@0 256 }
duke@0 257
duke@0 258 SysClassPath::~SysClassPath() {
duke@0 259 // Free everything except the base.
duke@0 260 for (int i = 0; i < _scp_nitems; ++i) {
duke@0 261 if (i != _scp_base) reset_item_at(i);
duke@0 262 }
duke@0 263 DEBUG_ONLY(_expansion_done = false;)
duke@0 264 }
duke@0 265
duke@0 266 inline void SysClassPath::set_base(const char* base) {
duke@0 267 _items[_scp_base] = base;
duke@0 268 }
duke@0 269
duke@0 270 inline void SysClassPath::add_prefix(const char* prefix) {
duke@0 271 _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true);
duke@0 272 }
duke@0 273
duke@0 274 inline void SysClassPath::add_suffix(const char* suffix) {
duke@0 275 _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false);
duke@0 276 }
duke@0 277
duke@0 278 inline void SysClassPath::reset_item_at(int index) {
duke@0 279 assert(index < _scp_nitems && index != _scp_base, "just checking");
duke@0 280 if (_items[index] != NULL) {
duke@0 281 FREE_C_HEAP_ARRAY(char, _items[index]);
duke@0 282 _items[index] = NULL;
duke@0 283 }
duke@0 284 }
duke@0 285
duke@0 286 inline void SysClassPath::reset_path(const char* base) {
duke@0 287 // Clear the prefix and suffix.
duke@0 288 reset_item_at(_scp_prefix);
duke@0 289 reset_item_at(_scp_suffix);
duke@0 290 set_base(base);
duke@0 291 }
duke@0 292
duke@0 293 //------------------------------------------------------------------------------
duke@0 294
duke@0 295 void SysClassPath::expand_endorsed() {
duke@0 296 assert(_items[_scp_endorsed] == NULL, "can only be called once.");
duke@0 297
duke@0 298 const char* path = Arguments::get_property("java.endorsed.dirs");
duke@0 299 if (path == NULL) {
duke@0 300 path = Arguments::get_endorsed_dir();
duke@0 301 assert(path != NULL, "no default for java.endorsed.dirs");
duke@0 302 }
duke@0 303
duke@0 304 char* expanded_path = NULL;
duke@0 305 const char separator = *os::path_separator();
duke@0 306 const char* const end = path + strlen(path);
duke@0 307 while (path < end) {
duke@0 308 const char* tmp_end = strchr(path, separator);
duke@0 309 if (tmp_end == NULL) {
duke@0 310 expanded_path = add_jars_to_path(expanded_path, path);
duke@0 311 path = end;
duke@0 312 } else {
duke@0 313 char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1);
duke@0 314 memcpy(dirpath, path, tmp_end - path);
duke@0 315 dirpath[tmp_end - path] = '\0';
duke@0 316 expanded_path = add_jars_to_path(expanded_path, dirpath);
duke@0 317 FREE_C_HEAP_ARRAY(char, dirpath);
duke@0 318 path = tmp_end + 1;
duke@0 319 }
duke@0 320 }
duke@0 321 _items[_scp_endorsed] = expanded_path;
duke@0 322 DEBUG_ONLY(_expansion_done = true;)
duke@0 323 }
duke@0 324
duke@0 325 // Combine the bootclasspath elements, some of which may be null, into a single
duke@0 326 // c-heap-allocated string.
duke@0 327 char* SysClassPath::combined_path() {
duke@0 328 assert(_items[_scp_base] != NULL, "empty default sysclasspath");
duke@0 329 assert(_expansion_done, "must call expand_endorsed() first.");
duke@0 330
duke@0 331 size_t lengths[_scp_nitems];
duke@0 332 size_t total_len = 0;
duke@0 333
duke@0 334 const char separator = *os::path_separator();
duke@0 335
duke@0 336 // Get the lengths.
duke@0 337 int i;
duke@0 338 for (i = 0; i < _scp_nitems; ++i) {
duke@0 339 if (_items[i] != NULL) {
duke@0 340 lengths[i] = strlen(_items[i]);
duke@0 341 // Include space for the separator char (or a NULL for the last item).
duke@0 342 total_len += lengths[i] + 1;
duke@0 343 }
duke@0 344 }
duke@0 345 assert(total_len > 0, "empty sysclasspath not allowed");
duke@0 346
duke@0 347 // Copy the _items to a single string.
duke@0 348 char* cp = NEW_C_HEAP_ARRAY(char, total_len);
duke@0 349 char* cp_tmp = cp;
duke@0 350 for (i = 0; i < _scp_nitems; ++i) {
duke@0 351 if (_items[i] != NULL) {
duke@0 352 memcpy(cp_tmp, _items[i], lengths[i]);
duke@0 353 cp_tmp += lengths[i];
duke@0 354 *cp_tmp++ = separator;
duke@0 355 }
duke@0 356 }
duke@0 357 *--cp_tmp = '\0'; // Replace the extra separator.
duke@0 358 return cp;
duke@0 359 }
duke@0 360
duke@0 361 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
duke@0 362 char*
duke@0 363 SysClassPath::add_to_path(const char* path, const char* str, bool prepend) {
duke@0 364 char *cp;
duke@0 365
duke@0 366 assert(str != NULL, "just checking");
duke@0 367 if (path == NULL) {
duke@0 368 size_t len = strlen(str) + 1;
duke@0 369 cp = NEW_C_HEAP_ARRAY(char, len);
duke@0 370 memcpy(cp, str, len); // copy the trailing null
duke@0 371 } else {
duke@0 372 const char separator = *os::path_separator();
duke@0 373 size_t old_len = strlen(path);
duke@0 374 size_t str_len = strlen(str);
duke@0 375 size_t len = old_len + str_len + 2;
duke@0 376
duke@0 377 if (prepend) {
duke@0 378 cp = NEW_C_HEAP_ARRAY(char, len);
duke@0 379 char* cp_tmp = cp;
duke@0 380 memcpy(cp_tmp, str, str_len);
duke@0 381 cp_tmp += str_len;
duke@0 382 *cp_tmp = separator;
duke@0 383 memcpy(++cp_tmp, path, old_len + 1); // copy the trailing null
duke@0 384 FREE_C_HEAP_ARRAY(char, path);
duke@0 385 } else {
duke@0 386 cp = REALLOC_C_HEAP_ARRAY(char, path, len);
duke@0 387 char* cp_tmp = cp + old_len;
duke@0 388 *cp_tmp = separator;
duke@0 389 memcpy(++cp_tmp, str, str_len + 1); // copy the trailing null
duke@0 390 }
duke@0 391 }
duke@0 392 return cp;
duke@0 393 }
duke@0 394
duke@0 395 // Scan the directory and append any jar or zip files found to path.
duke@0 396 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
duke@0 397 char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
duke@0 398 DIR* dir = os::opendir(directory);
duke@0 399 if (dir == NULL) return path;
duke@0 400
duke@0 401 char dir_sep[2] = { '\0', '\0' };
duke@0 402 size_t directory_len = strlen(directory);
duke@0 403 const char fileSep = *os::file_separator();
duke@0 404 if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep;
duke@0 405
duke@0 406 /* Scan the directory for jars/zips, appending them to path. */
duke@0 407 struct dirent *entry;
duke@0 408 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory));
duke@0 409 while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
duke@0 410 const char* name = entry->d_name;
duke@0 411 const char* ext = name + strlen(name) - 4;
duke@0 412 bool isJarOrZip = ext > name &&
duke@0 413 (os::file_name_strcmp(ext, ".jar") == 0 ||
duke@0 414 os::file_name_strcmp(ext, ".zip") == 0);
duke@0 415 if (isJarOrZip) {
duke@0 416 char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name));
duke@0 417 sprintf(jarpath, "%s%s%s", directory, dir_sep, name);
duke@0 418 path = add_to_path(path, jarpath, false);
duke@0 419 FREE_C_HEAP_ARRAY(char, jarpath);
duke@0 420 }
duke@0 421 }
duke@0 422 FREE_C_HEAP_ARRAY(char, dbuf);
duke@0 423 os::closedir(dir);
duke@0 424 return path;
duke@0 425 }
duke@0 426
duke@0 427 // Parses a memory size specification string.
duke@0 428 static bool atomll(const char *s, jlong* result) {
duke@0 429 jlong n = 0;
duke@0 430 int args_read = sscanf(s, os::jlong_format_specifier(), &n);
duke@0 431 if (args_read != 1) {
duke@0 432 return false;
duke@0 433 }
duke@0 434 while (*s != '\0' && isdigit(*s)) {
duke@0 435 s++;
duke@0 436 }
duke@0 437 // 4705540: illegal if more characters are found after the first non-digit
duke@0 438 if (strlen(s) > 1) {
duke@0 439 return false;
duke@0 440 }
duke@0 441 switch (*s) {
duke@0 442 case 'T': case 't':
duke@0 443 *result = n * G * K;
duke@0 444 return true;
duke@0 445 case 'G': case 'g':
duke@0 446 *result = n * G;
duke@0 447 return true;
duke@0 448 case 'M': case 'm':
duke@0 449 *result = n * M;
duke@0 450 return true;
duke@0 451 case 'K': case 'k':
duke@0 452 *result = n * K;
duke@0 453 return true;
duke@0 454 case '\0':
duke@0 455 *result = n;
duke@0 456 return true;
duke@0 457 default:
duke@0 458 return false;
duke@0 459 }
duke@0 460 }
duke@0 461
duke@0 462 Arguments::ArgsRange Arguments::check_memory_size(jlong size, jlong min_size) {
duke@0 463 if (size < min_size) return arg_too_small;
duke@0 464 // Check that size will fit in a size_t (only relevant on 32-bit)
duke@0 465 if ((julong) size > max_uintx) return arg_too_big;
duke@0 466 return arg_in_range;
duke@0 467 }
duke@0 468
duke@0 469 // Describe an argument out of range error
duke@0 470 void Arguments::describe_range_error(ArgsRange errcode) {
duke@0 471 switch(errcode) {
duke@0 472 case arg_too_big:
duke@0 473 jio_fprintf(defaultStream::error_stream(),
duke@0 474 "The specified size exceeds the maximum "
duke@0 475 "representable size.\n");
duke@0 476 break;
duke@0 477 case arg_too_small:
duke@0 478 case arg_unreadable:
duke@0 479 case arg_in_range:
duke@0 480 // do nothing for now
duke@0 481 break;
duke@0 482 default:
duke@0 483 ShouldNotReachHere();
duke@0 484 }
duke@0 485 }
duke@0 486
duke@0 487 static bool set_bool_flag(char* name, bool value, FlagValueOrigin origin) {
duke@0 488 return CommandLineFlags::boolAtPut(name, &value, origin);
duke@0 489 }
duke@0 490
duke@0 491
duke@0 492 static bool set_fp_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
duke@0 493 double v;
duke@0 494 if (sscanf(value, "%lf", &v) != 1) {
duke@0 495 return false;
duke@0 496 }
duke@0 497
duke@0 498 if (CommandLineFlags::doubleAtPut(name, &v, origin)) {
duke@0 499 return true;
duke@0 500 }
duke@0 501 return false;
duke@0 502 }
duke@0 503
duke@0 504
duke@0 505 static bool set_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
duke@0 506 jlong v;
duke@0 507 intx intx_v;
duke@0 508 bool is_neg = false;
duke@0 509 // Check the sign first since atomll() parses only unsigned values.
duke@0 510 if (*value == '-') {
duke@0 511 if (!CommandLineFlags::intxAt(name, &intx_v)) {
duke@0 512 return false;
duke@0 513 }
duke@0 514 value++;
duke@0 515 is_neg = true;
duke@0 516 }
duke@0 517 if (!atomll(value, &v)) {
duke@0 518 return false;
duke@0 519 }
duke@0 520 intx_v = (intx) v;
duke@0 521 if (is_neg) {
duke@0 522 intx_v = -intx_v;
duke@0 523 }
duke@0 524 if (CommandLineFlags::intxAtPut(name, &intx_v, origin)) {
duke@0 525 return true;
duke@0 526 }
duke@0 527 uintx uintx_v = (uintx) v;
duke@0 528 if (!is_neg && CommandLineFlags::uintxAtPut(name, &uintx_v, origin)) {
duke@0 529 return true;
duke@0 530 }
duke@0 531 return false;
duke@0 532 }
duke@0 533
duke@0 534
duke@0 535 static bool set_string_flag(char* name, const char* value, FlagValueOrigin origin) {
duke@0 536 if (!CommandLineFlags::ccstrAtPut(name, &value, origin)) return false;
duke@0 537 // Contract: CommandLineFlags always returns a pointer that needs freeing.
duke@0 538 FREE_C_HEAP_ARRAY(char, value);
duke@0 539 return true;
duke@0 540 }
duke@0 541
duke@0 542 static bool append_to_string_flag(char* name, const char* new_value, FlagValueOrigin origin) {
duke@0 543 const char* old_value = "";
duke@0 544 if (!CommandLineFlags::ccstrAt(name, &old_value)) return false;
duke@0 545 size_t old_len = old_value != NULL ? strlen(old_value) : 0;
duke@0 546 size_t new_len = strlen(new_value);
duke@0 547 const char* value;
duke@0 548 char* free_this_too = NULL;
duke@0 549 if (old_len == 0) {
duke@0 550 value = new_value;
duke@0 551 } else if (new_len == 0) {
duke@0 552 value = old_value;
duke@0 553 } else {
duke@0 554 char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1);
duke@0 555 // each new setting adds another LINE to the switch:
duke@0 556 sprintf(buf, "%s\n%s", old_value, new_value);
duke@0 557 value = buf;
duke@0 558 free_this_too = buf;
duke@0 559 }
duke@0 560 (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
duke@0 561 // CommandLineFlags always returns a pointer that needs freeing.
duke@0 562 FREE_C_HEAP_ARRAY(char, value);
duke@0 563 if (free_this_too != NULL) {
duke@0 564 // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
duke@0 565 FREE_C_HEAP_ARRAY(char, free_this_too);
duke@0 566 }
duke@0 567 return true;
duke@0 568 }
duke@0 569
duke@0 570
duke@0 571 bool Arguments::parse_argument(const char* arg, FlagValueOrigin origin) {
duke@0 572
duke@0 573 // range of acceptable characters spelled out for portability reasons
duke@0 574 #define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
duke@0 575 #define BUFLEN 255
duke@0 576 char name[BUFLEN+1];
duke@0 577 char dummy;
duke@0 578
duke@0 579 if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
duke@0 580 return set_bool_flag(name, false, origin);
duke@0 581 }
duke@0 582 if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
duke@0 583 return set_bool_flag(name, true, origin);
duke@0 584 }
duke@0 585
duke@0 586 char punct;
duke@0 587 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
duke@0 588 const char* value = strchr(arg, '=') + 1;
duke@0 589 Flag* flag = Flag::find_flag(name, strlen(name));
duke@0 590 if (flag != NULL && flag->is_ccstr()) {
duke@0 591 if (flag->ccstr_accumulates()) {
duke@0 592 return append_to_string_flag(name, value, origin);
duke@0 593 } else {
duke@0 594 if (value[0] == '\0') {
duke@0 595 value = NULL;
duke@0 596 }
duke@0 597 return set_string_flag(name, value, origin);
duke@0 598 }
duke@0 599 }
duke@0 600 }
duke@0 601
duke@0 602 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') {
duke@0 603 const char* value = strchr(arg, '=') + 1;
duke@0 604 // -XX:Foo:=xxx will reset the string flag to the given value.
duke@0 605 if (value[0] == '\0') {
duke@0 606 value = NULL;
duke@0 607 }
duke@0 608 return set_string_flag(name, value, origin);
duke@0 609 }
duke@0 610
duke@0 611 #define SIGNED_FP_NUMBER_RANGE "[-0123456789.]"
duke@0 612 #define SIGNED_NUMBER_RANGE "[-0123456789]"
duke@0 613 #define NUMBER_RANGE "[0123456789]"
duke@0 614 char value[BUFLEN + 1];
duke@0 615 char value2[BUFLEN + 1];
duke@0 616 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) {
duke@0 617 // Looks like a floating-point number -- try again with more lenient format string
duke@0 618 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) {
duke@0 619 return set_fp_numeric_flag(name, value, origin);
duke@0 620 }
duke@0 621 }
duke@0 622
duke@0 623 #define VALUE_RANGE "[-kmgtKMGT0123456789]"
duke@0 624 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
duke@0 625 return set_numeric_flag(name, value, origin);
duke@0 626 }
duke@0 627
duke@0 628 return false;
duke@0 629 }
duke@0 630
duke@0 631
duke@0 632 void Arguments::add_string(char*** bldarray, int* count, const char* arg) {
duke@0 633 assert(bldarray != NULL, "illegal argument");
duke@0 634
duke@0 635 if (arg == NULL) {
duke@0 636 return;
duke@0 637 }
duke@0 638
duke@0 639 int index = *count;
duke@0 640
duke@0 641 // expand the array and add arg to the last element
duke@0 642 (*count)++;
duke@0 643 if (*bldarray == NULL) {
duke@0 644 *bldarray = NEW_C_HEAP_ARRAY(char*, *count);
duke@0 645 } else {
duke@0 646 *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, *count);
duke@0 647 }
duke@0 648 (*bldarray)[index] = strdup(arg);
duke@0 649 }
duke@0 650
duke@0 651 void Arguments::build_jvm_args(const char* arg) {
duke@0 652 add_string(&_jvm_args_array, &_num_jvm_args, arg);
duke@0 653 }
duke@0 654
duke@0 655 void Arguments::build_jvm_flags(const char* arg) {
duke@0 656 add_string(&_jvm_flags_array, &_num_jvm_flags, arg);
duke@0 657 }
duke@0 658
duke@0 659 // utility function to return a string that concatenates all
duke@0 660 // strings in a given char** array
duke@0 661 const char* Arguments::build_resource_string(char** args, int count) {
duke@0 662 if (args == NULL || count == 0) {
duke@0 663 return NULL;
duke@0 664 }
duke@0 665 size_t length = strlen(args[0]) + 1; // add 1 for the null terminator
duke@0 666 for (int i = 1; i < count; i++) {
duke@0 667 length += strlen(args[i]) + 1; // add 1 for a space
duke@0 668 }
duke@0 669 char* s = NEW_RESOURCE_ARRAY(char, length);
duke@0 670 strcpy(s, args[0]);
duke@0 671 for (int j = 1; j < count; j++) {
duke@0 672 strcat(s, " ");
duke@0 673 strcat(s, args[j]);
duke@0 674 }
duke@0 675 return (const char*) s;
duke@0 676 }
duke@0 677
duke@0 678 void Arguments::print_on(outputStream* st) {
duke@0 679 st->print_cr("VM Arguments:");
duke@0 680 if (num_jvm_flags() > 0) {
duke@0 681 st->print("jvm_flags: "); print_jvm_flags_on(st);
duke@0 682 }
duke@0 683 if (num_jvm_args() > 0) {
duke@0 684 st->print("jvm_args: "); print_jvm_args_on(st);
duke@0 685 }
duke@0 686 st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>");
duke@0 687 st->print_cr("Launcher Type: %s", _sun_java_launcher);
duke@0 688 }
duke@0 689
duke@0 690 void Arguments::print_jvm_flags_on(outputStream* st) {
duke@0 691 if (_num_jvm_flags > 0) {
duke@0 692 for (int i=0; i < _num_jvm_flags; i++) {
duke@0 693 st->print("%s ", _jvm_flags_array[i]);
duke@0 694 }
duke@0 695 st->print_cr("");
duke@0 696 }
duke@0 697 }
duke@0 698
duke@0 699 void Arguments::print_jvm_args_on(outputStream* st) {
duke@0 700 if (_num_jvm_args > 0) {
duke@0 701 for (int i=0; i < _num_jvm_args; i++) {
duke@0 702 st->print("%s ", _jvm_args_array[i]);
duke@0 703 }
duke@0 704 st->print_cr("");
duke@0 705 }
duke@0 706 }
duke@0 707
duke@0 708 bool Arguments::process_argument(const char* arg, jboolean ignore_unrecognized, FlagValueOrigin origin) {
duke@0 709
duke@0 710 if (parse_argument(arg, origin)) {
duke@0 711 // do nothing
duke@0 712 } else if (made_obsolete_in_1_5_0(arg)) {
duke@0 713 jio_fprintf(defaultStream::error_stream(),
duke@0 714 "Warning: The flag %s has been EOL'd as of 1.5.0 and will"
duke@0 715 " be ignored\n", arg);
duke@0 716 } else {
duke@0 717 if (!ignore_unrecognized) {
duke@0 718 jio_fprintf(defaultStream::error_stream(),
duke@0 719 "Unrecognized VM option '%s'\n", arg);
duke@0 720 // allow for commandline "commenting out" options like -XX:#+Verbose
duke@0 721 if (strlen(arg) == 0 || arg[0] != '#') {
duke@0 722 return false;
duke@0 723 }
duke@0 724 }
duke@0 725 }
duke@0 726 return true;
duke@0 727 }
duke@0 728
duke@0 729
duke@0 730 bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
duke@0 731 FILE* stream = fopen(file_name, "rb");
duke@0 732 if (stream == NULL) {
duke@0 733 if (should_exist) {
duke@0 734 jio_fprintf(defaultStream::error_stream(),
duke@0 735 "Could not open settings file %s\n", file_name);
duke@0 736 return false;
duke@0 737 } else {
duke@0 738 return true;
duke@0 739 }
duke@0 740 }
duke@0 741
duke@0 742 char token[1024];
duke@0 743 int pos = 0;
duke@0 744
duke@0 745 bool in_white_space = true;
duke@0 746 bool in_comment = false;
duke@0 747 bool in_quote = false;
duke@0 748 char quote_c = 0;
duke@0 749 bool result = true;
duke@0 750
duke@0 751 int c = getc(stream);
duke@0 752 while(c != EOF) {
duke@0 753 if (in_white_space) {
duke@0 754 if (in_comment) {
duke@0 755 if (c == '\n') in_comment = false;
duke@0 756 } else {
duke@0 757 if (c == '#') in_comment = true;
duke@0 758 else if (!isspace(c)) {
duke@0 759 in_white_space = false;
duke@0 760 token[pos++] = c;
duke@0 761 }
duke@0 762 }
duke@0 763 } else {
duke@0 764 if (c == '\n' || (!in_quote && isspace(c))) {
duke@0 765 // token ends at newline, or at unquoted whitespace
duke@0 766 // this allows a way to include spaces in string-valued options
duke@0 767 token[pos] = '\0';
duke@0 768 logOption(token);
duke@0 769 result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
duke@0 770 build_jvm_flags(token);
duke@0 771 pos = 0;
duke@0 772 in_white_space = true;
duke@0 773 in_quote = false;
duke@0 774 } else if (!in_quote && (c == '\'' || c == '"')) {
duke@0 775 in_quote = true;
duke@0 776 quote_c = c;
duke@0 777 } else if (in_quote && (c == quote_c)) {
duke@0 778 in_quote = false;
duke@0 779 } else {
duke@0 780 token[pos++] = c;
duke@0 781 }
duke@0 782 }
duke@0 783 c = getc(stream);
duke@0 784 }
duke@0 785 if (pos > 0) {
duke@0 786 token[pos] = '\0';
duke@0 787 result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
duke@0 788 build_jvm_flags(token);
duke@0 789 }
duke@0 790 fclose(stream);
duke@0 791 return result;
duke@0 792 }
duke@0 793
duke@0 794 //=============================================================================================================
duke@0 795 // Parsing of properties (-D)
duke@0 796
duke@0 797 const char* Arguments::get_property(const char* key) {
duke@0 798 return PropertyList_get_value(system_properties(), key);
duke@0 799 }
duke@0 800
duke@0 801 bool Arguments::add_property(const char* prop) {
duke@0 802 const char* eq = strchr(prop, '=');
duke@0 803 char* key;
duke@0 804 // ns must be static--its address may be stored in a SystemProperty object.
duke@0 805 const static char ns[1] = {0};
duke@0 806 char* value = (char *)ns;
duke@0 807
duke@0 808 size_t key_len = (eq == NULL) ? strlen(prop) : (eq - prop);
duke@0 809 key = AllocateHeap(key_len + 1, "add_property");
duke@0 810 strncpy(key, prop, key_len);
duke@0 811 key[key_len] = '\0';
duke@0 812
duke@0 813 if (eq != NULL) {
duke@0 814 size_t value_len = strlen(prop) - key_len - 1;
duke@0 815 value = AllocateHeap(value_len + 1, "add_property");
duke@0 816 strncpy(value, &prop[key_len + 1], value_len + 1);
duke@0 817 }
duke@0 818
duke@0 819 if (strcmp(key, "java.compiler") == 0) {
duke@0 820 process_java_compiler_argument(value);
duke@0 821 FreeHeap(key);
duke@0 822 if (eq != NULL) {
duke@0 823 FreeHeap(value);
duke@0 824 }
duke@0 825 return true;
duke@0 826 }
duke@0 827 else if (strcmp(key, "sun.java.command") == 0) {
duke@0 828
duke@0 829 _java_command = value;
duke@0 830
duke@0 831 // don't add this property to the properties exposed to the java application
duke@0 832 FreeHeap(key);
duke@0 833 return true;
duke@0 834 }
duke@0 835 else if (strcmp(key, "sun.java.launcher.pid") == 0) {
duke@0 836 // launcher.pid property is private and is processed
duke@0 837 // in process_sun_java_launcher_properties();
duke@0 838 // the sun.java.launcher property is passed on to the java application
duke@0 839 FreeHeap(key);
duke@0 840 if (eq != NULL) {
duke@0 841 FreeHeap(value);
duke@0 842 }
duke@0 843 return true;
duke@0 844 }
duke@0 845 else if (strcmp(key, "java.vendor.url.bug") == 0) {
duke@0 846 // save it in _java_vendor_url_bug, so JVM fatal error handler can access
duke@0 847 // its value without going through the property list or making a Java call.
duke@0 848 _java_vendor_url_bug = value;
duke@0 849 }
duke@0 850
duke@0 851 // Create new property and add at the end of the list
duke@0 852 PropertyList_unique_add(&_system_properties, key, value);
duke@0 853 return true;
duke@0 854 }
duke@0 855
duke@0 856 //===========================================================================================================
duke@0 857 // Setting int/mixed/comp mode flags
duke@0 858
duke@0 859 void Arguments::set_mode_flags(Mode mode) {
duke@0 860 // Set up default values for all flags.
duke@0 861 // If you add a flag to any of the branches below,
duke@0 862 // add a default value for it here.
duke@0 863 set_java_compiler(false);
duke@0 864 _mode = mode;
duke@0 865
duke@0 866 // Ensure Agent_OnLoad has the correct initial values.
duke@0 867 // This may not be the final mode; mode may change later in onload phase.
duke@0 868 PropertyList_unique_add(&_system_properties, "java.vm.info",
duke@0 869 (char*)Abstract_VM_Version::vm_info_string());
duke@0 870
duke@0 871 UseInterpreter = true;
duke@0 872 UseCompiler = true;
duke@0 873 UseLoopCounter = true;
duke@0 874
duke@0 875 // Default values may be platform/compiler dependent -
duke@0 876 // use the saved values
duke@0 877 ClipInlining = Arguments::_ClipInlining;
duke@0 878 AlwaysCompileLoopMethods = Arguments::_AlwaysCompileLoopMethods;
duke@0 879 UseOnStackReplacement = Arguments::_UseOnStackReplacement;
duke@0 880 BackgroundCompilation = Arguments::_BackgroundCompilation;
duke@0 881 Tier2CompileThreshold = Arguments::_Tier2CompileThreshold;
duke@0 882
duke@0 883 // Change from defaults based on mode
duke@0 884 switch (mode) {
duke@0 885 default:
duke@0 886 ShouldNotReachHere();
duke@0 887 break;
duke@0 888 case _int:
duke@0 889 UseCompiler = false;
duke@0 890 UseLoopCounter = false;
duke@0 891 AlwaysCompileLoopMethods = false;
duke@0 892 UseOnStackReplacement = false;
duke@0 893 break;
duke@0 894 case _mixed:
duke@0 895 // same as default
duke@0 896 break;
duke@0 897 case _comp:
duke@0 898 UseInterpreter = false;
duke@0 899 BackgroundCompilation = false;
duke@0 900 ClipInlining = false;
duke@0 901 break;
duke@0 902 }
duke@0 903 }
duke@0 904
duke@0 905
duke@0 906 // Conflict: required to use shared spaces (-Xshare:on), but
duke@0 907 // incompatible command line options were chosen.
duke@0 908
duke@0 909 static void no_shared_spaces() {
duke@0 910 if (RequireSharedSpaces) {
duke@0 911 jio_fprintf(defaultStream::error_stream(),
duke@0 912 "Class data sharing is inconsistent with other specified options.\n");
duke@0 913 vm_exit_during_initialization("Unable to use shared archive.", NULL);
duke@0 914 } else {
duke@0 915 FLAG_SET_DEFAULT(UseSharedSpaces, false);
duke@0 916 }
duke@0 917 }
duke@0 918
duke@0 919
duke@0 920 // If the user has chosen ParallelGCThreads > 0, we set UseParNewGC
duke@0 921 // if it's not explictly set or unset. If the user has chosen
duke@0 922 // UseParNewGC and not explicitly set ParallelGCThreads we
duke@0 923 // set it, unless this is a single cpu machine.
duke@0 924 void Arguments::set_parnew_gc_flags() {
duke@0 925 assert(!UseSerialGC && !UseParallelGC, "control point invariant");
duke@0 926
jmasa@10 927 // Turn off AdaptiveSizePolicy by default for parnew until it is
jmasa@10 928 // complete.
jmasa@10 929 if (UseParNewGC &&
jmasa@10 930 FLAG_IS_DEFAULT(UseAdaptiveSizePolicy)) {
jmasa@10 931 FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
jmasa@10 932 }
jmasa@10 933
duke@0 934 if (FLAG_IS_DEFAULT(UseParNewGC) && ParallelGCThreads > 1) {
duke@0 935 FLAG_SET_DEFAULT(UseParNewGC, true);
duke@0 936 } else if (UseParNewGC && ParallelGCThreads == 0) {
jmasa@10 937 FLAG_SET_DEFAULT(ParallelGCThreads,
jmasa@10 938 Abstract_VM_Version::parallel_worker_threads());
duke@0 939 if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) {
duke@0 940 FLAG_SET_DEFAULT(UseParNewGC, false);
duke@0 941 }
duke@0 942 }
duke@0 943 if (!UseParNewGC) {
duke@0 944 FLAG_SET_DEFAULT(ParallelGCThreads, 0);
duke@0 945 } else {
duke@0 946 no_shared_spaces();
duke@0 947
duke@0 948 // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 correspondinly,
duke@0 949 // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration
duke@0 950 // we set them to 1024 and 1024.
duke@0 951 // See CR 6362902.
duke@0 952 if (FLAG_IS_DEFAULT(YoungPLABSize)) {
duke@0 953 FLAG_SET_DEFAULT(YoungPLABSize, (intx)1024);
duke@0 954 }
duke@0 955 if (FLAG_IS_DEFAULT(OldPLABSize)) {
duke@0 956 FLAG_SET_DEFAULT(OldPLABSize, (intx)1024);
duke@0 957 }
duke@0 958
duke@0 959 // AlwaysTenure flag should make ParNew to promote all at first collection.
duke@0 960 // See CR 6362902.
duke@0 961 if (AlwaysTenure) {
duke@0 962 FLAG_SET_CMDLINE(intx, MaxTenuringThreshold, 0);
duke@0 963 }
duke@0 964 }
duke@0 965 }
duke@0 966
duke@0 967 // Adjust some sizes to suit CMS and/or ParNew needs; these work well on
duke@0 968 // sparc/solaris for certain applications, but would gain from
duke@0 969 // further optimization and tuning efforts, and would almost
duke@0 970 // certainly gain from analysis of platform and environment.
duke@0 971 void Arguments::set_cms_and_parnew_gc_flags() {
duke@0 972 if (UseSerialGC || UseParallelGC) {
duke@0 973 return;
duke@0 974 }
duke@0 975
jmasa@10 976 assert(UseConcMarkSweepGC, "CMS is expected to be on here");
jmasa@10 977
duke@0 978 // If we are using CMS, we prefer to UseParNewGC,
duke@0 979 // unless explicitly forbidden.
jmasa@10 980 if (!UseParNewGC && FLAG_IS_DEFAULT(UseParNewGC)) {
jmasa@10 981 FLAG_SET_ERGO(bool, UseParNewGC, true);
duke@0 982 }
duke@0 983
duke@0 984 // Turn off AdaptiveSizePolicy by default for cms until it is
jmasa@10 985 // complete.
jmasa@10 986 if (FLAG_IS_DEFAULT(UseAdaptiveSizePolicy)) {
duke@0 987 FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
duke@0 988 }
duke@0 989
duke@0 990 // In either case, adjust ParallelGCThreads and/or UseParNewGC
duke@0 991 // as needed.
jmasa@10 992 if (UseParNewGC) {
jmasa@10 993 set_parnew_gc_flags();
duke@0 994 }
duke@0 995
duke@0 996 // Now make adjustments for CMS
duke@0 997 size_t young_gen_per_worker;
duke@0 998 intx new_ratio;
duke@0 999 size_t min_new_default;
duke@0 1000 intx tenuring_default;
duke@0 1001 if (CMSUseOldDefaults) { // old defaults: "old" as of 6.0
duke@0 1002 if FLAG_IS_DEFAULT(CMSYoungGenPerWorker) {
jmasa@13 1003 FLAG_SET_ERGO(intx, CMSYoungGenPerWorker, 4*M);
duke@0 1004 }
duke@0 1005 young_gen_per_worker = 4*M;
duke@0 1006 new_ratio = (intx)15;
duke@0 1007 min_new_default = 4*M;
duke@0 1008 tenuring_default = (intx)0;
duke@0 1009 } else { // new defaults: "new" as of 6.0
duke@0 1010 young_gen_per_worker = CMSYoungGenPerWorker;
duke@0 1011 new_ratio = (intx)7;
duke@0 1012 min_new_default = 16*M;
duke@0 1013 tenuring_default = (intx)4;
duke@0 1014 }
duke@0 1015
duke@0 1016 // Preferred young gen size for "short" pauses
duke@0 1017 const uintx parallel_gc_threads =
duke@0 1018 (ParallelGCThreads == 0 ? 1 : ParallelGCThreads);
duke@0 1019 const size_t preferred_max_new_size_unaligned =
duke@0 1020 ScaleForWordSize(young_gen_per_worker * parallel_gc_threads);
duke@0 1021 const size_t preferred_max_new_size =
duke@0 1022 align_size_up(preferred_max_new_size_unaligned, os::vm_page_size());
duke@0 1023
duke@0 1024 // Unless explicitly requested otherwise, size young gen
duke@0 1025 // for "short" pauses ~ 4M*ParallelGCThreads
duke@0 1026 if (FLAG_IS_DEFAULT(MaxNewSize)) { // MaxNewSize not set at command-line
duke@0 1027 if (!FLAG_IS_DEFAULT(NewSize)) { // NewSize explicitly set at command-line
jmasa@13 1028 FLAG_SET_ERGO(uintx, MaxNewSize, MAX2(NewSize, preferred_max_new_size));
duke@0 1029 } else {
jmasa@13 1030 FLAG_SET_ERGO(uintx, MaxNewSize, preferred_max_new_size);
duke@0 1031 }
jmasa@13 1032 if(PrintGCDetails && Verbose) {
jmasa@13 1033 // Too early to use gclog_or_tty
jmasa@13 1034 tty->print_cr("Ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize);
jmasa@13 1035 }
duke@0 1036 }
duke@0 1037 // Unless explicitly requested otherwise, prefer a large
duke@0 1038 // Old to Young gen size so as to shift the collection load
duke@0 1039 // to the old generation concurrent collector
duke@0 1040 if (FLAG_IS_DEFAULT(NewRatio)) {
jmasa@13 1041 FLAG_SET_ERGO(intx, NewRatio, MAX2(NewRatio, new_ratio));
duke@0 1042
duke@0 1043 size_t min_new = align_size_up(ScaleForWordSize(min_new_default), os::vm_page_size());
duke@0 1044 size_t prev_initial_size = initial_heap_size();
duke@0 1045 if (prev_initial_size != 0 && prev_initial_size < min_new+OldSize) {
duke@0 1046 set_initial_heap_size(min_new+OldSize);
duke@0 1047 // Currently minimum size and the initial heap sizes are the same.
duke@0 1048 set_min_heap_size(initial_heap_size());
duke@0 1049 if (PrintGCDetails && Verbose) {
duke@0 1050 warning("Initial heap size increased to " SIZE_FORMAT " M from "
duke@0 1051 SIZE_FORMAT " M; use -XX:NewSize=... for finer control.",
duke@0 1052 initial_heap_size()/M, prev_initial_size/M);
duke@0 1053 }
duke@0 1054 }
duke@0 1055 // MaxHeapSize is aligned down in collectorPolicy
duke@0 1056 size_t max_heap = align_size_down(MaxHeapSize,
duke@0 1057 CardTableRS::ct_max_alignment_constraint());
duke@0 1058
jmasa@13 1059 if(PrintGCDetails && Verbose) {
jmasa@13 1060 // Too early to use gclog_or_tty
jmasa@13 1061 tty->print_cr("CMS set min_heap_size: " SIZE_FORMAT
jmasa@13 1062 " initial_heap_size: " SIZE_FORMAT
jmasa@13 1063 " max_heap: " SIZE_FORMAT,
jmasa@13 1064 min_heap_size(), initial_heap_size(), max_heap);
jmasa@13 1065 }
duke@0 1066 if (max_heap > min_new) {
duke@0 1067 // Unless explicitly requested otherwise, make young gen
duke@0 1068 // at least min_new, and at most preferred_max_new_size.
duke@0 1069 if (FLAG_IS_DEFAULT(NewSize)) {
jmasa@13 1070 FLAG_SET_ERGO(uintx, NewSize, MAX2(NewSize, min_new));
jmasa@13 1071 FLAG_SET_ERGO(uintx, NewSize, MIN2(preferred_max_new_size, NewSize));
jmasa@13 1072 if(PrintGCDetails && Verbose) {
jmasa@13 1073 // Too early to use gclog_or_tty
jmasa@13 1074 tty->print_cr("Ergo set NewSize: " SIZE_FORMAT, NewSize);
jmasa@13 1075 }
duke@0 1076 }
duke@0 1077 // Unless explicitly requested otherwise, size old gen
duke@0 1078 // so that it's at least 3X of NewSize to begin with;
duke@0 1079 // later NewRatio will decide how it grows; see above.
duke@0 1080 if (FLAG_IS_DEFAULT(OldSize)) {
duke@0 1081 if (max_heap > NewSize) {
jmasa@13 1082 FLAG_SET_ERGO(uintx, OldSize, MIN2(3*NewSize, max_heap - NewSize));
jmasa@13 1083 if(PrintGCDetails && Verbose) {
jmasa@13 1084 // Too early to use gclog_or_tty
jmasa@13 1085 tty->print_cr("Ergo set OldSize: " SIZE_FORMAT, OldSize);
jmasa@13 1086 }
duke@0 1087 }
duke@0 1088 }
duke@0 1089 }
duke@0 1090 }
duke@0 1091 // Unless explicitly requested otherwise, definitely
duke@0 1092 // promote all objects surviving "tenuring_default" scavenges.
duke@0 1093 if (FLAG_IS_DEFAULT(MaxTenuringThreshold) &&
duke@0 1094 FLAG_IS_DEFAULT(SurvivorRatio)) {
jmasa@13 1095 FLAG_SET_ERGO(intx, MaxTenuringThreshold, tenuring_default);
duke@0 1096 }
duke@0 1097 // If we decided above (or user explicitly requested)
duke@0 1098 // `promote all' (via MaxTenuringThreshold := 0),
duke@0 1099 // prefer minuscule survivor spaces so as not to waste
duke@0 1100 // space for (non-existent) survivors
duke@0 1101 if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) {
jmasa@13 1102 FLAG_SET_ERGO(intx, SurvivorRatio, MAX2((intx)1024, SurvivorRatio));
duke@0 1103 }
duke@0 1104 // If OldPLABSize is set and CMSParPromoteBlocksToClaim is not,
duke@0 1105 // set CMSParPromoteBlocksToClaim equal to OldPLABSize.
duke@0 1106 // This is done in order to make ParNew+CMS configuration to work
duke@0 1107 // with YoungPLABSize and OldPLABSize options.
duke@0 1108 // See CR 6362902.
duke@0 1109 if (!FLAG_IS_DEFAULT(OldPLABSize)) {
duke@0 1110 if (FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim)) {
jmasa@13 1111 // OldPLABSize is not the default value but CMSParPromoteBlocksToClaim
jmasa@13 1112 // is. In this situtation let CMSParPromoteBlocksToClaim follow
jmasa@13 1113 // the value (either from the command line or ergonomics) of
jmasa@13 1114 // OldPLABSize. Following OldPLABSize is an ergonomics decision.
jmasa@13 1115 FLAG_SET_ERGO(uintx, CMSParPromoteBlocksToClaim, OldPLABSize);
duke@0 1116 }
duke@0 1117 else {
duke@0 1118 // OldPLABSize and CMSParPromoteBlocksToClaim are both set.
duke@0 1119 // CMSParPromoteBlocksToClaim is a collector-specific flag, so
duke@0 1120 // we'll let it to take precedence.
duke@0 1121 jio_fprintf(defaultStream::error_stream(),
duke@0 1122 "Both OldPLABSize and CMSParPromoteBlocksToClaim options are specified "
duke@0 1123 "for the CMS collector. CMSParPromoteBlocksToClaim will take precedence.\n");
duke@0 1124 }
duke@0 1125 }
duke@0 1126 }
duke@0 1127
coleenp@135 1128 inline uintx max_heap_for_compressed_oops() {
coleenp@135 1129 LP64_ONLY(return oopDesc::OopEncodingHeapMax - MaxPermSize - os::vm_page_size());
coleenp@135 1130 NOT_LP64(return DefaultMaxRAM);
coleenp@135 1131 }
coleenp@135 1132
duke@0 1133 bool Arguments::should_auto_select_low_pause_collector() {
duke@0 1134 if (UseAutoGCSelectPolicy &&
duke@0 1135 !FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
duke@0 1136 (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
duke@0 1137 if (PrintGCDetails) {
duke@0 1138 // Cannot use gclog_or_tty yet.
duke@0 1139 tty->print_cr("Automatic selection of the low pause collector"
duke@0 1140 " based on pause goal of %d (ms)", MaxGCPauseMillis);
duke@0 1141 }
duke@0 1142 return true;
duke@0 1143 }
duke@0 1144 return false;
duke@0 1145 }
duke@0 1146
duke@0 1147 void Arguments::set_ergonomics_flags() {
duke@0 1148 // Parallel GC is not compatible with sharing. If one specifies
duke@0 1149 // that they want sharing explicitly, do not set ergonmics flags.
duke@0 1150 if (DumpSharedSpaces || ForceSharedSpaces) {
duke@0 1151 return;
duke@0 1152 }
duke@0 1153
duke@0 1154 if (os::is_server_class_machine() && !force_client_mode ) {
duke@0 1155 // If no other collector is requested explicitly,
duke@0 1156 // let the VM select the collector based on
duke@0 1157 // machine class and automatic selection policy.
duke@0 1158 if (!UseSerialGC &&
duke@0 1159 !UseConcMarkSweepGC &&
duke@0 1160 !UseParNewGC &&
duke@0 1161 !DumpSharedSpaces &&
duke@0 1162 FLAG_IS_DEFAULT(UseParallelGC)) {
duke@0 1163 if (should_auto_select_low_pause_collector()) {
duke@0 1164 FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
duke@0 1165 } else {
duke@0 1166 FLAG_SET_ERGO(bool, UseParallelGC, true);
duke@0 1167 }
duke@0 1168 no_shared_spaces();
duke@0 1169 }
duke@0 1170 }
coleenp@113 1171
coleenp@113 1172 #ifdef _LP64
coleenp@113 1173 // Compressed Headers do not work with CMS, which uses a bit in the klass
coleenp@113 1174 // field offset to determine free list chunk markers.
coleenp@113 1175 // Check that UseCompressedOops can be set with the max heap size allocated
coleenp@113 1176 // by ergonomics.
coleenp@187 1177 if (MaxHeapSize <= max_heap_for_compressed_oops()) {
coleenp@113 1178 if (FLAG_IS_DEFAULT(UseCompressedOops)) {
rasbold@185 1179 // Leave compressed oops off by default. Uncomment
rasbold@185 1180 // the following line to return it to default status.
rasbold@185 1181 // FLAG_SET_ERGO(bool, UseCompressedOops, true);
coleenp@113 1182 }
coleenp@113 1183 } else {
coleenp@113 1184 if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
coleenp@113 1185 // If specified, give a warning
coleenp@113 1186 if (UseConcMarkSweepGC){
coleenp@113 1187 warning("Compressed Oops does not work with CMS");
coleenp@113 1188 } else {
coleenp@113 1189 warning(
coleenp@113 1190 "Max heap size too large for Compressed Oops");
coleenp@113 1191 }
coleenp@113 1192 FLAG_SET_DEFAULT(UseCompressedOops, false);
coleenp@113 1193 }
coleenp@113 1194 }
coleenp@113 1195 // Also checks that certain machines are slower with compressed oops
coleenp@113 1196 // in vm_version initialization code.
coleenp@113 1197 #endif // _LP64
duke@0 1198 }
duke@0 1199
duke@0 1200 void Arguments::set_parallel_gc_flags() {
duke@0 1201 // If parallel old was requested, automatically enable parallel scavenge.
duke@0 1202 if (UseParallelOldGC && !UseParallelGC && FLAG_IS_DEFAULT(UseParallelGC)) {
duke@0 1203 FLAG_SET_DEFAULT(UseParallelGC, true);
duke@0 1204 }
duke@0 1205
duke@0 1206 // If no heap maximum was requested explicitly, use some reasonable fraction
duke@0 1207 // of the physical memory, up to a maximum of 1GB.
duke@0 1208 if (UseParallelGC) {
jmasa@10 1209 FLAG_SET_ERGO(uintx, ParallelGCThreads,
jmasa@10 1210 Abstract_VM_Version::parallel_worker_threads());
jmasa@10 1211
duke@0 1212 if (FLAG_IS_DEFAULT(MaxHeapSize)) {
duke@0 1213 const uint64_t reasonable_fraction =
duke@0 1214 os::physical_memory() / DefaultMaxRAMFraction;
coleenp@135 1215 const uint64_t maximum_size = (uint64_t)
coleenp@135 1216 (FLAG_IS_DEFAULT(DefaultMaxRAM) && UseCompressedOops ?
coleenp@135 1217 MIN2(max_heap_for_compressed_oops(), DefaultMaxRAM) :
coleenp@135 1218 DefaultMaxRAM);
duke@0 1219 size_t reasonable_max =
duke@0 1220 (size_t) os::allocatable_physical_memory(reasonable_fraction);
duke@0 1221 if (reasonable_max > maximum_size) {
duke@0 1222 reasonable_max = maximum_size;
duke@0 1223 }
duke@0 1224 if (PrintGCDetails && Verbose) {
duke@0 1225 // Cannot use gclog_or_tty yet.
duke@0 1226 tty->print_cr(" Max heap size for server class platform "
duke@0 1227 SIZE_FORMAT, reasonable_max);
duke@0 1228 }
duke@0 1229 // If the initial_heap_size has not been set with -Xms,
duke@0 1230 // then set it as fraction of size of physical memory
duke@0 1231 // respecting the maximum and minimum sizes of the heap.
duke@0 1232 if (initial_heap_size() == 0) {
duke@0 1233 const uint64_t reasonable_initial_fraction =
duke@0 1234 os::physical_memory() / DefaultInitialRAMFraction;
duke@0 1235 const size_t reasonable_initial =
duke@0 1236 (size_t) os::allocatable_physical_memory(reasonable_initial_fraction);
duke@0 1237 const size_t minimum_size = NewSize + OldSize;
duke@0 1238 set_initial_heap_size(MAX2(MIN2(reasonable_initial, reasonable_max),
duke@0 1239 minimum_size));
duke@0 1240 // Currently the minimum size and the initial heap sizes are the same.
duke@0 1241 set_min_heap_size(initial_heap_size());
duke@0 1242 if (PrintGCDetails && Verbose) {
duke@0 1243 // Cannot use gclog_or_tty yet.
duke@0 1244 tty->print_cr(" Initial heap size for server class platform "
duke@0 1245 SIZE_FORMAT, initial_heap_size());
duke@0 1246 }
duke@0 1247 } else {
duke@0 1248 // An minimum size was specified on the command line. Be sure
duke@0 1249 // that the maximum size is consistent.
duke@0 1250 if (initial_heap_size() > reasonable_max) {
duke@0 1251 reasonable_max = initial_heap_size();
duke@0 1252 }
duke@0 1253 }
duke@0 1254 FLAG_SET_ERGO(uintx, MaxHeapSize, (uintx) reasonable_max);
duke@0 1255 }
duke@0 1256
duke@0 1257 // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the
duke@0 1258 // SurvivorRatio has been set, reset their default values to SurvivorRatio +
duke@0 1259 // 2. By doing this we make SurvivorRatio also work for Parallel Scavenger.
duke@0 1260 // See CR 6362902 for details.
duke@0 1261 if (!FLAG_IS_DEFAULT(SurvivorRatio)) {
duke@0 1262 if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) {
duke@0 1263 FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2);
duke@0 1264 }
duke@0 1265 if (FLAG_IS_DEFAULT(MinSurvivorRatio)) {
duke@0 1266 FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2);
duke@0 1267 }
duke@0 1268 }
duke@0 1269
duke@0 1270 if (UseParallelOldGC) {
duke@0 1271 // Par compact uses lower default values since they are treated as
jmasa@13 1272 // minimums. These are different defaults because of the different
jmasa@13 1273 // interpretation and are not ergonomically set.
duke@0 1274 if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) {
jmasa@13 1275 FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1);
duke@0 1276 }
duke@0 1277 if (FLAG_IS_DEFAULT(PermMarkSweepDeadRatio)) {
jmasa@13 1278 FLAG_SET_DEFAULT(PermMarkSweepDeadRatio, 5);
duke@0 1279 }
duke@0 1280 }
duke@0 1281 }
duke@0 1282 }
duke@0 1283
duke@0 1284 // This must be called after ergonomics because we want bytecode rewriting
duke@0 1285 // if the server compiler is used, or if UseSharedSpaces is disabled.
duke@0 1286 void Arguments::set_bytecode_flags() {
duke@0 1287 // Better not attempt to store into a read-only space.
duke@0 1288 if (UseSharedSpaces) {
duke@0 1289 FLAG_SET_DEFAULT(RewriteBytecodes, false);
duke@0 1290 FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
duke@0 1291 }
duke@0 1292
duke@0 1293 if (!RewriteBytecodes) {
duke@0 1294 FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
duke@0 1295 }
duke@0 1296 }
duke@0 1297
duke@0 1298 // Aggressive optimization flags -XX:+AggressiveOpts
duke@0 1299 void Arguments::set_aggressive_opts_flags() {
never@17 1300 #ifdef COMPILER2
never@17 1301 if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
never@17 1302 if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
never@17 1303 FLAG_SET_DEFAULT(EliminateAutoBox, true);
never@17 1304 }
never@17 1305 if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
never@17 1306 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000);
never@17 1307 }
never@17 1308
never@17 1309 // Feed the cache size setting into the JDK
never@17 1310 char buffer[1024];
never@17 1311 sprintf(buffer, "java.lang.Integer.IntegerCache.high=%d", AutoBoxCacheMax);
never@17 1312 add_property(buffer);
never@17 1313 }
kvn@65 1314 if (AggressiveOpts && FLAG_IS_DEFAULT(DoEscapeAnalysis)) {
kvn@65 1315 FLAG_SET_DEFAULT(DoEscapeAnalysis, true);
kvn@65 1316 }
rasbold@169 1317 if (AggressiveOpts && FLAG_IS_DEFAULT(SpecialArraysEquals)) {
rasbold@169 1318 FLAG_SET_DEFAULT(SpecialArraysEquals, true);
rasbold@169 1319 }
never@17 1320 #endif
never@17 1321
duke@0 1322 if (AggressiveOpts) {
sbohne@61 1323 // Sample flag setting code
sbohne@61 1324 // if (FLAG_IS_DEFAULT(EliminateZeroing)) {
sbohne@61 1325 // FLAG_SET_DEFAULT(EliminateZeroing, true);
sbohne@61 1326 // }
duke@0 1327 }
duke@0 1328 }
duke@0 1329
duke@0 1330 //===========================================================================================================
duke@0 1331 // Parsing of java.compiler property
duke@0 1332
duke@0 1333 void Arguments::process_java_compiler_argument(char* arg) {
duke@0 1334 // For backwards compatibility, Djava.compiler=NONE or ""
duke@0 1335 // causes us to switch to -Xint mode UNLESS -Xdebug
duke@0 1336 // is also specified.
duke@0 1337 if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) {
duke@0 1338 set_java_compiler(true); // "-Djava.compiler[=...]" most recently seen.
duke@0 1339 }
duke@0 1340 }
duke@0 1341
duke@0 1342 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) {
duke@0 1343 _sun_java_launcher = strdup(launcher);
duke@0 1344 }
duke@0 1345
duke@0 1346 bool Arguments::created_by_java_launcher() {
duke@0 1347 assert(_sun_java_launcher != NULL, "property must have value");
duke@0 1348 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
duke@0 1349 }
duke@0 1350
duke@0 1351 //===========================================================================================================
duke@0 1352 // Parsing of main arguments
duke@0 1353
duke@0 1354 bool Arguments::verify_percentage(uintx value, const char* name) {
duke@0 1355 if (value <= 100) {
duke@0 1356 return true;
duke@0 1357 }
duke@0 1358 jio_fprintf(defaultStream::error_stream(),
duke@0 1359 "%s of " UINTX_FORMAT " is invalid; must be between 0 and 100\n",
duke@0 1360 name, value);
duke@0 1361 return false;
duke@0 1362 }
duke@0 1363
duke@0 1364 static void set_serial_gc_flags() {
duke@0 1365 FLAG_SET_DEFAULT(UseSerialGC, true);
duke@0 1366 FLAG_SET_DEFAULT(UseParNewGC, false);
duke@0 1367 FLAG_SET_DEFAULT(UseConcMarkSweepGC, false);
duke@0 1368 FLAG_SET_DEFAULT(UseParallelGC, false);
duke@0 1369 FLAG_SET_DEFAULT(UseParallelOldGC, false);
duke@0 1370 }
duke@0 1371
duke@0 1372 static bool verify_serial_gc_flags() {
duke@0 1373 return (UseSerialGC &&
duke@0 1374 !(UseParNewGC || UseConcMarkSweepGC || UseParallelGC ||
duke@0 1375 UseParallelOldGC));
duke@0 1376 }
duke@0 1377
jmasa@10 1378 // Check consistency of GC selection
jmasa@10 1379 bool Arguments::check_gc_consistency() {
jmasa@10 1380 bool status = true;
jmasa@10 1381 // Ensure that the user has not selected conflicting sets
jmasa@10 1382 // of collectors. [Note: this check is merely a user convenience;
jmasa@10 1383 // collectors over-ride each other so that only a non-conflicting
jmasa@10 1384 // set is selected; however what the user gets is not what they
jmasa@10 1385 // may have expected from the combination they asked for. It's
jmasa@10 1386 // better to reduce user confusion by not allowing them to
jmasa@10 1387 // select conflicting combinations.
jmasa@10 1388 uint i = 0;
jmasa@10 1389 if (UseSerialGC) i++;
jmasa@10 1390 if (UseConcMarkSweepGC || UseParNewGC) i++;
jmasa@10 1391 if (UseParallelGC || UseParallelOldGC) i++;
jmasa@10 1392 if (i > 1) {
jmasa@10 1393 jio_fprintf(defaultStream::error_stream(),
jmasa@10 1394 "Conflicting collector combinations in option list; "
jmasa@10 1395 "please refer to the release notes for the combinations "
jmasa@10 1396 "allowed\n");
jmasa@10 1397 status = false;
jmasa@10 1398 }
jmasa@10 1399
jmasa@10 1400 return status;
jmasa@10 1401 }
jmasa@10 1402
duke@0 1403 // Check the consistency of vm_init_args
duke@0 1404 bool Arguments::check_vm_args_consistency() {
duke@0 1405 // Method for adding checks for flag consistency.
duke@0 1406 // The intent is to warn the user of all possible conflicts,
duke@0 1407 // before returning an error.
duke@0 1408 // Note: Needs platform-dependent factoring.
duke@0 1409 bool status = true;
duke@0 1410
duke@0 1411 #if ( (defined(COMPILER2) && defined(SPARC)))
duke@0 1412 // NOTE: The call to VM_Version_init depends on the fact that VM_Version_init
duke@0 1413 // on sparc doesn't require generation of a stub as is the case on, e.g.,
duke@0 1414 // x86. Normally, VM_Version_init must be called from init_globals in
duke@0 1415 // init.cpp, which is called by the initial java thread *after* arguments
duke@0 1416 // have been parsed. VM_Version_init gets called twice on sparc.
duke@0 1417 extern void VM_Version_init();
duke@0 1418 VM_Version_init();
duke@0 1419 if (!VM_Version::has_v9()) {
duke@0 1420 jio_fprintf(defaultStream::error_stream(),
duke@0 1421 "V8 Machine detected, Server requires V9\n");
duke@0 1422 status = false;
duke@0 1423 }
duke@0 1424 #endif /* COMPILER2 && SPARC */
duke@0 1425
duke@0 1426 // Allow both -XX:-UseStackBanging and -XX:-UseBoundThreads in non-product
duke@0 1427 // builds so the cost of stack banging can be measured.
duke@0 1428 #if (defined(PRODUCT) && defined(SOLARIS))
duke@0 1429 if (!UseBoundThreads && !UseStackBanging) {
duke@0 1430 jio_fprintf(defaultStream::error_stream(),
duke@0 1431 "-UseStackBanging conflicts with -UseBoundThreads\n");
duke@0 1432
duke@0 1433 status = false;
duke@0 1434 }
duke@0 1435 #endif
duke@0 1436
duke@0 1437 if (TLABRefillWasteFraction == 0) {
duke@0 1438 jio_fprintf(defaultStream::error_stream(),
duke@0 1439 "TLABRefillWasteFraction should be a denominator, "
duke@0 1440 "not " SIZE_FORMAT "\n",
duke@0 1441 TLABRefillWasteFraction);
duke@0 1442 status = false;
duke@0 1443 }
duke@0 1444
jmasa@10 1445 status = status && verify_percentage(MaxLiveObjectEvacuationRatio,
duke@0 1446 "MaxLiveObjectEvacuationRatio");
jmasa@10 1447 status = status && verify_percentage(AdaptiveSizePolicyWeight,
duke@0 1448 "AdaptiveSizePolicyWeight");
jmasa@10 1449 status = status && verify_percentage(AdaptivePermSizeWeight, "AdaptivePermSizeWeight");
jmasa@10 1450 status = status && verify_percentage(ThresholdTolerance, "ThresholdTolerance");
jmasa@10 1451 status = status && verify_percentage(MinHeapFreeRatio, "MinHeapFreeRatio");
jmasa@10 1452 status = status && verify_percentage(MaxHeapFreeRatio, "MaxHeapFreeRatio");
duke@0 1453
duke@0 1454 if (MinHeapFreeRatio > MaxHeapFreeRatio) {
duke@0 1455 jio_fprintf(defaultStream::error_stream(),
duke@0 1456 "MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or "
duke@0 1457 "equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n",
duke@0 1458 MinHeapFreeRatio, MaxHeapFreeRatio);
duke@0 1459 status = false;
duke@0 1460 }
duke@0 1461 // Keeping the heap 100% free is hard ;-) so limit it to 99%.
duke@0 1462 MinHeapFreeRatio = MIN2(MinHeapFreeRatio, (uintx) 99);
duke@0 1463
duke@0 1464 if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
duke@0 1465 MarkSweepAlwaysCompactCount = 1; // Move objects every gc.
duke@0 1466 }
duke@0 1467
jmasa@10 1468 status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
jmasa@10 1469 status = status && verify_percentage(GCTimeLimit, "GCTimeLimit");
duke@0 1470 if (GCTimeLimit == 100) {
duke@0 1471 // Turn off gc-overhead-limit-exceeded checks
duke@0 1472 FLAG_SET_DEFAULT(UseGCOverheadLimit, false);
duke@0 1473 }
duke@0 1474
jmasa@10 1475 status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
duke@0 1476
duke@0 1477 // Check user specified sharing option conflict with Parallel GC
duke@0 1478 bool cannot_share = (UseConcMarkSweepGC || UseParallelGC ||
duke@0 1479 UseParallelOldGC || UseParNewGC ||
duke@0 1480 SOLARIS_ONLY(UseISM) NOT_SOLARIS(UseLargePages));
duke@0 1481
duke@0 1482 if (cannot_share) {
duke@0 1483 // Either force sharing on by forcing the other options off, or
duke@0 1484 // force sharing off.
duke@0 1485 if (DumpSharedSpaces || ForceSharedSpaces) {
duke@0 1486 set_serial_gc_flags();
duke@0 1487 FLAG_SET_DEFAULT(SOLARIS_ONLY(UseISM) NOT_SOLARIS(UseLargePages), false);
duke@0 1488 } else {
duke@0 1489 no_shared_spaces();
duke@0 1490 }
duke@0 1491 }
duke@0 1492
jmasa@10 1493 status = status && check_gc_consistency();
duke@0 1494
duke@0 1495 if (_has_alloc_profile) {
duke@0 1496 if (UseParallelGC || UseParallelOldGC) {
duke@0 1497 jio_fprintf(defaultStream::error_stream(),
duke@0 1498 "error: invalid argument combination.\n"
duke@0 1499 "Allocation profiling (-Xaprof) cannot be used together with "
duke@0 1500 "Parallel GC (-XX:+UseParallelGC or -XX:+UseParallelOldGC).\n");
duke@0 1501 status = false;
duke@0 1502 }
duke@0 1503 if (UseConcMarkSweepGC) {
duke@0 1504 jio_fprintf(defaultStream::error_stream(),
duke@0 1505 "error: invalid argument combination.\n"
duke@0 1506 "Allocation profiling (-Xaprof) cannot be used together with "
duke@0 1507 "the CMS collector (-XX:+UseConcMarkSweepGC).\n");
duke@0 1508 status = false;
duke@0 1509 }
duke@0 1510 }
duke@0 1511
duke@0 1512 if (CMSIncrementalMode) {
duke@0 1513 if (!UseConcMarkSweepGC) {
duke@0 1514 jio_fprintf(defaultStream::error_stream(),
duke@0 1515 "error: invalid argument combination.\n"
duke@0 1516 "The CMS collector (-XX:+UseConcMarkSweepGC) must be "
duke@0 1517 "selected in order\nto use CMSIncrementalMode.\n");
duke@0 1518 status = false;
duke@0 1519 } else if (!UseTLAB) {
duke@0 1520 jio_fprintf(defaultStream::error_stream(),
duke@0 1521 "error: CMSIncrementalMode requires thread-local "
duke@0 1522 "allocation buffers\n(-XX:+UseTLAB).\n");
duke@0 1523 status = false;
duke@0 1524 } else {
jmasa@10 1525 status = status && verify_percentage(CMSIncrementalDutyCycle,
duke@0 1526 "CMSIncrementalDutyCycle");
jmasa@10 1527 status = status && verify_percentage(CMSIncrementalDutyCycleMin,
duke@0 1528 "CMSIncrementalDutyCycleMin");
jmasa@10 1529 status = status && verify_percentage(CMSIncrementalSafetyFactor,
duke@0 1530 "CMSIncrementalSafetyFactor");
jmasa@10 1531 status = status && verify_percentage(CMSIncrementalOffset,
duke@0 1532 "CMSIncrementalOffset");
jmasa@10 1533 status = status && verify_percentage(CMSExpAvgFactor,
duke@0 1534 "CMSExpAvgFactor");
duke@0 1535 // If it was not set on the command line, set
duke@0 1536 // CMSInitiatingOccupancyFraction to 1 so icms can initiate cycles early.
duke@0 1537 if (CMSInitiatingOccupancyFraction < 0) {
duke@0 1538 FLAG_SET_DEFAULT(CMSInitiatingOccupancyFraction, 1);
duke@0 1539 }
duke@0 1540 }
duke@0 1541 }
duke@0 1542
duke@0 1543 if (UseNUMA && !UseTLAB) {
duke@0 1544 jio_fprintf(defaultStream::error_stream(),
duke@0 1545 "error: NUMA allocator (-XX:+UseNUMA) requires thread-local "
duke@0 1546 "allocation\nbuffers (-XX:+UseTLAB).\n");
duke@0 1547 status = false;
duke@0 1548 }
duke@0 1549
duke@0 1550 // CMS space iteration, which FLSVerifyAllHeapreferences entails,
duke@0 1551 // insists that we hold the requisite locks so that the iteration is
duke@0 1552 // MT-safe. For the verification at start-up and shut-down, we don't
duke@0 1553 // yet have a good way of acquiring and releasing these locks,
duke@0 1554 // which are not visible at the CollectedHeap level. We want to
duke@0 1555 // be able to acquire these locks and then do the iteration rather
duke@0 1556 // than just disable the lock verification. This will be fixed under
duke@0 1557 // bug 4788986.
duke@0 1558 if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) {
duke@0 1559 if (VerifyGCStartAt == 0) {
duke@0 1560 warning("Heap verification at start-up disabled "
duke@0 1561 "(due to current incompatibility with FLSVerifyAllHeapReferences)");
duke@0 1562 VerifyGCStartAt = 1; // Disable verification at start-up
duke@0 1563 }
duke@0 1564 if (VerifyBeforeExit) {
duke@0 1565 warning("Heap verification at shutdown disabled "
duke@0 1566 "(due to current incompatibility with FLSVerifyAllHeapReferences)");
duke@0 1567 VerifyBeforeExit = false; // Disable verification at shutdown
duke@0 1568 }
duke@0 1569 }
duke@0 1570
duke@0 1571 // Note: only executed in non-PRODUCT mode
duke@0 1572 if (!UseAsyncConcMarkSweepGC &&
duke@0 1573 (ExplicitGCInvokesConcurrent ||
duke@0 1574 ExplicitGCInvokesConcurrentAndUnloadsClasses)) {
duke@0 1575 jio_fprintf(defaultStream::error_stream(),
duke@0 1576 "error: +ExplictGCInvokesConcurrent[AndUnloadsClasses] conflicts"
duke@0 1577 " with -UseAsyncConcMarkSweepGC");
duke@0 1578 status = false;
duke@0 1579 }
duke@0 1580
duke@0 1581 return status;
duke@0 1582 }
duke@0 1583
duke@0 1584 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore,
duke@0 1585 const char* option_type) {
duke@0 1586 if (ignore) return false;
duke@0 1587
duke@0 1588 const char* spacer = " ";
duke@0 1589 if (option_type == NULL) {
duke@0 1590 option_type = ++spacer; // Set both to the empty string.
duke@0 1591 }
duke@0 1592
duke@0 1593 if (os::obsolete_option(option)) {
duke@0 1594 jio_fprintf(defaultStream::error_stream(),
duke@0 1595 "Obsolete %s%soption: %s\n", option_type, spacer,
duke@0 1596 option->optionString);
duke@0 1597 return false;
duke@0 1598 } else {
duke@0 1599 jio_fprintf(defaultStream::error_stream(),
duke@0 1600 "Unrecognized %s%soption: %s\n", option_type, spacer,
duke@0 1601 option->optionString);
duke@0 1602 return true;
duke@0 1603 }
duke@0 1604 }
duke@0 1605
duke@0 1606 static const char* user_assertion_options[] = {
duke@0 1607 "-da", "-ea", "-disableassertions", "-enableassertions", 0
duke@0 1608 };
duke@0 1609
duke@0 1610 static const char* system_assertion_options[] = {
duke@0 1611 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0
duke@0 1612 };
duke@0 1613
duke@0 1614 // Return true if any of the strings in null-terminated array 'names' matches.
duke@0 1615 // If tail_allowed is true, then the tail must begin with a colon; otherwise,
duke@0 1616 // the option must match exactly.
duke@0 1617 static bool match_option(const JavaVMOption* option, const char** names, const char** tail,
duke@0 1618 bool tail_allowed) {
duke@0 1619 for (/* empty */; *names != NULL; ++names) {
duke@0 1620 if (match_option(option, *names, tail)) {
duke@0 1621 if (**tail == '\0' || tail_allowed && **tail == ':') {
duke@0 1622 return true;
duke@0 1623 }
duke@0 1624 }
duke@0 1625 }
duke@0 1626 return false;
duke@0 1627 }
duke@0 1628
duke@0 1629 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
duke@0 1630 jlong* long_arg,
duke@0 1631 jlong min_size) {
duke@0 1632 if (!atomll(s, long_arg)) return arg_unreadable;
duke@0 1633 return check_memory_size(*long_arg, min_size);
duke@0 1634 }
duke@0 1635
duke@0 1636 // Parse JavaVMInitArgs structure
duke@0 1637
duke@0 1638 jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) {
duke@0 1639 // For components of the system classpath.
duke@0 1640 SysClassPath scp(Arguments::get_sysclasspath());
duke@0 1641 bool scp_assembly_required = false;
duke@0 1642
duke@0 1643 // Save default settings for some mode flags
duke@0 1644 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
duke@0 1645 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
duke@0 1646 Arguments::_ClipInlining = ClipInlining;
duke@0 1647 Arguments::_BackgroundCompilation = BackgroundCompilation;
duke@0 1648 Arguments::_Tier2CompileThreshold = Tier2CompileThreshold;
duke@0 1649
duke@0 1650 // Parse JAVA_TOOL_OPTIONS environment variable (if present)
duke@0 1651 jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required);
duke@0 1652 if (result != JNI_OK) {
duke@0 1653 return result;
duke@0 1654 }
duke@0 1655
duke@0 1656 // Parse JavaVMInitArgs structure passed in
duke@0 1657 result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, COMMAND_LINE);
duke@0 1658 if (result != JNI_OK) {
duke@0 1659 return result;
duke@0 1660 }
duke@0 1661
duke@0 1662 // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM)
duke@0 1663 result = parse_java_options_environment_variable(&scp, &scp_assembly_required);
duke@0 1664 if (result != JNI_OK) {
duke@0 1665 return result;
duke@0 1666 }
duke@0 1667
duke@0 1668 // Do final processing now that all arguments have been parsed
duke@0 1669 result = finalize_vm_init_args(&scp, scp_assembly_required);
duke@0 1670 if (result != JNI_OK) {
duke@0 1671 return result;
duke@0 1672 }
duke@0 1673
duke@0 1674 return JNI_OK;
duke@0 1675 }
duke@0 1676
duke@0 1677
duke@0 1678 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
duke@0 1679 SysClassPath* scp_p,
duke@0 1680 bool* scp_assembly_required_p,
duke@0 1681 FlagValueOrigin origin) {
duke@0 1682 // Remaining part of option string
duke@0 1683 const char* tail;
duke@0 1684
duke@0 1685 // iterate over arguments
duke@0 1686 for (int index = 0; index < args->nOptions; index++) {
duke@0 1687 bool is_absolute_path = false; // for -agentpath vs -agentlib
duke@0 1688
duke@0 1689 const JavaVMOption* option = args->options + index;
duke@0 1690
duke@0 1691 if (!match_option(option, "-Djava.class.path", &tail) &&
duke@0 1692 !match_option(option, "-Dsun.java.command", &tail) &&
duke@0 1693 !match_option(option, "-Dsun.java.launcher", &tail)) {
duke@0 1694
duke@0 1695 // add all jvm options to the jvm_args string. This string
duke@0 1696 // is used later to set the java.vm.args PerfData string constant.
duke@0 1697 // the -Djava.class.path and the -Dsun.java.command options are
duke@0 1698 // omitted from jvm_args string as each have their own PerfData
duke@0 1699 // string constant object.
duke@0 1700 build_jvm_args(option->optionString);
duke@0 1701 }
duke@0 1702
duke@0 1703 // -verbose:[class/gc/jni]
duke@0 1704 if (match_option(option, "-verbose", &tail)) {
duke@0 1705 if (!strcmp(tail, ":class") || !strcmp(tail, "")) {
duke@0 1706 FLAG_SET_CMDLINE(bool, TraceClassLoading, true);
duke@0 1707 FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
duke@0 1708 } else if (!strcmp(tail, ":gc")) {
duke@0 1709 FLAG_SET_CMDLINE(bool, PrintGC, true);
duke@0 1710 FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
duke@0 1711 } else if (!strcmp(tail, ":jni")) {
duke@0 1712 FLAG_SET_CMDLINE(bool, PrintJNIResolving, true);
duke@0 1713 }
duke@0 1714 // -da / -ea / -disableassertions / -enableassertions
duke@0 1715 // These accept an optional class/package name separated by a colon, e.g.,
duke@0 1716 // -da:java.lang.Thread.
duke@0 1717 } else if (match_option(option, user_assertion_options, &tail, true)) {
duke@0 1718 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e'
duke@0 1719 if (*tail == '\0') {
duke@0 1720 JavaAssertions::setUserClassDefault(enable);
duke@0 1721 } else {
duke@0 1722 assert(*tail == ':', "bogus match by match_option()");
duke@0 1723 JavaAssertions::addOption(tail + 1, enable);
duke@0 1724 }
duke@0 1725 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions
duke@0 1726 } else if (match_option(option, system_assertion_options, &tail, false)) {
duke@0 1727 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e'
duke@0 1728 JavaAssertions::setSystemClassDefault(enable);
duke@0 1729 // -bootclasspath:
duke@0 1730 } else if (match_option(option, "-Xbootclasspath:", &tail)) {
duke@0 1731 scp_p->reset_path(tail);
duke@0 1732 *scp_assembly_required_p = true;
duke@0 1733 // -bootclasspath/a:
duke@0 1734 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) {
duke@0 1735 scp_p->add_suffix(tail);
duke@0 1736 *scp_assembly_required_p = true;
duke@0 1737 // -bootclasspath/p:
duke@0 1738 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) {
duke@0 1739 scp_p->add_prefix(tail);
duke@0 1740 *scp_assembly_required_p = true;
duke@0 1741 // -Xrun
duke@0 1742 } else if (match_option(option, "-Xrun", &tail)) {
duke@0 1743 if(tail != NULL) {
duke@0 1744 const char* pos = strchr(tail, ':');
duke@0 1745 size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
duke@0 1746 char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
duke@0 1747 name[len] = '\0';
duke@0 1748
duke@0 1749 char *options = NULL;
duke@0 1750 if(pos != NULL) {
duke@0 1751 size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied.
duke@0 1752 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2), pos+1, len2);
duke@0 1753 }
duke@0 1754 #ifdef JVMTI_KERNEL
duke@0 1755 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
duke@0 1756 warning("profiling and debugging agents are not supported with Kernel VM");
duke@0 1757 } else
duke@0 1758 #endif // JVMTI_KERNEL
duke@0 1759 add_init_library(name, options);
duke@0 1760 }
duke@0 1761 // -agentlib and -agentpath
duke@0 1762 } else if (match_option(option, "-agentlib:", &tail) ||
duke@0 1763 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
duke@0 1764 if(tail != NULL) {
duke@0 1765 const char* pos = strchr(tail, '=');
duke@0 1766 size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
duke@0 1767 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
duke@0 1768 name[len] = '\0';
duke@0 1769
duke@0 1770 char *options = NULL;
duke@0 1771 if(pos != NULL) {
duke@0 1772 options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1), pos + 1);
duke@0 1773 }
duke@0 1774 #ifdef JVMTI_KERNEL
duke@0 1775 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
duke@0 1776 warning("profiling and debugging agents are not supported with Kernel VM");
duke@0 1777 } else
duke@0 1778 #endif // JVMTI_KERNEL
duke@0 1779 add_init_agent(name, options, is_absolute_path);
duke@0 1780
duke@0 1781 }
duke@0 1782 // -javaagent
duke@0 1783 } else if (match_option(option, "-javaagent:", &tail)) {
duke@0 1784 if(tail != NULL) {
duke@0 1785 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1), tail);
duke@0 1786 add_init_agent("instrument", options, false);
duke@0 1787 }
duke@0 1788 // -Xnoclassgc
duke@0 1789 } else if (match_option(option, "-Xnoclassgc", &tail)) {
duke@0 1790 FLAG_SET_CMDLINE(bool, ClassUnloading, false);
duke@0 1791 // -Xincgc: i-CMS
duke@0 1792 } else if (match_option(option, "-Xincgc", &tail)) {
duke@0 1793 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
duke@0 1794 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, true);
duke@0 1795 // -Xnoincgc: no i-CMS
duke@0 1796 } else if (match_option(option, "-Xnoincgc", &tail)) {
duke@0 1797 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
duke@0 1798 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, false);
duke@0 1799 // -Xconcgc
duke@0 1800 } else if (match_option(option, "-Xconcgc", &tail)) {
duke@0 1801 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
duke@0 1802 // -Xnoconcgc
duke@0 1803 } else if (match_option(option, "-Xnoconcgc", &tail)) {
duke@0 1804 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
duke@0 1805 // -Xbatch
duke@0 1806 } else if (match_option(option, "-Xbatch", &tail)) {
duke@0 1807 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
duke@0 1808 // -Xmn for compatibility with other JVM vendors
duke@0 1809 } else if (match_option(option, "-Xmn", &tail)) {
duke@0 1810 jlong long_initial_eden_size = 0;
duke@0 1811 ArgsRange errcode = parse_memory_size(tail, &long_initial_eden_size, 1);
duke@0 1812 if (errcode != arg_in_range) {
duke@0 1813 jio_fprintf(defaultStream::error_stream(),
duke@0 1814 "Invalid initial eden size: %s\n", option->optionString);
duke@0 1815 describe_range_error(errcode);
duke@0 1816 return JNI_EINVAL;
duke@0 1817 }
duke@0 1818 FLAG_SET_CMDLINE(uintx, MaxNewSize, (size_t) long_initial_eden_size);
duke@0 1819 FLAG_SET_CMDLINE(uintx, NewSize, (size_t) long_initial_eden_size);
duke@0 1820 // -Xms
duke@0 1821 } else if (match_option(option, "-Xms", &tail)) {
duke@0 1822 jlong long_initial_heap_size = 0;
duke@0 1823 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 1);
duke@0 1824 if (errcode != arg_in_range) {
duke@0 1825 jio_fprintf(defaultStream::error_stream(),
duke@0 1826 "Invalid initial heap size: %s\n", option->optionString);
duke@0 1827 describe_range_error(errcode);
duke@0 1828 return JNI_EINVAL;
duke@0 1829 }
duke@0 1830 set_initial_heap_size((size_t) long_initial_heap_size);
duke@0 1831 // Currently the minimum size and the initial heap sizes are the same.
duke@0 1832 set_min_heap_size(initial_heap_size());
duke@0 1833 // -Xmx
duke@0 1834 } else if (match_option(option, "-Xmx", &tail)) {
duke@0 1835 jlong long_max_heap_size = 0;
duke@0 1836 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
duke@0 1837 if (errcode != arg_in_range) {
duke@0 1838 jio_fprintf(defaultStream::error_stream(),
duke@0 1839 "Invalid maximum heap size: %s\n", option->optionString);
duke@0 1840 describe_range_error(errcode);
duke@0 1841 return JNI_EINVAL;
duke@0 1842 }
duke@0 1843 FLAG_SET_CMDLINE(uintx, MaxHeapSize, (size_t) long_max_heap_size);
duke@0 1844 // Xmaxf
duke@0 1845 } else if (match_option(option, "-Xmaxf", &tail)) {
duke@0 1846 int maxf = (int)(atof(tail) * 100);
duke@0 1847 if (maxf < 0 || maxf > 100) {
duke@0 1848 jio_fprintf(defaultStream::error_stream(),
duke@0 1849 "Bad max heap free percentage size: %s\n",
duke@0 1850 option->optionString);
duke@0 1851 return JNI_EINVAL;
duke@0 1852 } else {
duke@0 1853 FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf);
duke@0 1854 }
duke@0 1855 // Xminf
duke@0 1856 } else if (match_option(option, "-Xminf", &tail)) {
duke@0 1857 int minf = (int)(atof(tail) * 100);
duke@0 1858 if (minf < 0 || minf > 100) {
duke@0 1859 jio_fprintf(defaultStream::error_stream(),
duke@0 1860 "Bad min heap free percentage size: %s\n",
duke@0 1861 option->optionString);
duke@0 1862 return JNI_EINVAL;
duke@0 1863 } else {
duke@0 1864 FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf);
duke@0 1865 }
duke@0 1866 // -Xss
duke@0 1867 } else if (match_option(option, "-Xss", &tail)) {
duke@0 1868 jlong long_ThreadStackSize = 0;
duke@0 1869 ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
duke@0 1870 if (errcode != arg_in_range) {
duke@0 1871 jio_fprintf(defaultStream::error_stream(),
duke@0 1872 "Invalid thread stack size: %s\n", option->optionString);
duke@0 1873 describe_range_error(errcode);
duke@0 1874 return JNI_EINVAL;
duke@0 1875 }
duke@0 1876 // Internally track ThreadStackSize in units of 1024 bytes.
duke@0 1877 FLAG_SET_CMDLINE(intx, ThreadStackSize,
duke@0 1878 round_to((int)long_ThreadStackSize, K) / K);
duke@0 1879 // -Xoss
duke@0 1880 } else if (match_option(option, "-Xoss", &tail)) {
duke@0 1881 // HotSpot does not have separate native and Java stacks, ignore silently for compatibility
duke@0 1882 // -Xmaxjitcodesize
duke@0 1883 } else if (match_option(option, "-Xmaxjitcodesize", &tail)) {
duke@0 1884 jlong long_ReservedCodeCacheSize = 0;
duke@0 1885 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize,
duke@0 1886 InitialCodeCacheSize);
duke@0 1887 if (errcode != arg_in_range) {
duke@0 1888 jio_fprintf(defaultStream::error_stream(),
duke@0 1889 "Invalid maximum code cache size: %s\n",
duke@0 1890 option->optionString);
duke@0 1891 describe_range_error(errcode);
duke@0 1892 return JNI_EINVAL;
duke@0 1893 }
duke@0 1894 FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize);
duke@0 1895 // -green
duke@0 1896 } else if (match_option(option, "-green", &tail)) {
duke@0 1897 jio_fprintf(defaultStream::error_stream(),
duke@0 1898 "Green threads support not available\n");
duke@0 1899 return JNI_EINVAL;
duke@0 1900 // -native
duke@0 1901 } else if (match_option(option, "-native", &tail)) {
duke@0 1902 // HotSpot always uses native threads, ignore silently for compatibility
duke@0 1903 // -Xsqnopause
duke@0 1904 } else if (match_option(option, "-Xsqnopause", &tail)) {
duke@0 1905 // EVM option, ignore silently for compatibility
duke@0 1906 // -Xrs
duke@0 1907 } else if (match_option(option, "-Xrs", &tail)) {
duke@0 1908 // Classic/EVM option, new functionality
duke@0 1909 FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true);
duke@0 1910 } else if (match_option(option, "-Xusealtsigs", &tail)) {
duke@0 1911 // change default internal VM signals used - lower case for back compat
duke@0 1912 FLAG_SET_CMDLINE(bool, UseAltSigs, true);
duke@0 1913 // -Xoptimize
duke@0 1914 } else if (match_option(option, "-Xoptimize", &tail)) {
duke@0 1915 // EVM option, ignore silently for compatibility
duke@0 1916 // -Xprof
duke@0 1917 } else if (match_option(option, "-Xprof", &tail)) {
duke@0 1918 #ifndef FPROF_KERNEL
duke@0 1919 _has_profile = true;
duke@0 1920 #else // FPROF_KERNEL
duke@0 1921 // do we have to exit?
duke@0 1922 warning("Kernel VM does not support flat profiling.");
duke@0 1923 #endif // FPROF_KERNEL
duke@0 1924 // -Xaprof
duke@0 1925 } else if (match_option(option, "-Xaprof", &tail)) {
duke@0 1926 _has_alloc_profile = true;
duke@0 1927 // -Xconcurrentio
duke@0 1928 } else if (match_option(option, "-Xconcurrentio", &tail)) {
duke@0 1929 FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true);
duke@0 1930 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
duke@0 1931 FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1);
duke@0 1932 FLAG_SET_CMDLINE(bool, UseTLAB, false);
duke@0 1933 FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K); // 20Kb per thread added to new generation
duke@0 1934
duke@0 1935 // -Xinternalversion
duke@0 1936 } else if (match_option(option, "-Xinternalversion", &tail)) {
duke@0 1937 jio_fprintf(defaultStream::output_stream(), "%s\n",
duke@0 1938 VM_Version::internal_vm_info_string());
duke@0 1939 vm_exit(0);
duke@0 1940 #ifndef PRODUCT
duke@0 1941 // -Xprintflags
duke@0 1942 } else if (match_option(option, "-Xprintflags", &tail)) {
duke@0 1943 CommandLineFlags::printFlags();
duke@0 1944 vm_exit(0);
duke@0 1945 #endif
duke@0 1946 // -D
duke@0 1947 } else if (match_option(option, "-D", &tail)) {
duke@0 1948 if (!add_property(tail)) {
duke@0 1949 return JNI_ENOMEM;
duke@0 1950 }
duke@0 1951 // Out of the box management support
duke@0 1952 if (match_option(option, "-Dcom.sun.management", &tail)) {
duke@0 1953 FLAG_SET_CMDLINE(bool, ManagementServer, true);
duke@0 1954 }
duke@0 1955 // -Xint
duke@0 1956 } else if (match_option(option, "-Xint", &tail)) {
duke@0 1957 set_mode_flags(_int);
duke@0 1958 // -Xmixed
duke@0 1959 } else if (match_option(option, "-Xmixed", &tail)) {
duke@0 1960 set_mode_flags(_mixed);
duke@0 1961 // -Xcomp
duke@0 1962 } else if (match_option(option, "-Xcomp", &tail)) {
duke@0 1963 // for testing the compiler; turn off all flags that inhibit compilation
duke@0 1964 set_mode_flags(_comp);
duke@0 1965
duke@0 1966 // -Xshare:dump
duke@0 1967 } else if (match_option(option, "-Xshare:dump", &tail)) {
duke@0 1968 #ifdef TIERED
duke@0 1969 FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
duke@0 1970 set_mode_flags(_int); // Prevent compilation, which creates objects
duke@0 1971 #elif defined(COMPILER2)
duke@0 1972 vm_exit_during_initialization(
duke@0 1973 "Dumping a shared archive is not supported on the Server JVM.", NULL);
duke@0 1974 #elif defined(KERNEL)
duke@0 1975 vm_exit_during_initialization(
duke@0 1976 "Dumping a shared archive is not supported on the Kernel JVM.", NULL);
duke@0 1977 #else
duke@0 1978 FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
duke@0 1979 set_mode_flags(_int); // Prevent compilation, which creates objects
duke@0 1980 #endif
duke@0 1981 // -Xshare:on
duke@0 1982 } else if (match_option(option, "-Xshare:on", &tail)) {
duke@0 1983 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
duke@0 1984 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true);
duke@0 1985 #ifdef TIERED
duke@0 1986 FLAG_SET_CMDLINE(bool, ForceSharedSpaces, true);
duke@0 1987 #endif // TIERED
duke@0 1988 // -Xshare:auto
duke@0 1989 } else if (match_option(option, "-Xshare:auto", &tail)) {
duke@0 1990 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
duke@0 1991 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
duke@0 1992 // -Xshare:off
duke@0 1993 } else if (match_option(option, "-Xshare:off", &tail)) {
duke@0 1994 FLAG_SET_CMDLINE(bool, UseSharedSpaces, false);
duke@0 1995 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
duke@0 1996
duke@0 1997 // -Xverify
duke@0 1998 } else if (match_option(option, "-Xverify", &tail)) {
duke@0 1999 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) {
duke@0 2000 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true);
duke@0 2001 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
duke@0 2002 } else if (strcmp(tail, ":remote") == 0) {
duke@0 2003 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
duke@0 2004 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
duke@0 2005 } else if (strcmp(tail, ":none") == 0) {
duke@0 2006 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
duke@0 2007 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false);
duke@0 2008 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) {
duke@0 2009 return JNI_EINVAL;
duke@0 2010 }
duke@0 2011 // -Xdebug
duke@0 2012 } else if (match_option(option, "-Xdebug", &tail)) {
duke@0 2013 // note this flag has been used, then ignore
duke@0 2014 set_xdebug_mode(true);
duke@0 2015 // -Xnoagent
duke@0 2016 } else if (match_option(option, "-Xnoagent", &tail)) {
duke@0 2017 // For compatibility with classic. HotSpot refuses to load the old style agent.dll.
duke@0 2018 } else if (match_option(option, "-Xboundthreads", &tail)) {
duke@0 2019 // Bind user level threads to kernel threads (Solaris only)
duke@0 2020 FLAG_SET_CMDLINE(bool, UseBoundThreads, true);
duke@0 2021 } else if (match_option(option, "-Xloggc:", &tail)) {
duke@0 2022 // Redirect GC output to the file. -Xloggc:<filename>
duke@0 2023 // ostream_init_log(), when called will use this filename
duke@0 2024 // to initialize a fileStream.
duke@0 2025 _gc_log_filename = strdup(tail);
duke@0 2026 FLAG_SET_CMDLINE(bool, PrintGC, true);
duke@0 2027 FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true);
duke@0 2028 FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
duke@0 2029
duke@0 2030 // JNI hooks
duke@0 2031 } else if (match_option(option, "-Xcheck", &tail)) {
duke@0 2032 if (!strcmp(tail, ":jni")) {
duke@0 2033 CheckJNICalls = true;
duke@0 2034 } else if (is_bad_option(option, args->ignoreUnrecognized,
duke@0 2035 "check")) {
duke@0 2036 return JNI_EINVAL;
duke@0 2037 }
duke@0 2038 } else if (match_option(option, "vfprintf", &tail)) {
duke@0 2039 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo);
duke@0 2040 } else if (match_option(option, "exit", &tail)) {
duke@0 2041 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
duke@0 2042 } else if (match_option(option, "abort", &tail)) {
duke@0 2043 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
duke@0 2044 // -XX:+AggressiveHeap
duke@0 2045 } else if (match_option(option, "-XX:+AggressiveHeap", &tail)) {
duke@0 2046
duke@0 2047 // This option inspects the machine and attempts to set various
duke@0 2048 // parameters to be optimal for long-running, memory allocation
duke@0 2049 // intensive jobs. It is intended for machines with large
duke@0 2050 // amounts of cpu and memory.
duke@0 2051
duke@0 2052 // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
duke@0 2053 // VM, but we may not be able to represent the total physical memory
duke@0 2054 // available (like having 8gb of memory on a box but using a 32bit VM).
duke@0 2055 // Thus, we need to make sure we're using a julong for intermediate
duke@0 2056 // calculations.
duke@0 2057 julong initHeapSize;
duke@0 2058 julong total_memory = os::physical_memory();
duke@0 2059
duke@0 2060 if (total_memory < (julong)256*M) {
duke@0 2061 jio_fprintf(defaultStream::error_stream(),
duke@0 2062 "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
duke@0 2063 vm_exit(1);
duke@0 2064 }
duke@0 2065
duke@0 2066 // The heap size is half of available memory, or (at most)
duke@0 2067 // all of possible memory less 160mb (leaving room for the OS
duke@0 2068 // when using ISM). This is the maximum; because adaptive sizing
duke@0 2069 // is turned on below, the actual space used may be smaller.
duke@0 2070
duke@0 2071 initHeapSize = MIN2(total_memory / (julong)2,
duke@0 2072 total_memory - (julong)160*M);
duke@0 2073
duke@0 2074 // Make sure that if we have a lot of memory we cap the 32 bit
duke@0 2075 // process space. The 64bit VM version of this function is a nop.
duke@0 2076 initHeapSize = os::allocatable_physical_memory(initHeapSize);
duke@0 2077
duke@0 2078 // The perm gen is separate but contiguous with the
duke@0 2079 // object heap (and is reserved with it) so subtract it
duke@0 2080 // from the heap size.
duke@0 2081 if (initHeapSize > MaxPermSize) {
duke@0 2082 initHeapSize = initHeapSize - MaxPermSize;
duke@0 2083 } else {
duke@0 2084 warning("AggressiveHeap and MaxPermSize values may conflict");
duke@0 2085 }
duke@0 2086
duke@0 2087 if (FLAG_IS_DEFAULT(MaxHeapSize)) {
duke@0 2088 FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize);
duke@0 2089 set_initial_heap_size(MaxHeapSize);
duke@0 2090 // Currently the minimum size and the initial heap sizes are the same.
duke@0 2091 set_min_heap_size(initial_heap_size());
duke@0 2092 }
duke@0 2093 if (FLAG_IS_DEFAULT(NewSize)) {
duke@0 2094 // Make the young generation 3/8ths of the total heap.
duke@0 2095 FLAG_SET_CMDLINE(uintx, NewSize,
duke@0 2096 ((julong)MaxHeapSize / (julong)8) * (julong)3);
duke@0 2097 FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
duke@0 2098 }
duke@0 2099
duke@0 2100 FLAG_SET_DEFAULT(UseLargePages, true);
duke@0 2101
duke@0 2102 // Increase some data structure sizes for efficiency
duke@0 2103 FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
duke@0 2104 FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
duke@0 2105 FLAG_SET_CMDLINE(uintx, TLABSize, 256*K);
duke@0 2106
duke@0 2107 // See the OldPLABSize comment below, but replace 'after promotion'
duke@0 2108 // with 'after copying'. YoungPLABSize is the size of the survivor
duke@0 2109 // space per-gc-thread buffers. The default is 4kw.
duke@0 2110 FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256*K); // Note: this is in words
duke@0 2111
duke@0 2112 // OldPLABSize is the size of the buffers in the old gen that
duke@0 2113 // UseParallelGC uses to promote live data that doesn't fit in the
duke@0 2114 // survivor spaces. At any given time, there's one for each gc thread.
duke@0 2115 // The default size is 1kw. These buffers are rarely used, since the
duke@0 2116 // survivor spaces are usually big enough. For specjbb, however, there
duke@0 2117 // are occasions when there's lots of live data in the young gen
duke@0 2118 // and we end up promoting some of it. We don't have a definite
duke@0 2119 // explanation for why bumping OldPLABSize helps, but the theory
duke@0 2120 // is that a bigger PLAB results in retaining something like the
duke@0 2121 // original allocation order after promotion, which improves mutator
duke@0 2122 // locality. A minor effect may be that larger PLABs reduce the
duke@0 2123 // number of PLAB allocation events during gc. The value of 8kw
duke@0 2124 // was arrived at by experimenting with specjbb.
duke@0 2125 FLAG_SET_CMDLINE(uintx, OldPLABSize, 8*K); // Note: this is in words
duke@0 2126
duke@0 2127 // CompilationPolicyChoice=0 causes the server compiler to adopt
duke@0 2128 // a more conservative which-method-do-I-compile policy when one
duke@0 2129 // of the counters maintained by the interpreter trips. The
duke@0 2130 // result is reduced startup time and improved specjbb and
duke@0 2131 // alacrity performance. Zero is the default, but we set it
duke@0 2132 // explicitly here in case the default changes.
duke@0 2133 // See runtime/compilationPolicy.*.
duke@0 2134 FLAG_SET_CMDLINE(intx, CompilationPolicyChoice, 0);
duke@0 2135
duke@0 2136 // Enable parallel GC and adaptive generation sizing
duke@0 2137 FLAG_SET_CMDLINE(bool, UseParallelGC, true);
jmasa@10 2138 FLAG_SET_DEFAULT(ParallelGCThreads,
jmasa@10 2139 Abstract_VM_Version::parallel_worker_threads());
duke@0 2140
duke@0 2141 // Encourage steady state memory management
duke@0 2142 FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
duke@0 2143
duke@0 2144 // This appears to improve mutator locality
duke@0 2145 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
duke@0 2146
duke@0 2147 // Get around early Solaris scheduling bug
duke@0 2148 // (affinity vs other jobs on system)
duke@0 2149 // but disallow DR and offlining (5008695).
duke@0 2150 FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
duke@0 2151
duke@0 2152 } else if (match_option(option, "-XX:+NeverTenure", &tail)) {
duke@0 2153 // The last option must always win.
duke@0 2154 FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
duke@0 2155 FLAG_SET_CMDLINE(bool, NeverTenure, true);
duke@0 2156 } else if (match_option(option, "-XX:+AlwaysTenure", &tail)) {
duke@0 2157 // The last option must always win.
duke@0 2158 FLAG_SET_CMDLINE(bool, NeverTenure, false);
duke@0 2159 FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
duke@0 2160 } else if (match_option(option, "-XX:+CMSPermGenSweepingEnabled", &tail) ||
duke@0 2161 match_option(option, "-XX:-CMSPermGenSweepingEnabled", &tail)) {
duke@0 2162 jio_fprintf(defaultStream::error_stream(),
duke@0 2163 "Please use CMSClassUnloadingEnabled in place of "
duke@0 2164 "CMSPermGenSweepingEnabled in the future\n");
duke@0 2165 } else if (match_option(option, "-XX:+UseGCTimeLimit", &tail)) {
duke@0 2166 FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, true);
duke@0 2167 jio_fprintf(defaultStream::error_stream(),
duke@0 2168 "Please use -XX:+UseGCOverheadLimit in place of "
duke@0 2169 "-XX:+UseGCTimeLimit in the future\n");
duke@0 2170 } else if (match_option(option, "-XX:-UseGCTimeLimit", &tail)) {
duke@0 2171 FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, false);
duke@0 2172 jio_fprintf(defaultStream::error_stream(),
duke@0 2173 "Please use -XX:-UseGCOverheadLimit in place of "
duke@0 2174 "-XX:-UseGCTimeLimit in the future\n");
duke@0 2175 // The TLE options are for compatibility with 1.3 and will be
duke@0 2176 // removed without notice in a future release. These options
duke@0 2177 // are not to be documented.
duke@0 2178 } else if (match_option(option, "-XX:MaxTLERatio=", &tail)) {
duke@0 2179 // No longer used.
duke@0 2180 } else if (match_option(option, "-XX:+ResizeTLE", &tail)) {
duke@0 2181 FLAG_SET_CMDLINE(bool, ResizeTLAB, true);
duke@0 2182 } else if (match_option(option, "-XX:-ResizeTLE", &tail)) {
duke@0 2183 FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
duke@0 2184 } else if (match_option(option, "-XX:+PrintTLE", &tail)) {
duke@0 2185 FLAG_SET_CMDLINE(bool, PrintTLAB, true);
duke@0 2186 } else if (match_option(option, "-XX:-PrintTLE", &tail)) {
duke@0 2187 FLAG_SET_CMDLINE(bool, PrintTLAB, false);
duke@0 2188 } else if (match_option(option, "-XX:TLEFragmentationRatio=", &tail)) {
duke@0 2189 // No longer used.
duke@0 2190 } else if (match_option(option, "-XX:TLESize=", &tail)) {
duke@0 2191 jlong long_tlab_size = 0;
duke@0 2192 ArgsRange errcode = parse_memory_size(tail, &long_tlab_size, 1);
duke@0 2193 if (errcode != arg_in_range) {
duke@0 2194 jio_fprintf(defaultStream::error_stream(),
duke@0 2195 "Invalid TLAB size: %s\n", option->optionString);
duke@0 2196 describe_range_error(errcode);
duke@0 2197 return JNI_EINVAL;
duke@0 2198 }
duke@0 2199 FLAG_SET_CMDLINE(uintx, TLABSize, long_tlab_size);
duke@0 2200 } else if (match_option(option, "-XX:TLEThreadRatio=", &tail)) {
duke@0 2201 // No longer used.
duke@0 2202 } else if (match_option(option, "-XX:+UseTLE", &tail)) {
duke@0 2203 FLAG_SET_CMDLINE(bool, UseTLAB, true);
duke@0 2204 } else if (match_option(option, "-XX:-UseTLE", &tail)) {
duke@0 2205 FLAG_SET_CMDLINE(bool, UseTLAB, false);
duke@0 2206 SOLARIS_ONLY(
duke@0 2207 } else if (match_option(option, "-XX:+UsePermISM", &tail)) {
duke@0 2208 warning("-XX:+UsePermISM is obsolete.");
duke@0 2209 FLAG_SET_CMDLINE(bool, UseISM, true);
duke@0 2210 } else if (match_option(option, "-XX:-UsePermISM", &tail)) {
duke@0 2211 FLAG_SET_CMDLINE(bool, UseISM, false);
duke@0 2212 )
duke@0 2213 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr", &tail)) {
duke@0 2214 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false);
duke@0 2215 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true);
duke@0 2216 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout", &tail)) {
duke@0 2217 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false);
duke@0 2218 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true);
duke@0 2219 } else if (match_option(option, "-XX:+ExtendedDTraceProbes", &tail)) {
duke@0 2220 #ifdef SOLARIS
duke@0 2221 FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true);
duke@0 2222 FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true);
duke@0 2223 FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true);
duke@0 2224 FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true);
duke@0 2225 #else // ndef SOLARIS
duke@0 2226 jio_fprintf(defaultStream::error_stream(),
duke@0 2227 "ExtendedDTraceProbes flag is only applicable on Solaris\n");
duke@0 2228 return JNI_EINVAL;
duke@0 2229 #endif // ndef SOLARIS
duke@0 2230 } else
duke@0 2231 #ifdef ASSERT
duke@0 2232 if (match_option(option, "-XX:+FullGCALot", &tail)) {
duke@0 2233 FLAG_SET_CMDLINE(bool, FullGCALot, true);
duke@0 2234 // disable scavenge before parallel mark-compact
duke@0 2235 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
duke@0 2236 } else
duke@0 2237 #endif
duke@0 2238 if (match_option(option, "-XX:ParCMSPromoteBlocksToClaim=", &tail)) {
duke@0 2239 julong cms_blocks_to_claim = (julong)atol(tail);
duke@0 2240 FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim);
duke@0 2241 jio_fprintf(defaultStream::error_stream(),
duke@0 2242 "Please use -XX:CMSParPromoteBlocksToClaim in place of "
duke@0 2243 "-XX:ParCMSPromoteBlocksToClaim in the future\n");
duke@0 2244 } else
duke@0 2245 if (match_option(option, "-XX:ParallelGCOldGenAllocBufferSize=", &tail)) {
duke@0 2246 jlong old_plab_size = 0;
duke@0 2247 ArgsRange errcode = parse_memory_size(tail, &old_plab_size, 1);
duke@0 2248 if (errcode != arg_in_range) {
duke@0 2249 jio_fprintf(defaultStream::error_stream(),
duke@0 2250 "Invalid old PLAB size: %s\n", option->optionString);
duke@0 2251 describe_range_error(errcode);
duke@0 2252 return JNI_EINVAL;
duke@0 2253 }
duke@0 2254 FLAG_SET_CMDLINE(uintx, OldPLABSize, (julong)old_plab_size);
duke@0 2255 jio_fprintf(defaultStream::error_stream(),
duke@0 2256 "Please use -XX:OldPLABSize in place of "
duke@0 2257 "-XX:ParallelGCOldGenAllocBufferSize in the future\n");
duke@0 2258 } else
duke@0 2259 if (match_option(option, "-XX:ParallelGCToSpaceAllocBufferSize=", &tail)) {
duke@0 2260 jlong young_plab_size = 0;
duke@0 2261 ArgsRange errcode = parse_memory_size(tail, &young_plab_size, 1);
duke@0 2262 if (errcode != arg_in_range) {
duke@0 2263 jio_fprintf(defaultStream::error_stream(),
duke@0 2264 "Invalid young PLAB size: %s\n", option->optionString);
duke@0 2265 describe_range_error(errcode);
duke@0 2266 return JNI_EINVAL;
duke@0 2267 }
duke@0 2268 FLAG_SET_CMDLINE(uintx, YoungPLABSize, (julong)young_plab_size);
duke@0 2269 jio_fprintf(defaultStream::error_stream(),
duke@0 2270 "Please use -XX:YoungPLABSize in place of "
duke@0 2271 "-XX:ParallelGCToSpaceAllocBufferSize in the future\n");
duke@0 2272 } else
duke@0 2273 if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
duke@0 2274 // Skip -XX:Flags= since that case has already been handled
duke@0 2275 if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) {
duke@0 2276 if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
duke@0 2277 return JNI_EINVAL;
duke@0 2278 }
duke@0 2279 }
duke@0 2280 // Unknown option
duke@0 2281 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
duke@0 2282 return JNI_ERR;
duke@0 2283 }
duke@0 2284 }
duke@0 2285
duke@0 2286 return JNI_OK;
duke@0 2287 }
duke@0 2288
duke@0 2289 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) {
duke@0 2290 // This must be done after all -D arguments have been processed.
duke@0 2291 scp_p->expand_endorsed();
duke@0 2292
duke@0 2293 if (scp_assembly_required || scp_p->get_endorsed() != NULL) {
duke@0 2294 // Assemble the bootclasspath elements into the final path.
duke@0 2295 Arguments::set_sysclasspath(scp_p->combined_path());
duke@0 2296 }
duke@0 2297
duke@0 2298 // This must be done after all arguments have been processed.
duke@0 2299 // java_compiler() true means set to "NONE" or empty.
duke@0 2300 if (java_compiler() && !xdebug_mode()) {
duke@0 2301 // For backwards compatibility, we switch to interpreted mode if
duke@0 2302 // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was
duke@0 2303 // not specified.
duke@0 2304 set_mode_flags(_int);
duke@0 2305 }
duke@0 2306 if (CompileThreshold == 0) {
duke@0 2307 set_mode_flags(_int);
duke@0 2308 }
duke@0 2309
duke@0 2310 #ifdef TIERED
duke@0 2311 // If we are using tiered compilation in the tiered vm then c1 will
duke@0 2312 // do the profiling and we don't want to waste that time in the
duke@0 2313 // interpreter.
duke@0 2314 if (TieredCompilation) {
duke@0 2315 ProfileInterpreter = false;
duke@0 2316 } else {
duke@0 2317 // Since we are running vanilla server we must adjust the compile threshold
duke@0 2318 // unless the user has already adjusted it because the default threshold assumes
duke@0 2319 // we will run tiered.
duke@0 2320
duke@0 2321 if (FLAG_IS_DEFAULT(CompileThreshold)) {
duke@0 2322 CompileThreshold = Tier2CompileThreshold;
duke@0 2323 }
duke@0 2324 }
duke@0 2325 #endif // TIERED
duke@0 2326
duke@0 2327 #ifndef COMPILER2
duke@0 2328 // Don't degrade server performance for footprint
duke@0 2329 if (FLAG_IS_DEFAULT(UseLargePages) &&
duke@0 2330 MaxHeapSize < LargePageHeapSizeThreshold) {
duke@0 2331 // No need for large granularity pages w/small heaps.
duke@0 2332 // Note that large pages are enabled/disabled for both the
duke@0 2333 // Java heap and the code cache.
duke@0 2334 FLAG_SET_DEFAULT(UseLargePages, false);
duke@0 2335 SOLARIS_ONLY(FLAG_SET_DEFAULT(UseMPSS, false));
duke@0 2336 SOLARIS_ONLY(FLAG_SET_DEFAULT(UseISM, false));
duke@0 2337 }
duke@0 2338 #else
duke@0 2339 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
duke@0 2340 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
duke@0 2341 }
duke@0 2342 #endif
duke@0 2343
duke@0 2344 if (!check_vm_args_consistency()) {
duke@0 2345 return JNI_ERR;
duke@0 2346 }
duke@0 2347
duke@0 2348 return JNI_OK;
duke@0 2349 }
duke@0 2350
duke@0 2351 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
duke@0 2352 return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
duke@0 2353 scp_assembly_required_p);
duke@0 2354 }
duke@0 2355
duke@0 2356 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
duke@0 2357 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p,
duke@0 2358 scp_assembly_required_p);
duke@0 2359 }
duke@0 2360
duke@0 2361 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) {
duke@0 2362 const int N_MAX_OPTIONS = 64;
duke@0 2363 const int OPTION_BUFFER_SIZE = 1024;
duke@0 2364 char buffer[OPTION_BUFFER_SIZE];
duke@0 2365
duke@0 2366 // The variable will be ignored if it exceeds the length of the buffer.
duke@0 2367 // Don't check this variable if user has special privileges
duke@0 2368 // (e.g. unix su command).
duke@0 2369 if (os::getenv(name, buffer, sizeof(buffer)) &&
duke@0 2370 !os::have_special_privileges()) {
duke@0 2371 JavaVMOption options[N_MAX_OPTIONS]; // Construct option array
duke@0 2372 jio_fprintf(defaultStream::error_stream(),
duke@0 2373 "Picked up %s: %s\n", name, buffer);
duke@0 2374 char* rd = buffer; // pointer to the input string (rd)
duke@0 2375 int i;
duke@0 2376 for (i = 0; i < N_MAX_OPTIONS;) { // repeat for all options in the input string
duke@0 2377 while (isspace(*rd)) rd++; // skip whitespace
duke@0 2378 if (*rd == 0) break; // we re done when the input string is read completely
duke@0 2379
duke@0 2380 // The output, option string, overwrites the input string.
duke@0 2381 // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
duke@0 2382 // input string (rd).
duke@0 2383 char* wrt = rd;
duke@0 2384
duke@0 2385 options[i++].optionString = wrt; // Fill in option
duke@0 2386 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL
duke@0 2387 if (*rd == '\'' || *rd == '"') { // handle a quoted string
duke@0 2388 int quote = *rd; // matching quote to look for
duke@0 2389 rd++; // don't copy open quote
duke@0 2390 while (*rd != quote) { // include everything (even spaces) up until quote
duke@0 2391 if (*rd == 0) { // string termination means unmatched string
duke@0 2392 jio_fprintf(defaultStream::error_stream(),
duke@0 2393 "Unmatched quote in %s\n", name);
duke@0 2394 return JNI_ERR;
duke@0 2395 }
duke@0 2396 *wrt++ = *rd++; // copy to option string
duke@0 2397 }
duke@0 2398 rd++; // don't copy close quote
duke@0 2399 } else {
duke@0 2400 *wrt++ = *rd++; // copy to option string
duke@0 2401 }
duke@0 2402 }
duke@0 2403 // Need to check if we're done before writing a NULL,
duke@0 2404 // because the write could be to the byte that rd is pointing to.
duke@0 2405 if (*rd++ == 0) {
duke@0 2406 *wrt = 0;
duke@0 2407 break;
duke@0 2408 }
duke@0 2409 *wrt = 0; // Zero terminate option
duke@0 2410 }
duke@0 2411 // Construct JavaVMInitArgs structure and parse as if it was part of the command line
duke@0 2412 JavaVMInitArgs vm_args;
duke@0 2413 vm_args.version = JNI_VERSION_1_2;
duke@0 2414 vm_args.options = options;
duke@0 2415 vm_args.nOptions = i;
duke@0 2416 vm_args.ignoreUnrecognized = false;
duke@0 2417
duke@0 2418 if (PrintVMOptions) {
duke@0 2419 const char* tail;
duke@0 2420 for (int i = 0; i < vm_args.nOptions; i++) {
duke@0 2421 const JavaVMOption *option = vm_args.options + i;
duke@0 2422 if (match_option(option, "-XX:", &tail)) {
duke@0 2423 logOption(tail);
duke@0 2424 }
duke@0 2425 }
duke@0 2426 }
duke@0 2427
duke@0 2428 return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, ENVIRON_VAR));
duke@0 2429 }
duke@0 2430 return JNI_OK;
duke@0 2431 }
duke@0 2432
duke@0 2433 // Parse entry point called from JNI_CreateJavaVM
duke@0 2434
duke@0 2435 jint Arguments::parse(const JavaVMInitArgs* args) {
duke@0 2436
duke@0 2437 // Sharing support
duke@0 2438 // Construct the path to the archive
duke@0 2439 char jvm_path[JVM_MAXPATHLEN];
duke@0 2440 os::jvm_path(jvm_path, sizeof(jvm_path));
duke@0 2441 #ifdef TIERED
duke@0 2442 if (strstr(jvm_path, "client") != NULL) {
duke@0 2443 force_client_mode = true;
duke@0 2444 }
duke@0 2445 #endif // TIERED
duke@0 2446 char *end = strrchr(jvm_path, *os::file_separator());
duke@0 2447 if (end != NULL) *end = '\0';
duke@0 2448 char *shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(jvm_path) +
duke@0 2449 strlen(os::file_separator()) + 20);
duke@0 2450 if (shared_archive_path == NULL) return JNI_ENOMEM;
duke@0 2451 strcpy(shared_archive_path, jvm_path);
duke@0 2452 strcat(shared_archive_path, os::file_separator());
duke@0 2453 strcat(shared_archive_path, "classes");
duke@0 2454 DEBUG_ONLY(strcat(shared_archive_path, "_g");)
duke@0 2455 strcat(shared_archive_path, ".jsa");
duke@0 2456 SharedArchivePath = shared_archive_path;
duke@0 2457
duke@0 2458 // Remaining part of option string
duke@0 2459 const char* tail;
duke@0 2460
duke@0 2461 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
duke@0 2462 bool settings_file_specified = false;
duke@0 2463 int index;
duke@0 2464 for (index = 0; index < args->nOptions; index++) {
duke@0 2465 const JavaVMOption *option = args->options + index;
duke@0 2466 if (match_option(option, "-XX:Flags=", &tail)) {
duke@0 2467 if (!process_settings_file(tail, true, args->ignoreUnrecognized)) {
duke@0 2468 return JNI_EINVAL;
duke@0 2469 }
duke@0 2470 settings_file_specified = true;
duke@0 2471 }
duke@0 2472 if (match_option(option, "-XX:+PrintVMOptions", &tail)) {
duke@0 2473 PrintVMOptions = true;
duke@0 2474 }
duke@0 2475 }
duke@0 2476
duke@0 2477 // Parse default .hotspotrc settings file
duke@0 2478 if (!settings_file_specified) {
duke@0 2479 if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) {
duke@0 2480 return JNI_EINVAL;
duke@0 2481 }
duke@0 2482 }
duke@0 2483
duke@0 2484 if (PrintVMOptions) {
duke@0 2485 for (index = 0; index < args->nOptions; index++) {
duke@0 2486 const JavaVMOption *option = args->options + index;
duke@0 2487 if (match_option(option, "-XX:", &tail)) {
duke@0 2488 logOption(tail);
duke@0 2489 }
duke@0 2490 }
duke@0 2491 }
duke@0 2492
duke@0 2493 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
duke@0 2494 jint result = parse_vm_init_args(args);
duke@0 2495 if (result != JNI_OK) {
duke@0 2496 return result;
duke@0 2497 }
duke@0 2498
duke@0 2499 #ifndef PRODUCT
duke@0 2500 if (TraceBytecodesAt != 0) {
duke@0 2501 TraceBytecodes = true;
duke@0 2502 }
duke@0 2503 if (CountCompiledCalls) {
duke@0 2504 if (UseCounterDecay) {
duke@0 2505 warning("UseCounterDecay disabled because CountCalls is set");
duke@0 2506 UseCounterDecay = false;
duke@0 2507 }
duke@0 2508 }
duke@0 2509 #endif // PRODUCT
duke@0 2510
duke@0 2511 if (PrintGCDetails) {
duke@0 2512 // Turn on -verbose:gc options as well
duke@0 2513 PrintGC = true;
duke@0 2514 if (FLAG_IS_DEFAULT(TraceClassUnloading)) {
duke@0 2515 TraceClassUnloading = true;
duke@0 2516 }
duke@0 2517 }
duke@0 2518
duke@0 2519 #ifdef SERIALGC
duke@0 2520 set_serial_gc_flags();
duke@0 2521 #endif // SERIALGC
duke@0 2522 #ifdef KERNEL
duke@0 2523 no_shared_spaces();
duke@0 2524 #endif // KERNEL
duke@0 2525
duke@0 2526 // Set flags based on ergonomics.
duke@0 2527 set_ergonomics_flags();
duke@0 2528
jmasa@10 2529 // Check the GC selections again.
jmasa@10 2530 if (!check_gc_consistency()) {
jmasa@10 2531 return JNI_EINVAL;
jmasa@10 2532 }
jmasa@10 2533
jmasa@13 2534 if (UseParallelGC || UseParallelOldGC) {
jmasa@10 2535 // Set some flags for ParallelGC if needed.
jmasa@10 2536 set_parallel_gc_flags();
jmasa@10 2537 } else if (UseConcMarkSweepGC) {
jmasa@10 2538 // Set some flags for CMS
jmasa@10 2539 set_cms_and_parnew_gc_flags();
jmasa@10 2540 } else if (UseParNewGC) {
jmasa@10 2541 // Set some flags for ParNew
jmasa@10 2542 set_parnew_gc_flags();
jmasa@10 2543 }
jmasa@10 2544
duke@0 2545 #ifdef SERIALGC
duke@0 2546 assert(verify_serial_gc_flags(), "SerialGC unset");
duke@0 2547 #endif // SERIALGC
duke@0 2548
duke@0 2549 // Set bytecode rewriting flags
duke@0 2550 set_bytecode_flags();
duke@0 2551
duke@0 2552 // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled.
duke@0 2553 set_aggressive_opts_flags();
duke@0 2554
duke@0 2555 #ifdef CC_INTERP
duke@0 2556 // Biased locking is not implemented with c++ interpreter
duke@0 2557 FLAG_SET_DEFAULT(UseBiasedLocking, false);
duke@0 2558 #endif /* CC_INTERP */
duke@0 2559
duke@0 2560 if (PrintCommandLineFlags) {
duke@0 2561 CommandLineFlags::printSetFlags();
duke@0 2562 }
duke@0 2563
jmasa@10 2564 #ifdef ASSERT
jmasa@10 2565 if (PrintFlagsFinal) {
jmasa@10 2566 CommandLineFlags::printFlags();
jmasa@10 2567 }
jmasa@10 2568 #endif
jmasa@10 2569
duke@0 2570 return JNI_OK;
duke@0 2571 }
duke@0 2572
duke@0 2573 int Arguments::PropertyList_count(SystemProperty* pl) {
duke@0 2574 int count = 0;
duke@0 2575 while(pl != NULL) {
duke@0 2576 count++;
duke@0 2577 pl = pl->next();
duke@0 2578 }
duke@0 2579 return count;
duke@0 2580 }
duke@0 2581
duke@0 2582 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) {
duke@0 2583 assert(key != NULL, "just checking");
duke@0 2584 SystemProperty* prop;
duke@0 2585 for (prop = pl; prop != NULL; prop = prop->next()) {
duke@0 2586 if (strcmp(key, prop->key()) == 0) return prop->value();
duke@0 2587 }
duke@0 2588 return NULL;
duke@0 2589 }
duke@0 2590
duke@0 2591 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) {
duke@0 2592 int count = 0;
duke@0 2593 const char* ret_val = NULL;
duke@0 2594
duke@0 2595 while(pl != NULL) {
duke@0 2596 if(count >= index) {
duke@0 2597 ret_val = pl->key();
duke@0 2598 break;
duke@0 2599 }
duke@0 2600 count++;
duke@0 2601 pl = pl->next();
duke@0 2602 }
duke@0 2603
duke@0 2604 return ret_val;
duke@0 2605 }
duke@0 2606
duke@0 2607 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) {
duke@0 2608 int count = 0;
duke@0 2609 char* ret_val = NULL;
duke@0 2610
duke@0 2611 while(pl != NULL) {
duke@0 2612 if(count >= index) {
duke@0 2613 ret_val = pl->value();
duke@0 2614 break;
duke@0 2615 }
duke@0 2616 count++;
duke@0 2617 pl = pl->next();
duke@0 2618 }
duke@0 2619
duke@0 2620 return ret_val;
duke@0 2621 }
duke@0 2622
duke@0 2623 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) {
duke@0 2624 SystemProperty* p = *plist;
duke@0 2625 if (p == NULL) {
duke@0 2626 *plist = new_p;
duke@0 2627 } else {
duke@0 2628 while (p->next() != NULL) {
duke@0 2629 p = p->next();
duke@0 2630 }
duke@0 2631 p->set_next(new_p);
duke@0 2632 }
duke@0 2633 }
duke@0 2634
duke@0 2635 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) {
duke@0 2636 if (plist == NULL)
duke@0 2637 return;
duke@0 2638
duke@0 2639 SystemProperty* new_p = new SystemProperty(k, v, true);
duke@0 2640 PropertyList_add(plist, new_p);
duke@0 2641 }
duke@0 2642
duke@0 2643 // This add maintains unique property key in the list.
duke@0 2644 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v) {
duke@0 2645 if (plist == NULL)
duke@0 2646 return;
duke@0 2647
duke@0 2648 // If property key exist then update with new value.
duke@0 2649 SystemProperty* prop;
duke@0 2650 for (prop = *plist; prop != NULL; prop = prop->next()) {
duke@0 2651 if (strcmp(k, prop->key()) == 0) {
duke@0 2652 prop->set_value(v);
duke@0 2653 return;
duke@0 2654 }
duke@0 2655 }
duke@0 2656
duke@0 2657 PropertyList_add(plist, k, v);
duke@0 2658 }
duke@0 2659
duke@0 2660 #ifdef KERNEL
duke@0 2661 char *Arguments::get_kernel_properties() {
duke@0 2662 // Find properties starting with kernel and append them to string
duke@0 2663 // We need to find out how long they are first because the URL's that they
duke@0 2664 // might point to could get long.
duke@0 2665 int length = 0;
duke@0 2666 SystemProperty* prop;
duke@0 2667 for (prop = _system_properties; prop != NULL; prop = prop->next()) {
duke@0 2668 if (strncmp(prop->key(), "kernel.", 7 ) == 0) {
duke@0 2669 length += (strlen(prop->key()) + strlen(prop->value()) + 5); // "-D ="
duke@0 2670 }
duke@0 2671 }
duke@0 2672 // Add one for null terminator.
duke@0 2673 char *props = AllocateHeap(length + 1, "get_kernel_properties");
duke@0 2674 if (length != 0) {
duke@0 2675 int pos = 0;
duke@0 2676 for (prop = _system_properties; prop != NULL; prop = prop->next()) {
duke@0 2677 if (strncmp(prop->key(), "kernel.", 7 ) == 0) {
duke@0 2678 jio_snprintf(&props[pos], length-pos,
duke@0 2679 "-D%s=%s ", prop->key(), prop->value());
duke@0 2680 pos = strlen(props);
duke@0 2681 }
duke@0 2682 }
duke@0 2683 }
duke@0 2684 // null terminate props in case of null
duke@0 2685 props[length] = '\0';
duke@0 2686 return props;
duke@0 2687 }
duke@0 2688 #endif // KERNEL
duke@0 2689
duke@0 2690 // Copies src into buf, replacing "%%" with "%" and "%p" with pid
duke@0 2691 // Returns true if all of the source pointed by src has been copied over to
duke@0 2692 // the destination buffer pointed by buf. Otherwise, returns false.
duke@0 2693 // Notes:
duke@0 2694 // 1. If the length (buflen) of the destination buffer excluding the
duke@0 2695 // NULL terminator character is not long enough for holding the expanded
duke@0 2696 // pid characters, it also returns false instead of returning the partially
duke@0 2697 // expanded one.
duke@0 2698 // 2. The passed in "buflen" should be large enough to hold the null terminator.
duke@0 2699 bool Arguments::copy_expand_pid(const char* src, size_t srclen,
duke@0 2700 char* buf, size_t buflen) {
duke@0 2701 const char* p = src;
duke@0 2702 char* b = buf;
duke@0 2703 const char* src_end = &src[srclen];
duke@0 2704 char* buf_end = &buf[buflen - 1];
duke@0 2705
duke@0 2706 while (p < src_end && b < buf_end) {
duke@0 2707 if (*p == '%') {
duke@0 2708 switch (*(++p)) {
duke@0 2709 case '%': // "%%" ==> "%"
duke@0 2710 *b++ = *p++;
duke@0 2711 break;
duke@0 2712 case 'p': { // "%p" ==> current process id
duke@0 2713 // buf_end points to the character before the last character so
duke@0 2714 // that we could write '\0' to the end of the buffer.
duke@0 2715 size_t buf_sz = buf_end - b + 1;
duke@0 2716 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id());
duke@0 2717
duke@0 2718 // if jio_snprintf fails or the buffer is not long enough to hold
duke@0 2719 // the expanded pid, returns false.
duke@0 2720 if (ret < 0 || ret >= (int)buf_sz) {
duke@0 2721 return false;
duke@0 2722 } else {
duke@0 2723 b += ret;
duke@0 2724 assert(*b == '\0', "fail in copy_expand_pid");
duke@0 2725 if (p == src_end && b == buf_end + 1) {
duke@0 2726 // reach the end of the buffer.
duke@0 2727 return true;
duke@0 2728 }
duke@0 2729 }
duke@0 2730 p++;
duke@0 2731 break;
duke@0 2732 }
duke@0 2733 default :
duke@0 2734 *b++ = '%';
duke@0 2735 }
duke@0 2736 } else {
duke@0 2737 *b++ = *p++;
duke@0 2738 }
duke@0 2739 }
duke@0 2740 *b = '\0';
duke@0 2741 return (p == src_end); // return false if not all of the source was copied
duke@0 2742 }