Tue, 19 Oct 2010 11:14:52 -0700
6989669: Coops: -Xshare:dump causes crash
Summary: Temporarily fix to disable compressed oops with CDS
Reviewed-by: dholmes, twisti, kvn, never
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_arguments.cpp.incl"
28 #define DEFAULT_VENDOR_URL_BUG "http://java.sun.com/webapps/bugreport/crash.jsp"
29 #define DEFAULT_JAVA_LAUNCHER "generic"
31 char** Arguments::_jvm_flags_array = NULL;
32 int Arguments::_num_jvm_flags = 0;
33 char** Arguments::_jvm_args_array = NULL;
34 int Arguments::_num_jvm_args = 0;
35 char* Arguments::_java_command = NULL;
36 SystemProperty* Arguments::_system_properties = NULL;
37 const char* Arguments::_gc_log_filename = NULL;
38 bool Arguments::_has_profile = false;
39 bool Arguments::_has_alloc_profile = false;
40 uintx Arguments::_min_heap_size = 0;
41 Arguments::Mode Arguments::_mode = _mixed;
42 bool Arguments::_java_compiler = false;
43 bool Arguments::_xdebug_mode = false;
44 const char* Arguments::_java_vendor_url_bug = DEFAULT_VENDOR_URL_BUG;
45 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
46 int Arguments::_sun_java_launcher_pid = -1;
48 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
49 bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
50 bool Arguments::_UseOnStackReplacement = UseOnStackReplacement;
51 bool Arguments::_BackgroundCompilation = BackgroundCompilation;
52 bool Arguments::_ClipInlining = ClipInlining;
54 char* Arguments::SharedArchivePath = NULL;
56 AgentLibraryList Arguments::_libraryList;
57 AgentLibraryList Arguments::_agentList;
59 abort_hook_t Arguments::_abort_hook = NULL;
60 exit_hook_t Arguments::_exit_hook = NULL;
61 vfprintf_hook_t Arguments::_vfprintf_hook = NULL;
64 SystemProperty *Arguments::_java_ext_dirs = NULL;
65 SystemProperty *Arguments::_java_endorsed_dirs = NULL;
66 SystemProperty *Arguments::_sun_boot_library_path = NULL;
67 SystemProperty *Arguments::_java_library_path = NULL;
68 SystemProperty *Arguments::_java_home = NULL;
69 SystemProperty *Arguments::_java_class_path = NULL;
70 SystemProperty *Arguments::_sun_boot_class_path = NULL;
72 char* Arguments::_meta_index_path = NULL;
73 char* Arguments::_meta_index_dir = NULL;
75 static bool force_client_mode = false;
77 // Check if head of 'option' matches 'name', and sets 'tail' remaining part of option string
79 static bool match_option(const JavaVMOption *option, const char* name,
80 const char** tail) {
81 int len = (int)strlen(name);
82 if (strncmp(option->optionString, name, len) == 0) {
83 *tail = option->optionString + len;
84 return true;
85 } else {
86 return false;
87 }
88 }
90 static void logOption(const char* opt) {
91 if (PrintVMOptions) {
92 jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
93 }
94 }
96 // Process java launcher properties.
97 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
98 // See if sun.java.launcher or sun.java.launcher.pid is defined.
99 // Must do this before setting up other system properties,
100 // as some of them may depend on launcher type.
101 for (int index = 0; index < args->nOptions; index++) {
102 const JavaVMOption* option = args->options + index;
103 const char* tail;
105 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
106 process_java_launcher_argument(tail, option->extraInfo);
107 continue;
108 }
109 if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
110 _sun_java_launcher_pid = atoi(tail);
111 continue;
112 }
113 }
114 }
116 // Initialize system properties key and value.
117 void Arguments::init_system_properties() {
119 PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.version", "1.0", false));
120 PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name",
121 "Java Virtual Machine Specification", false));
122 PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(), false));
123 PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(), false));
124 PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(), true));
126 // following are JVMTI agent writeable properties.
127 // Properties values are set to NULL and they are
128 // os specific they are initialized in os::init_system_properties_values().
129 _java_ext_dirs = new SystemProperty("java.ext.dirs", NULL, true);
130 _java_endorsed_dirs = new SystemProperty("java.endorsed.dirs", NULL, true);
131 _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL, true);
132 _java_library_path = new SystemProperty("java.library.path", NULL, true);
133 _java_home = new SystemProperty("java.home", NULL, true);
134 _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL, true);
136 _java_class_path = new SystemProperty("java.class.path", "", true);
138 // Add to System Property list.
139 PropertyList_add(&_system_properties, _java_ext_dirs);
140 PropertyList_add(&_system_properties, _java_endorsed_dirs);
141 PropertyList_add(&_system_properties, _sun_boot_library_path);
142 PropertyList_add(&_system_properties, _java_library_path);
143 PropertyList_add(&_system_properties, _java_home);
144 PropertyList_add(&_system_properties, _java_class_path);
145 PropertyList_add(&_system_properties, _sun_boot_class_path);
147 // Set OS specific system properties values
148 os::init_system_properties_values();
149 }
152 // Update/Initialize System properties after JDK version number is known
153 void Arguments::init_version_specific_system_properties() {
154 PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.vendor",
155 JDK_Version::is_gte_jdk17x_version() ? "Oracle Corporation" : "Sun Microsystems Inc.", false));
156 PropertyList_add(&_system_properties, new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(), false));
157 }
159 /**
160 * Provide a slightly more user-friendly way of eliminating -XX flags.
161 * When a flag is eliminated, it can be added to this list in order to
162 * continue accepting this flag on the command-line, while issuing a warning
163 * and ignoring the value. Once the JDK version reaches the 'accept_until'
164 * limit, we flatly refuse to admit the existence of the flag. This allows
165 * a flag to die correctly over JDK releases using HSX.
166 */
167 typedef struct {
168 const char* name;
169 JDK_Version obsoleted_in; // when the flag went away
170 JDK_Version accept_until; // which version to start denying the existence
171 } ObsoleteFlag;
173 static ObsoleteFlag obsolete_jvm_flags[] = {
174 { "UseTrainGC", JDK_Version::jdk(5), JDK_Version::jdk(7) },
175 { "UseSpecialLargeObjectHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
176 { "UseOversizedCarHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
177 { "TraceCarAllocation", JDK_Version::jdk(5), JDK_Version::jdk(7) },
178 { "PrintTrainGCProcessingStats", JDK_Version::jdk(5), JDK_Version::jdk(7) },
179 { "LogOfCarSpaceSize", JDK_Version::jdk(5), JDK_Version::jdk(7) },
180 { "OversizedCarThreshold", JDK_Version::jdk(5), JDK_Version::jdk(7) },
181 { "MinTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
182 { "DefaultTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
183 { "MaxTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
184 { "DelayTickAdjustment", JDK_Version::jdk(5), JDK_Version::jdk(7) },
185 { "ProcessingToTenuringRatio", JDK_Version::jdk(5), JDK_Version::jdk(7) },
186 { "MinTrainLength", JDK_Version::jdk(5), JDK_Version::jdk(7) },
187 { "AppendRatio", JDK_Version::jdk_update(6,10), JDK_Version::jdk(7) },
188 { "DefaultMaxRAM", JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
189 { "DefaultInitialRAMFraction",
190 JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
191 { "UseDepthFirstScavengeOrder",
192 JDK_Version::jdk_update(6,22), JDK_Version::jdk(7) },
193 { NULL, JDK_Version(0), JDK_Version(0) }
194 };
196 // Returns true if the flag is obsolete and fits into the range specified
197 // for being ignored. In the case that the flag is ignored, the 'version'
198 // value is filled in with the version number when the flag became
199 // obsolete so that that value can be displayed to the user.
200 bool Arguments::is_newly_obsolete(const char *s, JDK_Version* version) {
201 int i = 0;
202 assert(version != NULL, "Must provide a version buffer");
203 while (obsolete_jvm_flags[i].name != NULL) {
204 const ObsoleteFlag& flag_status = obsolete_jvm_flags[i];
205 // <flag>=xxx form
206 // [-|+]<flag> form
207 if ((strncmp(flag_status.name, s, strlen(flag_status.name)) == 0) ||
208 ((s[0] == '+' || s[0] == '-') &&
209 (strncmp(flag_status.name, &s[1], strlen(flag_status.name)) == 0))) {
210 if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
211 *version = flag_status.obsoleted_in;
212 return true;
213 }
214 }
215 i++;
216 }
217 return false;
218 }
220 // Constructs the system class path (aka boot class path) from the following
221 // components, in order:
222 //
223 // prefix // from -Xbootclasspath/p:...
224 // endorsed // the expansion of -Djava.endorsed.dirs=...
225 // base // from os::get_system_properties() or -Xbootclasspath=
226 // suffix // from -Xbootclasspath/a:...
227 //
228 // java.endorsed.dirs is a list of directories; any jar or zip files in the
229 // directories are added to the sysclasspath just before the base.
230 //
231 // This could be AllStatic, but it isn't needed after argument processing is
232 // complete.
233 class SysClassPath: public StackObj {
234 public:
235 SysClassPath(const char* base);
236 ~SysClassPath();
238 inline void set_base(const char* base);
239 inline void add_prefix(const char* prefix);
240 inline void add_suffix_to_prefix(const char* suffix);
241 inline void add_suffix(const char* suffix);
242 inline void reset_path(const char* base);
244 // Expand the jar/zip files in each directory listed by the java.endorsed.dirs
245 // property. Must be called after all command-line arguments have been
246 // processed (in particular, -Djava.endorsed.dirs=...) and before calling
247 // combined_path().
248 void expand_endorsed();
250 inline const char* get_base() const { return _items[_scp_base]; }
251 inline const char* get_prefix() const { return _items[_scp_prefix]; }
252 inline const char* get_suffix() const { return _items[_scp_suffix]; }
253 inline const char* get_endorsed() const { return _items[_scp_endorsed]; }
255 // Combine all the components into a single c-heap-allocated string; caller
256 // must free the string if/when no longer needed.
257 char* combined_path();
259 private:
260 // Utility routines.
261 static char* add_to_path(const char* path, const char* str, bool prepend);
262 static char* add_jars_to_path(char* path, const char* directory);
264 inline void reset_item_at(int index);
266 // Array indices for the items that make up the sysclasspath. All except the
267 // base are allocated in the C heap and freed by this class.
268 enum {
269 _scp_prefix, // from -Xbootclasspath/p:...
270 _scp_endorsed, // the expansion of -Djava.endorsed.dirs=...
271 _scp_base, // the default sysclasspath
272 _scp_suffix, // from -Xbootclasspath/a:...
273 _scp_nitems // the number of items, must be last.
274 };
276 const char* _items[_scp_nitems];
277 DEBUG_ONLY(bool _expansion_done;)
278 };
280 SysClassPath::SysClassPath(const char* base) {
281 memset(_items, 0, sizeof(_items));
282 _items[_scp_base] = base;
283 DEBUG_ONLY(_expansion_done = false;)
284 }
286 SysClassPath::~SysClassPath() {
287 // Free everything except the base.
288 for (int i = 0; i < _scp_nitems; ++i) {
289 if (i != _scp_base) reset_item_at(i);
290 }
291 DEBUG_ONLY(_expansion_done = false;)
292 }
294 inline void SysClassPath::set_base(const char* base) {
295 _items[_scp_base] = base;
296 }
298 inline void SysClassPath::add_prefix(const char* prefix) {
299 _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true);
300 }
302 inline void SysClassPath::add_suffix_to_prefix(const char* suffix) {
303 _items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false);
304 }
306 inline void SysClassPath::add_suffix(const char* suffix) {
307 _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false);
308 }
310 inline void SysClassPath::reset_item_at(int index) {
311 assert(index < _scp_nitems && index != _scp_base, "just checking");
312 if (_items[index] != NULL) {
313 FREE_C_HEAP_ARRAY(char, _items[index]);
314 _items[index] = NULL;
315 }
316 }
318 inline void SysClassPath::reset_path(const char* base) {
319 // Clear the prefix and suffix.
320 reset_item_at(_scp_prefix);
321 reset_item_at(_scp_suffix);
322 set_base(base);
323 }
325 //------------------------------------------------------------------------------
327 void SysClassPath::expand_endorsed() {
328 assert(_items[_scp_endorsed] == NULL, "can only be called once.");
330 const char* path = Arguments::get_property("java.endorsed.dirs");
331 if (path == NULL) {
332 path = Arguments::get_endorsed_dir();
333 assert(path != NULL, "no default for java.endorsed.dirs");
334 }
336 char* expanded_path = NULL;
337 const char separator = *os::path_separator();
338 const char* const end = path + strlen(path);
339 while (path < end) {
340 const char* tmp_end = strchr(path, separator);
341 if (tmp_end == NULL) {
342 expanded_path = add_jars_to_path(expanded_path, path);
343 path = end;
344 } else {
345 char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1);
346 memcpy(dirpath, path, tmp_end - path);
347 dirpath[tmp_end - path] = '\0';
348 expanded_path = add_jars_to_path(expanded_path, dirpath);
349 FREE_C_HEAP_ARRAY(char, dirpath);
350 path = tmp_end + 1;
351 }
352 }
353 _items[_scp_endorsed] = expanded_path;
354 DEBUG_ONLY(_expansion_done = true;)
355 }
357 // Combine the bootclasspath elements, some of which may be null, into a single
358 // c-heap-allocated string.
359 char* SysClassPath::combined_path() {
360 assert(_items[_scp_base] != NULL, "empty default sysclasspath");
361 assert(_expansion_done, "must call expand_endorsed() first.");
363 size_t lengths[_scp_nitems];
364 size_t total_len = 0;
366 const char separator = *os::path_separator();
368 // Get the lengths.
369 int i;
370 for (i = 0; i < _scp_nitems; ++i) {
371 if (_items[i] != NULL) {
372 lengths[i] = strlen(_items[i]);
373 // Include space for the separator char (or a NULL for the last item).
374 total_len += lengths[i] + 1;
375 }
376 }
377 assert(total_len > 0, "empty sysclasspath not allowed");
379 // Copy the _items to a single string.
380 char* cp = NEW_C_HEAP_ARRAY(char, total_len);
381 char* cp_tmp = cp;
382 for (i = 0; i < _scp_nitems; ++i) {
383 if (_items[i] != NULL) {
384 memcpy(cp_tmp, _items[i], lengths[i]);
385 cp_tmp += lengths[i];
386 *cp_tmp++ = separator;
387 }
388 }
389 *--cp_tmp = '\0'; // Replace the extra separator.
390 return cp;
391 }
393 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
394 char*
395 SysClassPath::add_to_path(const char* path, const char* str, bool prepend) {
396 char *cp;
398 assert(str != NULL, "just checking");
399 if (path == NULL) {
400 size_t len = strlen(str) + 1;
401 cp = NEW_C_HEAP_ARRAY(char, len);
402 memcpy(cp, str, len); // copy the trailing null
403 } else {
404 const char separator = *os::path_separator();
405 size_t old_len = strlen(path);
406 size_t str_len = strlen(str);
407 size_t len = old_len + str_len + 2;
409 if (prepend) {
410 cp = NEW_C_HEAP_ARRAY(char, len);
411 char* cp_tmp = cp;
412 memcpy(cp_tmp, str, str_len);
413 cp_tmp += str_len;
414 *cp_tmp = separator;
415 memcpy(++cp_tmp, path, old_len + 1); // copy the trailing null
416 FREE_C_HEAP_ARRAY(char, path);
417 } else {
418 cp = REALLOC_C_HEAP_ARRAY(char, path, len);
419 char* cp_tmp = cp + old_len;
420 *cp_tmp = separator;
421 memcpy(++cp_tmp, str, str_len + 1); // copy the trailing null
422 }
423 }
424 return cp;
425 }
427 // Scan the directory and append any jar or zip files found to path.
428 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
429 char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
430 DIR* dir = os::opendir(directory);
431 if (dir == NULL) return path;
433 char dir_sep[2] = { '\0', '\0' };
434 size_t directory_len = strlen(directory);
435 const char fileSep = *os::file_separator();
436 if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep;
438 /* Scan the directory for jars/zips, appending them to path. */
439 struct dirent *entry;
440 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory));
441 while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
442 const char* name = entry->d_name;
443 const char* ext = name + strlen(name) - 4;
444 bool isJarOrZip = ext > name &&
445 (os::file_name_strcmp(ext, ".jar") == 0 ||
446 os::file_name_strcmp(ext, ".zip") == 0);
447 if (isJarOrZip) {
448 char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name));
449 sprintf(jarpath, "%s%s%s", directory, dir_sep, name);
450 path = add_to_path(path, jarpath, false);
451 FREE_C_HEAP_ARRAY(char, jarpath);
452 }
453 }
454 FREE_C_HEAP_ARRAY(char, dbuf);
455 os::closedir(dir);
456 return path;
457 }
459 // Parses a memory size specification string.
460 static bool atomull(const char *s, julong* result) {
461 julong n = 0;
462 int args_read = sscanf(s, os::julong_format_specifier(), &n);
463 if (args_read != 1) {
464 return false;
465 }
466 while (*s != '\0' && isdigit(*s)) {
467 s++;
468 }
469 // 4705540: illegal if more characters are found after the first non-digit
470 if (strlen(s) > 1) {
471 return false;
472 }
473 switch (*s) {
474 case 'T': case 't':
475 *result = n * G * K;
476 // Check for overflow.
477 if (*result/((julong)G * K) != n) return false;
478 return true;
479 case 'G': case 'g':
480 *result = n * G;
481 if (*result/G != n) return false;
482 return true;
483 case 'M': case 'm':
484 *result = n * M;
485 if (*result/M != n) return false;
486 return true;
487 case 'K': case 'k':
488 *result = n * K;
489 if (*result/K != n) return false;
490 return true;
491 case '\0':
492 *result = n;
493 return true;
494 default:
495 return false;
496 }
497 }
499 Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size) {
500 if (size < min_size) return arg_too_small;
501 // Check that size will fit in a size_t (only relevant on 32-bit)
502 if (size > max_uintx) return arg_too_big;
503 return arg_in_range;
504 }
506 // Describe an argument out of range error
507 void Arguments::describe_range_error(ArgsRange errcode) {
508 switch(errcode) {
509 case arg_too_big:
510 jio_fprintf(defaultStream::error_stream(),
511 "The specified size exceeds the maximum "
512 "representable size.\n");
513 break;
514 case arg_too_small:
515 case arg_unreadable:
516 case arg_in_range:
517 // do nothing for now
518 break;
519 default:
520 ShouldNotReachHere();
521 }
522 }
524 static bool set_bool_flag(char* name, bool value, FlagValueOrigin origin) {
525 return CommandLineFlags::boolAtPut(name, &value, origin);
526 }
528 static bool set_fp_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
529 double v;
530 if (sscanf(value, "%lf", &v) != 1) {
531 return false;
532 }
534 if (CommandLineFlags::doubleAtPut(name, &v, origin)) {
535 return true;
536 }
537 return false;
538 }
540 static bool set_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
541 julong v;
542 intx intx_v;
543 bool is_neg = false;
544 // Check the sign first since atomull() parses only unsigned values.
545 if (*value == '-') {
546 if (!CommandLineFlags::intxAt(name, &intx_v)) {
547 return false;
548 }
549 value++;
550 is_neg = true;
551 }
552 if (!atomull(value, &v)) {
553 return false;
554 }
555 intx_v = (intx) v;
556 if (is_neg) {
557 intx_v = -intx_v;
558 }
559 if (CommandLineFlags::intxAtPut(name, &intx_v, origin)) {
560 return true;
561 }
562 uintx uintx_v = (uintx) v;
563 if (!is_neg && CommandLineFlags::uintxAtPut(name, &uintx_v, origin)) {
564 return true;
565 }
566 uint64_t uint64_t_v = (uint64_t) v;
567 if (!is_neg && CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin)) {
568 return true;
569 }
570 return false;
571 }
573 static bool set_string_flag(char* name, const char* value, FlagValueOrigin origin) {
574 if (!CommandLineFlags::ccstrAtPut(name, &value, origin)) return false;
575 // Contract: CommandLineFlags always returns a pointer that needs freeing.
576 FREE_C_HEAP_ARRAY(char, value);
577 return true;
578 }
580 static bool append_to_string_flag(char* name, const char* new_value, FlagValueOrigin origin) {
581 const char* old_value = "";
582 if (!CommandLineFlags::ccstrAt(name, &old_value)) return false;
583 size_t old_len = old_value != NULL ? strlen(old_value) : 0;
584 size_t new_len = strlen(new_value);
585 const char* value;
586 char* free_this_too = NULL;
587 if (old_len == 0) {
588 value = new_value;
589 } else if (new_len == 0) {
590 value = old_value;
591 } else {
592 char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1);
593 // each new setting adds another LINE to the switch:
594 sprintf(buf, "%s\n%s", old_value, new_value);
595 value = buf;
596 free_this_too = buf;
597 }
598 (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
599 // CommandLineFlags always returns a pointer that needs freeing.
600 FREE_C_HEAP_ARRAY(char, value);
601 if (free_this_too != NULL) {
602 // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
603 FREE_C_HEAP_ARRAY(char, free_this_too);
604 }
605 return true;
606 }
608 bool Arguments::parse_argument(const char* arg, FlagValueOrigin origin) {
610 // range of acceptable characters spelled out for portability reasons
611 #define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
612 #define BUFLEN 255
613 char name[BUFLEN+1];
614 char dummy;
616 if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
617 return set_bool_flag(name, false, origin);
618 }
619 if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
620 return set_bool_flag(name, true, origin);
621 }
623 char punct;
624 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
625 const char* value = strchr(arg, '=') + 1;
626 Flag* flag = Flag::find_flag(name, strlen(name));
627 if (flag != NULL && flag->is_ccstr()) {
628 if (flag->ccstr_accumulates()) {
629 return append_to_string_flag(name, value, origin);
630 } else {
631 if (value[0] == '\0') {
632 value = NULL;
633 }
634 return set_string_flag(name, value, origin);
635 }
636 }
637 }
639 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') {
640 const char* value = strchr(arg, '=') + 1;
641 // -XX:Foo:=xxx will reset the string flag to the given value.
642 if (value[0] == '\0') {
643 value = NULL;
644 }
645 return set_string_flag(name, value, origin);
646 }
648 #define SIGNED_FP_NUMBER_RANGE "[-0123456789.]"
649 #define SIGNED_NUMBER_RANGE "[-0123456789]"
650 #define NUMBER_RANGE "[0123456789]"
651 char value[BUFLEN + 1];
652 char value2[BUFLEN + 1];
653 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) {
654 // Looks like a floating-point number -- try again with more lenient format string
655 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) {
656 return set_fp_numeric_flag(name, value, origin);
657 }
658 }
660 #define VALUE_RANGE "[-kmgtKMGT0123456789]"
661 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
662 return set_numeric_flag(name, value, origin);
663 }
665 return false;
666 }
668 void Arguments::add_string(char*** bldarray, int* count, const char* arg) {
669 assert(bldarray != NULL, "illegal argument");
671 if (arg == NULL) {
672 return;
673 }
675 int index = *count;
677 // expand the array and add arg to the last element
678 (*count)++;
679 if (*bldarray == NULL) {
680 *bldarray = NEW_C_HEAP_ARRAY(char*, *count);
681 } else {
682 *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, *count);
683 }
684 (*bldarray)[index] = strdup(arg);
685 }
687 void Arguments::build_jvm_args(const char* arg) {
688 add_string(&_jvm_args_array, &_num_jvm_args, arg);
689 }
691 void Arguments::build_jvm_flags(const char* arg) {
692 add_string(&_jvm_flags_array, &_num_jvm_flags, arg);
693 }
695 // utility function to return a string that concatenates all
696 // strings in a given char** array
697 const char* Arguments::build_resource_string(char** args, int count) {
698 if (args == NULL || count == 0) {
699 return NULL;
700 }
701 size_t length = strlen(args[0]) + 1; // add 1 for the null terminator
702 for (int i = 1; i < count; i++) {
703 length += strlen(args[i]) + 1; // add 1 for a space
704 }
705 char* s = NEW_RESOURCE_ARRAY(char, length);
706 strcpy(s, args[0]);
707 for (int j = 1; j < count; j++) {
708 strcat(s, " ");
709 strcat(s, args[j]);
710 }
711 return (const char*) s;
712 }
714 void Arguments::print_on(outputStream* st) {
715 st->print_cr("VM Arguments:");
716 if (num_jvm_flags() > 0) {
717 st->print("jvm_flags: "); print_jvm_flags_on(st);
718 }
719 if (num_jvm_args() > 0) {
720 st->print("jvm_args: "); print_jvm_args_on(st);
721 }
722 st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>");
723 st->print_cr("Launcher Type: %s", _sun_java_launcher);
724 }
726 void Arguments::print_jvm_flags_on(outputStream* st) {
727 if (_num_jvm_flags > 0) {
728 for (int i=0; i < _num_jvm_flags; i++) {
729 st->print("%s ", _jvm_flags_array[i]);
730 }
731 st->print_cr("");
732 }
733 }
735 void Arguments::print_jvm_args_on(outputStream* st) {
736 if (_num_jvm_args > 0) {
737 for (int i=0; i < _num_jvm_args; i++) {
738 st->print("%s ", _jvm_args_array[i]);
739 }
740 st->print_cr("");
741 }
742 }
744 bool Arguments::process_argument(const char* arg,
745 jboolean ignore_unrecognized, FlagValueOrigin origin) {
747 JDK_Version since = JDK_Version();
749 if (parse_argument(arg, origin)) {
750 // do nothing
751 } else if (is_newly_obsolete(arg, &since)) {
752 enum { bufsize = 256 };
753 char buffer[bufsize];
754 since.to_string(buffer, bufsize);
755 jio_fprintf(defaultStream::error_stream(),
756 "Warning: The flag %s has been EOL'd as of %s and will"
757 " be ignored\n", arg, buffer);
758 } else {
759 if (!ignore_unrecognized) {
760 jio_fprintf(defaultStream::error_stream(),
761 "Unrecognized VM option '%s'\n", arg);
762 // allow for commandline "commenting out" options like -XX:#+Verbose
763 if (strlen(arg) == 0 || arg[0] != '#') {
764 return false;
765 }
766 }
767 }
768 return true;
769 }
771 bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
772 FILE* stream = fopen(file_name, "rb");
773 if (stream == NULL) {
774 if (should_exist) {
775 jio_fprintf(defaultStream::error_stream(),
776 "Could not open settings file %s\n", file_name);
777 return false;
778 } else {
779 return true;
780 }
781 }
783 char token[1024];
784 int pos = 0;
786 bool in_white_space = true;
787 bool in_comment = false;
788 bool in_quote = false;
789 char quote_c = 0;
790 bool result = true;
792 int c = getc(stream);
793 while(c != EOF) {
794 if (in_white_space) {
795 if (in_comment) {
796 if (c == '\n') in_comment = false;
797 } else {
798 if (c == '#') in_comment = true;
799 else if (!isspace(c)) {
800 in_white_space = false;
801 token[pos++] = c;
802 }
803 }
804 } else {
805 if (c == '\n' || (!in_quote && isspace(c))) {
806 // token ends at newline, or at unquoted whitespace
807 // this allows a way to include spaces in string-valued options
808 token[pos] = '\0';
809 logOption(token);
810 result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
811 build_jvm_flags(token);
812 pos = 0;
813 in_white_space = true;
814 in_quote = false;
815 } else if (!in_quote && (c == '\'' || c == '"')) {
816 in_quote = true;
817 quote_c = c;
818 } else if (in_quote && (c == quote_c)) {
819 in_quote = false;
820 } else {
821 token[pos++] = c;
822 }
823 }
824 c = getc(stream);
825 }
826 if (pos > 0) {
827 token[pos] = '\0';
828 result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
829 build_jvm_flags(token);
830 }
831 fclose(stream);
832 return result;
833 }
835 //=============================================================================================================
836 // Parsing of properties (-D)
838 const char* Arguments::get_property(const char* key) {
839 return PropertyList_get_value(system_properties(), key);
840 }
842 bool Arguments::add_property(const char* prop) {
843 const char* eq = strchr(prop, '=');
844 char* key;
845 // ns must be static--its address may be stored in a SystemProperty object.
846 const static char ns[1] = {0};
847 char* value = (char *)ns;
849 size_t key_len = (eq == NULL) ? strlen(prop) : (eq - prop);
850 key = AllocateHeap(key_len + 1, "add_property");
851 strncpy(key, prop, key_len);
852 key[key_len] = '\0';
854 if (eq != NULL) {
855 size_t value_len = strlen(prop) - key_len - 1;
856 value = AllocateHeap(value_len + 1, "add_property");
857 strncpy(value, &prop[key_len + 1], value_len + 1);
858 }
860 if (strcmp(key, "java.compiler") == 0) {
861 process_java_compiler_argument(value);
862 FreeHeap(key);
863 if (eq != NULL) {
864 FreeHeap(value);
865 }
866 return true;
867 } else if (strcmp(key, "sun.java.command") == 0) {
868 _java_command = value;
870 // don't add this property to the properties exposed to the java application
871 FreeHeap(key);
872 return true;
873 } else if (strcmp(key, "sun.java.launcher.pid") == 0) {
874 // launcher.pid property is private and is processed
875 // in process_sun_java_launcher_properties();
876 // the sun.java.launcher property is passed on to the java application
877 FreeHeap(key);
878 if (eq != NULL) {
879 FreeHeap(value);
880 }
881 return true;
882 } else if (strcmp(key, "java.vendor.url.bug") == 0) {
883 // save it in _java_vendor_url_bug, so JVM fatal error handler can access
884 // its value without going through the property list or making a Java call.
885 _java_vendor_url_bug = value;
886 } else if (strcmp(key, "sun.boot.library.path") == 0) {
887 PropertyList_unique_add(&_system_properties, key, value, true);
888 return true;
889 }
890 // Create new property and add at the end of the list
891 PropertyList_unique_add(&_system_properties, key, value);
892 return true;
893 }
895 //===========================================================================================================
896 // Setting int/mixed/comp mode flags
898 void Arguments::set_mode_flags(Mode mode) {
899 // Set up default values for all flags.
900 // If you add a flag to any of the branches below,
901 // add a default value for it here.
902 set_java_compiler(false);
903 _mode = mode;
905 // Ensure Agent_OnLoad has the correct initial values.
906 // This may not be the final mode; mode may change later in onload phase.
907 PropertyList_unique_add(&_system_properties, "java.vm.info",
908 (char*)Abstract_VM_Version::vm_info_string(), false);
910 UseInterpreter = true;
911 UseCompiler = true;
912 UseLoopCounter = true;
914 // Default values may be platform/compiler dependent -
915 // use the saved values
916 ClipInlining = Arguments::_ClipInlining;
917 AlwaysCompileLoopMethods = Arguments::_AlwaysCompileLoopMethods;
918 UseOnStackReplacement = Arguments::_UseOnStackReplacement;
919 BackgroundCompilation = Arguments::_BackgroundCompilation;
921 // Change from defaults based on mode
922 switch (mode) {
923 default:
924 ShouldNotReachHere();
925 break;
926 case _int:
927 UseCompiler = false;
928 UseLoopCounter = false;
929 AlwaysCompileLoopMethods = false;
930 UseOnStackReplacement = false;
931 break;
932 case _mixed:
933 // same as default
934 break;
935 case _comp:
936 UseInterpreter = false;
937 BackgroundCompilation = false;
938 ClipInlining = false;
939 break;
940 }
941 }
943 // Conflict: required to use shared spaces (-Xshare:on), but
944 // incompatible command line options were chosen.
946 static void no_shared_spaces() {
947 if (RequireSharedSpaces) {
948 jio_fprintf(defaultStream::error_stream(),
949 "Class data sharing is inconsistent with other specified options.\n");
950 vm_exit_during_initialization("Unable to use shared archive.", NULL);
951 } else {
952 FLAG_SET_DEFAULT(UseSharedSpaces, false);
953 }
954 }
956 void Arguments::set_tiered_flags() {
957 if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
958 FLAG_SET_DEFAULT(CompilationPolicyChoice, 2);
959 }
961 if (CompilationPolicyChoice < 2) {
962 vm_exit_during_initialization(
963 "Incompatible compilation policy selected", NULL);
964 }
966 #ifdef _LP64
967 if (FLAG_IS_DEFAULT(UseCompressedOops) || FLAG_IS_ERGO(UseCompressedOops)) {
968 UseCompressedOops = false;
969 }
970 if (UseCompressedOops) {
971 vm_exit_during_initialization(
972 "Tiered compilation is not supported with compressed oops yet", NULL);
973 }
974 #endif
975 // Increase the code cache size - tiered compiles a lot more.
976 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
977 FLAG_SET_DEFAULT(ReservedCodeCacheSize, ReservedCodeCacheSize * 2);
978 }
979 }
981 #ifndef KERNEL
982 // If the user has chosen ParallelGCThreads > 0, we set UseParNewGC
983 // if it's not explictly set or unset. If the user has chosen
984 // UseParNewGC and not explicitly set ParallelGCThreads we
985 // set it, unless this is a single cpu machine.
986 void Arguments::set_parnew_gc_flags() {
987 assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
988 "control point invariant");
989 assert(UseParNewGC, "Error");
991 // Turn off AdaptiveSizePolicy by default for parnew until it is
992 // complete.
993 if (FLAG_IS_DEFAULT(UseAdaptiveSizePolicy)) {
994 FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
995 }
997 if (ParallelGCThreads == 0) {
998 FLAG_SET_DEFAULT(ParallelGCThreads,
999 Abstract_VM_Version::parallel_worker_threads());
1000 if (ParallelGCThreads == 1) {
1001 FLAG_SET_DEFAULT(UseParNewGC, false);
1002 FLAG_SET_DEFAULT(ParallelGCThreads, 0);
1003 }
1004 }
1005 if (UseParNewGC) {
1006 // CDS doesn't work with ParNew yet
1007 no_shared_spaces();
1009 // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 respectively,
1010 // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration
1011 // we set them to 1024 and 1024.
1012 // See CR 6362902.
1013 if (FLAG_IS_DEFAULT(YoungPLABSize)) {
1014 FLAG_SET_DEFAULT(YoungPLABSize, (intx)1024);
1015 }
1016 if (FLAG_IS_DEFAULT(OldPLABSize)) {
1017 FLAG_SET_DEFAULT(OldPLABSize, (intx)1024);
1018 }
1020 // AlwaysTenure flag should make ParNew promote all at first collection.
1021 // See CR 6362902.
1022 if (AlwaysTenure) {
1023 FLAG_SET_CMDLINE(intx, MaxTenuringThreshold, 0);
1024 }
1025 // When using compressed oops, we use local overflow stacks,
1026 // rather than using a global overflow list chained through
1027 // the klass word of the object's pre-image.
1028 if (UseCompressedOops && !ParGCUseLocalOverflow) {
1029 if (!FLAG_IS_DEFAULT(ParGCUseLocalOverflow)) {
1030 warning("Forcing +ParGCUseLocalOverflow: needed if using compressed references");
1031 }
1032 FLAG_SET_DEFAULT(ParGCUseLocalOverflow, true);
1033 }
1034 assert(ParGCUseLocalOverflow || !UseCompressedOops, "Error");
1035 }
1036 }
1038 // Adjust some sizes to suit CMS and/or ParNew needs; these work well on
1039 // sparc/solaris for certain applications, but would gain from
1040 // further optimization and tuning efforts, and would almost
1041 // certainly gain from analysis of platform and environment.
1042 void Arguments::set_cms_and_parnew_gc_flags() {
1043 assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error");
1044 assert(UseConcMarkSweepGC, "CMS is expected to be on here");
1046 // If we are using CMS, we prefer to UseParNewGC,
1047 // unless explicitly forbidden.
1048 if (FLAG_IS_DEFAULT(UseParNewGC)) {
1049 FLAG_SET_ERGO(bool, UseParNewGC, true);
1050 }
1052 // Turn off AdaptiveSizePolicy by default for cms until it is
1053 // complete.
1054 if (FLAG_IS_DEFAULT(UseAdaptiveSizePolicy)) {
1055 FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
1056 }
1058 // In either case, adjust ParallelGCThreads and/or UseParNewGC
1059 // as needed.
1060 if (UseParNewGC) {
1061 set_parnew_gc_flags();
1062 }
1064 // Now make adjustments for CMS
1065 size_t young_gen_per_worker;
1066 intx new_ratio;
1067 size_t min_new_default;
1068 intx tenuring_default;
1069 if (CMSUseOldDefaults) { // old defaults: "old" as of 6.0
1070 if FLAG_IS_DEFAULT(CMSYoungGenPerWorker) {
1071 FLAG_SET_ERGO(intx, CMSYoungGenPerWorker, 4*M);
1072 }
1073 young_gen_per_worker = 4*M;
1074 new_ratio = (intx)15;
1075 min_new_default = 4*M;
1076 tenuring_default = (intx)0;
1077 } else { // new defaults: "new" as of 6.0
1078 young_gen_per_worker = CMSYoungGenPerWorker;
1079 new_ratio = (intx)7;
1080 min_new_default = 16*M;
1081 tenuring_default = (intx)4;
1082 }
1084 // Preferred young gen size for "short" pauses
1085 const uintx parallel_gc_threads =
1086 (ParallelGCThreads == 0 ? 1 : ParallelGCThreads);
1087 const size_t preferred_max_new_size_unaligned =
1088 ScaleForWordSize(young_gen_per_worker * parallel_gc_threads);
1089 const size_t preferred_max_new_size =
1090 align_size_up(preferred_max_new_size_unaligned, os::vm_page_size());
1092 // Unless explicitly requested otherwise, size young gen
1093 // for "short" pauses ~ 4M*ParallelGCThreads
1095 // If either MaxNewSize or NewRatio is set on the command line,
1096 // assume the user is trying to set the size of the young gen.
1098 if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) {
1100 // Set MaxNewSize to our calculated preferred_max_new_size unless
1101 // NewSize was set on the command line and it is larger than
1102 // preferred_max_new_size.
1103 if (!FLAG_IS_DEFAULT(NewSize)) { // NewSize explicitly set at command-line
1104 FLAG_SET_ERGO(uintx, MaxNewSize, MAX2(NewSize, preferred_max_new_size));
1105 } else {
1106 FLAG_SET_ERGO(uintx, MaxNewSize, preferred_max_new_size);
1107 }
1108 if (PrintGCDetails && Verbose) {
1109 // Too early to use gclog_or_tty
1110 tty->print_cr("Ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize);
1111 }
1113 // Unless explicitly requested otherwise, prefer a large
1114 // Old to Young gen size so as to shift the collection load
1115 // to the old generation concurrent collector
1117 // If this is only guarded by FLAG_IS_DEFAULT(NewRatio)
1118 // then NewSize and OldSize may be calculated. That would
1119 // generally lead to some differences with ParNewGC for which
1120 // there was no obvious reason. Also limit to the case where
1121 // MaxNewSize has not been set.
1123 FLAG_SET_ERGO(intx, NewRatio, MAX2(NewRatio, new_ratio));
1125 // Code along this path potentially sets NewSize and OldSize
1127 // Calculate the desired minimum size of the young gen but if
1128 // NewSize has been set on the command line, use it here since
1129 // it should be the final value.
1130 size_t min_new;
1131 if (FLAG_IS_DEFAULT(NewSize)) {
1132 min_new = align_size_up(ScaleForWordSize(min_new_default),
1133 os::vm_page_size());
1134 } else {
1135 min_new = NewSize;
1136 }
1137 size_t prev_initial_size = InitialHeapSize;
1138 if (prev_initial_size != 0 && prev_initial_size < min_new + OldSize) {
1139 FLAG_SET_ERGO(uintx, InitialHeapSize, min_new + OldSize);
1140 // Currently minimum size and the initial heap sizes are the same.
1141 set_min_heap_size(InitialHeapSize);
1142 if (PrintGCDetails && Verbose) {
1143 warning("Initial heap size increased to " SIZE_FORMAT " M from "
1144 SIZE_FORMAT " M; use -XX:NewSize=... for finer control.",
1145 InitialHeapSize/M, prev_initial_size/M);
1146 }
1147 }
1149 // MaxHeapSize is aligned down in collectorPolicy
1150 size_t max_heap =
1151 align_size_down(MaxHeapSize,
1152 CardTableRS::ct_max_alignment_constraint());
1154 if (PrintGCDetails && Verbose) {
1155 // Too early to use gclog_or_tty
1156 tty->print_cr("CMS set min_heap_size: " SIZE_FORMAT
1157 " initial_heap_size: " SIZE_FORMAT
1158 " max_heap: " SIZE_FORMAT,
1159 min_heap_size(), InitialHeapSize, max_heap);
1160 }
1161 if (max_heap > min_new) {
1162 // Unless explicitly requested otherwise, make young gen
1163 // at least min_new, and at most preferred_max_new_size.
1164 if (FLAG_IS_DEFAULT(NewSize)) {
1165 FLAG_SET_ERGO(uintx, NewSize, MAX2(NewSize, min_new));
1166 FLAG_SET_ERGO(uintx, NewSize, MIN2(preferred_max_new_size, NewSize));
1167 if (PrintGCDetails && Verbose) {
1168 // Too early to use gclog_or_tty
1169 tty->print_cr("Ergo set NewSize: " SIZE_FORMAT, NewSize);
1170 }
1171 }
1172 // Unless explicitly requested otherwise, size old gen
1173 // so that it's at least 3X of NewSize to begin with;
1174 // later NewRatio will decide how it grows; see above.
1175 if (FLAG_IS_DEFAULT(OldSize)) {
1176 if (max_heap > NewSize) {
1177 FLAG_SET_ERGO(uintx, OldSize, MIN2(3*NewSize, max_heap - NewSize));
1178 if (PrintGCDetails && Verbose) {
1179 // Too early to use gclog_or_tty
1180 tty->print_cr("Ergo set OldSize: " SIZE_FORMAT, OldSize);
1181 }
1182 }
1183 }
1184 }
1185 }
1186 // Unless explicitly requested otherwise, definitely
1187 // promote all objects surviving "tenuring_default" scavenges.
1188 if (FLAG_IS_DEFAULT(MaxTenuringThreshold) &&
1189 FLAG_IS_DEFAULT(SurvivorRatio)) {
1190 FLAG_SET_ERGO(intx, MaxTenuringThreshold, tenuring_default);
1191 }
1192 // If we decided above (or user explicitly requested)
1193 // `promote all' (via MaxTenuringThreshold := 0),
1194 // prefer minuscule survivor spaces so as not to waste
1195 // space for (non-existent) survivors
1196 if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) {
1197 FLAG_SET_ERGO(intx, SurvivorRatio, MAX2((intx)1024, SurvivorRatio));
1198 }
1199 // If OldPLABSize is set and CMSParPromoteBlocksToClaim is not,
1200 // set CMSParPromoteBlocksToClaim equal to OldPLABSize.
1201 // This is done in order to make ParNew+CMS configuration to work
1202 // with YoungPLABSize and OldPLABSize options.
1203 // See CR 6362902.
1204 if (!FLAG_IS_DEFAULT(OldPLABSize)) {
1205 if (FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim)) {
1206 // OldPLABSize is not the default value but CMSParPromoteBlocksToClaim
1207 // is. In this situtation let CMSParPromoteBlocksToClaim follow
1208 // the value (either from the command line or ergonomics) of
1209 // OldPLABSize. Following OldPLABSize is an ergonomics decision.
1210 FLAG_SET_ERGO(uintx, CMSParPromoteBlocksToClaim, OldPLABSize);
1211 } else {
1212 // OldPLABSize and CMSParPromoteBlocksToClaim are both set.
1213 // CMSParPromoteBlocksToClaim is a collector-specific flag, so
1214 // we'll let it to take precedence.
1215 jio_fprintf(defaultStream::error_stream(),
1216 "Both OldPLABSize and CMSParPromoteBlocksToClaim"
1217 " options are specified for the CMS collector."
1218 " CMSParPromoteBlocksToClaim will take precedence.\n");
1219 }
1220 }
1221 if (!FLAG_IS_DEFAULT(ResizeOldPLAB) && !ResizeOldPLAB) {
1222 // OldPLAB sizing manually turned off: Use a larger default setting,
1223 // unless it was manually specified. This is because a too-low value
1224 // will slow down scavenges.
1225 if (FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim)) {
1226 FLAG_SET_ERGO(uintx, CMSParPromoteBlocksToClaim, 50); // default value before 6631166
1227 }
1228 }
1229 // Overwrite OldPLABSize which is the variable we will internally use everywhere.
1230 FLAG_SET_ERGO(uintx, OldPLABSize, CMSParPromoteBlocksToClaim);
1231 // If either of the static initialization defaults have changed, note this
1232 // modification.
1233 if (!FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim) || !FLAG_IS_DEFAULT(OldPLABWeight)) {
1234 CFLS_LAB::modify_initialization(OldPLABSize, OldPLABWeight);
1235 }
1236 if (PrintGCDetails && Verbose) {
1237 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk",
1238 MarkStackSize / K, MarkStackSizeMax / K);
1239 tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
1240 }
1241 }
1242 #endif // KERNEL
1244 void set_object_alignment() {
1245 // Object alignment.
1246 assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2");
1247 MinObjAlignmentInBytes = ObjectAlignmentInBytes;
1248 assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small");
1249 MinObjAlignment = MinObjAlignmentInBytes / HeapWordSize;
1250 assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect");
1251 MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1;
1253 LogMinObjAlignmentInBytes = exact_log2(ObjectAlignmentInBytes);
1254 LogMinObjAlignment = LogMinObjAlignmentInBytes - LogHeapWordSize;
1256 // Oop encoding heap max
1257 OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes;
1259 #ifndef KERNEL
1260 // Set CMS global values
1261 CompactibleFreeListSpace::set_cms_values();
1262 #endif // KERNEL
1263 }
1265 bool verify_object_alignment() {
1266 // Object alignment.
1267 if (!is_power_of_2(ObjectAlignmentInBytes)) {
1268 jio_fprintf(defaultStream::error_stream(),
1269 "error: ObjectAlignmentInBytes=%d must be power of 2\n",
1270 (int)ObjectAlignmentInBytes);
1271 return false;
1272 }
1273 if ((int)ObjectAlignmentInBytes < BytesPerLong) {
1274 jio_fprintf(defaultStream::error_stream(),
1275 "error: ObjectAlignmentInBytes=%d must be greater or equal %d\n",
1276 (int)ObjectAlignmentInBytes, BytesPerLong);
1277 return false;
1278 }
1279 // It does not make sense to have big object alignment
1280 // since a space lost due to alignment will be greater
1281 // then a saved space from compressed oops.
1282 if ((int)ObjectAlignmentInBytes > 256) {
1283 jio_fprintf(defaultStream::error_stream(),
1284 "error: ObjectAlignmentInBytes=%d must not be greater then 256\n",
1285 (int)ObjectAlignmentInBytes);
1286 return false;
1287 }
1288 // In case page size is very small.
1289 if ((int)ObjectAlignmentInBytes >= os::vm_page_size()) {
1290 jio_fprintf(defaultStream::error_stream(),
1291 "error: ObjectAlignmentInBytes=%d must be less then page size %d\n",
1292 (int)ObjectAlignmentInBytes, os::vm_page_size());
1293 return false;
1294 }
1295 return true;
1296 }
1298 inline uintx max_heap_for_compressed_oops() {
1299 // Heap should be above HeapBaseMinAddress to get zero based compressed oops.
1300 LP64_ONLY(return OopEncodingHeapMax - MaxPermSize - os::vm_page_size() - HeapBaseMinAddress);
1301 NOT_LP64(ShouldNotReachHere(); return 0);
1302 }
1304 bool Arguments::should_auto_select_low_pause_collector() {
1305 if (UseAutoGCSelectPolicy &&
1306 !FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
1307 (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
1308 if (PrintGCDetails) {
1309 // Cannot use gclog_or_tty yet.
1310 tty->print_cr("Automatic selection of the low pause collector"
1311 " based on pause goal of %d (ms)", MaxGCPauseMillis);
1312 }
1313 return true;
1314 }
1315 return false;
1316 }
1318 void Arguments::set_ergonomics_flags() {
1319 // Parallel GC is not compatible with sharing. If one specifies
1320 // that they want sharing explicitly, do not set ergonomics flags.
1321 if (DumpSharedSpaces || ForceSharedSpaces) {
1322 return;
1323 }
1325 if (os::is_server_class_machine() && !force_client_mode ) {
1326 // If no other collector is requested explicitly,
1327 // let the VM select the collector based on
1328 // machine class and automatic selection policy.
1329 if (!UseSerialGC &&
1330 !UseConcMarkSweepGC &&
1331 !UseG1GC &&
1332 !UseParNewGC &&
1333 !DumpSharedSpaces &&
1334 FLAG_IS_DEFAULT(UseParallelGC)) {
1335 if (should_auto_select_low_pause_collector()) {
1336 FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
1337 } else {
1338 FLAG_SET_ERGO(bool, UseParallelGC, true);
1339 }
1340 no_shared_spaces();
1341 }
1342 }
1344 #ifndef ZERO
1345 #ifdef _LP64
1346 // Check that UseCompressedOops can be set with the max heap size allocated
1347 // by ergonomics.
1348 if (MaxHeapSize <= max_heap_for_compressed_oops()) {
1349 #if !defined(COMPILER1) || defined(TIERED)
1350 if (FLAG_IS_DEFAULT(UseCompressedOops) && !UseG1GC) {
1351 FLAG_SET_ERGO(bool, UseCompressedOops, true);
1352 }
1353 #endif
1354 #ifdef _WIN64
1355 if (UseLargePages && UseCompressedOops) {
1356 // Cannot allocate guard pages for implicit checks in indexed addressing
1357 // mode, when large pages are specified on windows.
1358 // This flag could be switched ON if narrow oop base address is set to 0,
1359 // see code in Universe::initialize_heap().
1360 Universe::set_narrow_oop_use_implicit_null_checks(false);
1361 }
1362 #endif // _WIN64
1363 } else {
1364 if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
1365 warning("Max heap size too large for Compressed Oops");
1366 FLAG_SET_DEFAULT(UseCompressedOops, false);
1367 }
1368 }
1369 // Also checks that certain machines are slower with compressed oops
1370 // in vm_version initialization code.
1371 #endif // _LP64
1372 #endif // !ZERO
1373 }
1375 void Arguments::set_parallel_gc_flags() {
1376 assert(UseParallelGC || UseParallelOldGC, "Error");
1377 // If parallel old was requested, automatically enable parallel scavenge.
1378 if (UseParallelOldGC && !UseParallelGC && FLAG_IS_DEFAULT(UseParallelGC)) {
1379 FLAG_SET_DEFAULT(UseParallelGC, true);
1380 }
1382 // If no heap maximum was requested explicitly, use some reasonable fraction
1383 // of the physical memory, up to a maximum of 1GB.
1384 if (UseParallelGC) {
1385 FLAG_SET_ERGO(uintx, ParallelGCThreads,
1386 Abstract_VM_Version::parallel_worker_threads());
1388 // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the
1389 // SurvivorRatio has been set, reset their default values to SurvivorRatio +
1390 // 2. By doing this we make SurvivorRatio also work for Parallel Scavenger.
1391 // See CR 6362902 for details.
1392 if (!FLAG_IS_DEFAULT(SurvivorRatio)) {
1393 if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) {
1394 FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2);
1395 }
1396 if (FLAG_IS_DEFAULT(MinSurvivorRatio)) {
1397 FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2);
1398 }
1399 }
1401 if (UseParallelOldGC) {
1402 // Par compact uses lower default values since they are treated as
1403 // minimums. These are different defaults because of the different
1404 // interpretation and are not ergonomically set.
1405 if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) {
1406 FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1);
1407 }
1408 if (FLAG_IS_DEFAULT(PermMarkSweepDeadRatio)) {
1409 FLAG_SET_DEFAULT(PermMarkSweepDeadRatio, 5);
1410 }
1411 }
1412 }
1413 }
1415 void Arguments::set_g1_gc_flags() {
1416 assert(UseG1GC, "Error");
1417 #ifdef COMPILER1
1418 FastTLABRefill = false;
1419 #endif
1420 FLAG_SET_DEFAULT(ParallelGCThreads,
1421 Abstract_VM_Version::parallel_worker_threads());
1422 if (ParallelGCThreads == 0) {
1423 FLAG_SET_DEFAULT(ParallelGCThreads,
1424 Abstract_VM_Version::parallel_worker_threads());
1425 }
1426 no_shared_spaces();
1428 if (FLAG_IS_DEFAULT(MarkStackSize)) {
1429 FLAG_SET_DEFAULT(MarkStackSize, 128 * TASKQUEUE_SIZE);
1430 }
1431 if (PrintGCDetails && Verbose) {
1432 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk",
1433 MarkStackSize / K, MarkStackSizeMax / K);
1434 tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
1435 }
1437 if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
1438 // In G1, we want the default GC overhead goal to be higher than
1439 // say in PS. So we set it here to 10%. Otherwise the heap might
1440 // be expanded more aggressively than we would like it to. In
1441 // fact, even 10% seems to not be high enough in some cases
1442 // (especially small GC stress tests that the main thing they do
1443 // is allocation). We might consider increase it further.
1444 FLAG_SET_DEFAULT(GCTimeRatio, 9);
1445 }
1446 }
1448 void Arguments::set_heap_size() {
1449 if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) {
1450 // Deprecated flag
1451 FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction);
1452 }
1454 const julong phys_mem =
1455 FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM)
1456 : (julong)MaxRAM;
1458 // If the maximum heap size has not been set with -Xmx,
1459 // then set it as fraction of the size of physical memory,
1460 // respecting the maximum and minimum sizes of the heap.
1461 if (FLAG_IS_DEFAULT(MaxHeapSize)) {
1462 julong reasonable_max = phys_mem / MaxRAMFraction;
1464 if (phys_mem <= MaxHeapSize * MinRAMFraction) {
1465 // Small physical memory, so use a minimum fraction of it for the heap
1466 reasonable_max = phys_mem / MinRAMFraction;
1467 } else {
1468 // Not-small physical memory, so require a heap at least
1469 // as large as MaxHeapSize
1470 reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
1471 }
1472 if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
1473 // Limit the heap size to ErgoHeapSizeLimit
1474 reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit);
1475 }
1476 if (UseCompressedOops) {
1477 // Limit the heap size to the maximum possible when using compressed oops
1478 reasonable_max = MIN2(reasonable_max, (julong)max_heap_for_compressed_oops());
1479 }
1480 reasonable_max = os::allocatable_physical_memory(reasonable_max);
1482 if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
1483 // An initial heap size was specified on the command line,
1484 // so be sure that the maximum size is consistent. Done
1485 // after call to allocatable_physical_memory because that
1486 // method might reduce the allocation size.
1487 reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
1488 }
1490 if (PrintGCDetails && Verbose) {
1491 // Cannot use gclog_or_tty yet.
1492 tty->print_cr(" Maximum heap size " SIZE_FORMAT, reasonable_max);
1493 }
1494 FLAG_SET_ERGO(uintx, MaxHeapSize, (uintx)reasonable_max);
1495 }
1497 // If the initial_heap_size has not been set with InitialHeapSize
1498 // or -Xms, then set it as fraction of the size of physical memory,
1499 // respecting the maximum and minimum sizes of the heap.
1500 if (FLAG_IS_DEFAULT(InitialHeapSize)) {
1501 julong reasonable_minimum = (julong)(OldSize + NewSize);
1503 reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
1505 reasonable_minimum = os::allocatable_physical_memory(reasonable_minimum);
1507 julong reasonable_initial = phys_mem / InitialRAMFraction;
1509 reasonable_initial = MAX2(reasonable_initial, reasonable_minimum);
1510 reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
1512 reasonable_initial = os::allocatable_physical_memory(reasonable_initial);
1514 if (PrintGCDetails && Verbose) {
1515 // Cannot use gclog_or_tty yet.
1516 tty->print_cr(" Initial heap size " SIZE_FORMAT, (uintx)reasonable_initial);
1517 tty->print_cr(" Minimum heap size " SIZE_FORMAT, (uintx)reasonable_minimum);
1518 }
1519 FLAG_SET_ERGO(uintx, InitialHeapSize, (uintx)reasonable_initial);
1520 set_min_heap_size((uintx)reasonable_minimum);
1521 }
1522 }
1524 // This must be called after ergonomics because we want bytecode rewriting
1525 // if the server compiler is used, or if UseSharedSpaces is disabled.
1526 void Arguments::set_bytecode_flags() {
1527 // Better not attempt to store into a read-only space.
1528 if (UseSharedSpaces) {
1529 FLAG_SET_DEFAULT(RewriteBytecodes, false);
1530 FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1531 }
1533 if (!RewriteBytecodes) {
1534 FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1535 }
1536 }
1538 // Aggressive optimization flags -XX:+AggressiveOpts
1539 void Arguments::set_aggressive_opts_flags() {
1540 #ifdef COMPILER2
1541 if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
1542 if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
1543 FLAG_SET_DEFAULT(EliminateAutoBox, true);
1544 }
1545 if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
1546 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000);
1547 }
1549 // Feed the cache size setting into the JDK
1550 char buffer[1024];
1551 sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
1552 add_property(buffer);
1553 }
1554 if (AggressiveOpts && FLAG_IS_DEFAULT(DoEscapeAnalysis)) {
1555 FLAG_SET_DEFAULT(DoEscapeAnalysis, true);
1556 }
1557 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) {
1558 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500);
1559 }
1560 if (AggressiveOpts && FLAG_IS_DEFAULT(OptimizeStringConcat)) {
1561 FLAG_SET_DEFAULT(OptimizeStringConcat, true);
1562 }
1563 if (AggressiveOpts && FLAG_IS_DEFAULT(OptimizeFill)) {
1564 FLAG_SET_DEFAULT(OptimizeFill, true);
1565 }
1566 #endif
1568 if (AggressiveOpts) {
1569 // Sample flag setting code
1570 // if (FLAG_IS_DEFAULT(EliminateZeroing)) {
1571 // FLAG_SET_DEFAULT(EliminateZeroing, true);
1572 // }
1573 }
1574 }
1576 //===========================================================================================================
1577 // Parsing of java.compiler property
1579 void Arguments::process_java_compiler_argument(char* arg) {
1580 // For backwards compatibility, Djava.compiler=NONE or ""
1581 // causes us to switch to -Xint mode UNLESS -Xdebug
1582 // is also specified.
1583 if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) {
1584 set_java_compiler(true); // "-Djava.compiler[=...]" most recently seen.
1585 }
1586 }
1588 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) {
1589 _sun_java_launcher = strdup(launcher);
1590 }
1592 bool Arguments::created_by_java_launcher() {
1593 assert(_sun_java_launcher != NULL, "property must have value");
1594 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1595 }
1597 //===========================================================================================================
1598 // Parsing of main arguments
1600 bool Arguments::verify_interval(uintx val, uintx min,
1601 uintx max, const char* name) {
1602 // Returns true iff value is in the inclusive interval [min..max]
1603 // false, otherwise.
1604 if (val >= min && val <= max) {
1605 return true;
1606 }
1607 jio_fprintf(defaultStream::error_stream(),
1608 "%s of " UINTX_FORMAT " is invalid; must be between " UINTX_FORMAT
1609 " and " UINTX_FORMAT "\n",
1610 name, val, min, max);
1611 return false;
1612 }
1614 bool Arguments::verify_min_value(intx val, intx min, const char* name) {
1615 // Returns true if given value is greater than specified min threshold
1616 // false, otherwise.
1617 if (val >= min ) {
1618 return true;
1619 }
1620 jio_fprintf(defaultStream::error_stream(),
1621 "%s of " INTX_FORMAT " is invalid; must be greater than " INTX_FORMAT "\n",
1622 name, val, min);
1623 return false;
1624 }
1626 bool Arguments::verify_percentage(uintx value, const char* name) {
1627 if (value <= 100) {
1628 return true;
1629 }
1630 jio_fprintf(defaultStream::error_stream(),
1631 "%s of " UINTX_FORMAT " is invalid; must be between 0 and 100\n",
1632 name, value);
1633 return false;
1634 }
1636 static void force_serial_gc() {
1637 FLAG_SET_DEFAULT(UseSerialGC, true);
1638 FLAG_SET_DEFAULT(UseParNewGC, false);
1639 FLAG_SET_DEFAULT(UseConcMarkSweepGC, false);
1640 FLAG_SET_DEFAULT(CMSIncrementalMode, false); // special CMS suboption
1641 FLAG_SET_DEFAULT(UseParallelGC, false);
1642 FLAG_SET_DEFAULT(UseParallelOldGC, false);
1643 FLAG_SET_DEFAULT(UseG1GC, false);
1644 }
1646 static bool verify_serial_gc_flags() {
1647 return (UseSerialGC &&
1648 !(UseParNewGC || (UseConcMarkSweepGC || CMSIncrementalMode) || UseG1GC ||
1649 UseParallelGC || UseParallelOldGC));
1650 }
1652 // Check consistency of GC selection
1653 bool Arguments::check_gc_consistency() {
1654 bool status = true;
1655 // Ensure that the user has not selected conflicting sets
1656 // of collectors. [Note: this check is merely a user convenience;
1657 // collectors over-ride each other so that only a non-conflicting
1658 // set is selected; however what the user gets is not what they
1659 // may have expected from the combination they asked for. It's
1660 // better to reduce user confusion by not allowing them to
1661 // select conflicting combinations.
1662 uint i = 0;
1663 if (UseSerialGC) i++;
1664 if (UseConcMarkSweepGC || UseParNewGC) i++;
1665 if (UseParallelGC || UseParallelOldGC) i++;
1666 if (UseG1GC) i++;
1667 if (i > 1) {
1668 jio_fprintf(defaultStream::error_stream(),
1669 "Conflicting collector combinations in option list; "
1670 "please refer to the release notes for the combinations "
1671 "allowed\n");
1672 status = false;
1673 }
1675 return status;
1676 }
1678 // Check stack pages settings
1679 bool Arguments::check_stack_pages()
1680 {
1681 bool status = true;
1682 status = status && verify_min_value(StackYellowPages, 1, "StackYellowPages");
1683 status = status && verify_min_value(StackRedPages, 1, "StackRedPages");
1684 // greater stack shadow pages can't generate instruction to bang stack
1685 status = status && verify_interval(StackShadowPages, 1, 50, "StackShadowPages");
1686 return status;
1687 }
1689 // Check the consistency of vm_init_args
1690 bool Arguments::check_vm_args_consistency() {
1691 // Method for adding checks for flag consistency.
1692 // The intent is to warn the user of all possible conflicts,
1693 // before returning an error.
1694 // Note: Needs platform-dependent factoring.
1695 bool status = true;
1697 #if ( (defined(COMPILER2) && defined(SPARC)))
1698 // NOTE: The call to VM_Version_init depends on the fact that VM_Version_init
1699 // on sparc doesn't require generation of a stub as is the case on, e.g.,
1700 // x86. Normally, VM_Version_init must be called from init_globals in
1701 // init.cpp, which is called by the initial java thread *after* arguments
1702 // have been parsed. VM_Version_init gets called twice on sparc.
1703 extern void VM_Version_init();
1704 VM_Version_init();
1705 if (!VM_Version::has_v9()) {
1706 jio_fprintf(defaultStream::error_stream(),
1707 "V8 Machine detected, Server requires V9\n");
1708 status = false;
1709 }
1710 #endif /* COMPILER2 && SPARC */
1712 // Allow both -XX:-UseStackBanging and -XX:-UseBoundThreads in non-product
1713 // builds so the cost of stack banging can be measured.
1714 #if (defined(PRODUCT) && defined(SOLARIS))
1715 if (!UseBoundThreads && !UseStackBanging) {
1716 jio_fprintf(defaultStream::error_stream(),
1717 "-UseStackBanging conflicts with -UseBoundThreads\n");
1719 status = false;
1720 }
1721 #endif
1723 if (TLABRefillWasteFraction == 0) {
1724 jio_fprintf(defaultStream::error_stream(),
1725 "TLABRefillWasteFraction should be a denominator, "
1726 "not " SIZE_FORMAT "\n",
1727 TLABRefillWasteFraction);
1728 status = false;
1729 }
1731 status = status && verify_percentage(MaxLiveObjectEvacuationRatio,
1732 "MaxLiveObjectEvacuationRatio");
1733 status = status && verify_percentage(AdaptiveSizePolicyWeight,
1734 "AdaptiveSizePolicyWeight");
1735 status = status && verify_percentage(AdaptivePermSizeWeight, "AdaptivePermSizeWeight");
1736 status = status && verify_percentage(ThresholdTolerance, "ThresholdTolerance");
1737 status = status && verify_percentage(MinHeapFreeRatio, "MinHeapFreeRatio");
1738 status = status && verify_percentage(MaxHeapFreeRatio, "MaxHeapFreeRatio");
1740 if (MinHeapFreeRatio > MaxHeapFreeRatio) {
1741 jio_fprintf(defaultStream::error_stream(),
1742 "MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or "
1743 "equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n",
1744 MinHeapFreeRatio, MaxHeapFreeRatio);
1745 status = false;
1746 }
1747 // Keeping the heap 100% free is hard ;-) so limit it to 99%.
1748 MinHeapFreeRatio = MIN2(MinHeapFreeRatio, (uintx) 99);
1750 if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
1751 MarkSweepAlwaysCompactCount = 1; // Move objects every gc.
1752 }
1754 if (UseParallelOldGC && ParallelOldGCSplitALot) {
1755 // Settings to encourage splitting.
1756 if (!FLAG_IS_CMDLINE(NewRatio)) {
1757 FLAG_SET_CMDLINE(intx, NewRatio, 2);
1758 }
1759 if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) {
1760 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
1761 }
1762 }
1764 status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
1765 status = status && verify_percentage(GCTimeLimit, "GCTimeLimit");
1766 if (GCTimeLimit == 100) {
1767 // Turn off gc-overhead-limit-exceeded checks
1768 FLAG_SET_DEFAULT(UseGCOverheadLimit, false);
1769 }
1771 status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
1773 // Check whether user-specified sharing option conflicts with GC or page size.
1774 // Both sharing and large pages are enabled by default on some platforms;
1775 // large pages override sharing only if explicitly set on the command line.
1776 const bool cannot_share = UseConcMarkSweepGC || CMSIncrementalMode ||
1777 UseG1GC || UseParNewGC || UseParallelGC || UseParallelOldGC ||
1778 UseLargePages && FLAG_IS_CMDLINE(UseLargePages);
1779 if (cannot_share) {
1780 // Either force sharing on by forcing the other options off, or
1781 // force sharing off.
1782 if (DumpSharedSpaces || ForceSharedSpaces) {
1783 jio_fprintf(defaultStream::error_stream(),
1784 "Using Serial GC and default page size because of %s\n",
1785 ForceSharedSpaces ? "-Xshare:on" : "-Xshare:dump");
1786 force_serial_gc();
1787 FLAG_SET_DEFAULT(UseLargePages, false);
1788 } else {
1789 if (UseSharedSpaces && Verbose) {
1790 jio_fprintf(defaultStream::error_stream(),
1791 "Turning off use of shared archive because of "
1792 "choice of garbage collector or large pages\n");
1793 }
1794 no_shared_spaces();
1795 }
1796 } else if (UseLargePages && (UseSharedSpaces || DumpSharedSpaces)) {
1797 FLAG_SET_DEFAULT(UseLargePages, false);
1798 }
1800 status = status && check_gc_consistency();
1801 status = status && check_stack_pages();
1803 if (_has_alloc_profile) {
1804 if (UseParallelGC || UseParallelOldGC) {
1805 jio_fprintf(defaultStream::error_stream(),
1806 "error: invalid argument combination.\n"
1807 "Allocation profiling (-Xaprof) cannot be used together with "
1808 "Parallel GC (-XX:+UseParallelGC or -XX:+UseParallelOldGC).\n");
1809 status = false;
1810 }
1811 if (UseConcMarkSweepGC) {
1812 jio_fprintf(defaultStream::error_stream(),
1813 "error: invalid argument combination.\n"
1814 "Allocation profiling (-Xaprof) cannot be used together with "
1815 "the CMS collector (-XX:+UseConcMarkSweepGC).\n");
1816 status = false;
1817 }
1818 }
1820 if (CMSIncrementalMode) {
1821 if (!UseConcMarkSweepGC) {
1822 jio_fprintf(defaultStream::error_stream(),
1823 "error: invalid argument combination.\n"
1824 "The CMS collector (-XX:+UseConcMarkSweepGC) must be "
1825 "selected in order\nto use CMSIncrementalMode.\n");
1826 status = false;
1827 } else {
1828 status = status && verify_percentage(CMSIncrementalDutyCycle,
1829 "CMSIncrementalDutyCycle");
1830 status = status && verify_percentage(CMSIncrementalDutyCycleMin,
1831 "CMSIncrementalDutyCycleMin");
1832 status = status && verify_percentage(CMSIncrementalSafetyFactor,
1833 "CMSIncrementalSafetyFactor");
1834 status = status && verify_percentage(CMSIncrementalOffset,
1835 "CMSIncrementalOffset");
1836 status = status && verify_percentage(CMSExpAvgFactor,
1837 "CMSExpAvgFactor");
1838 // If it was not set on the command line, set
1839 // CMSInitiatingOccupancyFraction to 1 so icms can initiate cycles early.
1840 if (CMSInitiatingOccupancyFraction < 0) {
1841 FLAG_SET_DEFAULT(CMSInitiatingOccupancyFraction, 1);
1842 }
1843 }
1844 }
1846 // CMS space iteration, which FLSVerifyAllHeapreferences entails,
1847 // insists that we hold the requisite locks so that the iteration is
1848 // MT-safe. For the verification at start-up and shut-down, we don't
1849 // yet have a good way of acquiring and releasing these locks,
1850 // which are not visible at the CollectedHeap level. We want to
1851 // be able to acquire these locks and then do the iteration rather
1852 // than just disable the lock verification. This will be fixed under
1853 // bug 4788986.
1854 if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) {
1855 if (VerifyGCStartAt == 0) {
1856 warning("Heap verification at start-up disabled "
1857 "(due to current incompatibility with FLSVerifyAllHeapReferences)");
1858 VerifyGCStartAt = 1; // Disable verification at start-up
1859 }
1860 if (VerifyBeforeExit) {
1861 warning("Heap verification at shutdown disabled "
1862 "(due to current incompatibility with FLSVerifyAllHeapReferences)");
1863 VerifyBeforeExit = false; // Disable verification at shutdown
1864 }
1865 }
1867 // Note: only executed in non-PRODUCT mode
1868 if (!UseAsyncConcMarkSweepGC &&
1869 (ExplicitGCInvokesConcurrent ||
1870 ExplicitGCInvokesConcurrentAndUnloadsClasses)) {
1871 jio_fprintf(defaultStream::error_stream(),
1872 "error: +ExplictGCInvokesConcurrent[AndUnloadsClasses] conflicts"
1873 " with -UseAsyncConcMarkSweepGC");
1874 status = false;
1875 }
1877 if (UseG1GC) {
1878 status = status && verify_percentage(InitiatingHeapOccupancyPercent,
1879 "InitiatingHeapOccupancyPercent");
1880 }
1882 status = status && verify_interval(RefDiscoveryPolicy,
1883 ReferenceProcessor::DiscoveryPolicyMin,
1884 ReferenceProcessor::DiscoveryPolicyMax,
1885 "RefDiscoveryPolicy");
1887 // Limit the lower bound of this flag to 1 as it is used in a division
1888 // expression.
1889 status = status && verify_interval(TLABWasteTargetPercent,
1890 1, 100, "TLABWasteTargetPercent");
1892 status = status && verify_object_alignment();
1894 return status;
1895 }
1897 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore,
1898 const char* option_type) {
1899 if (ignore) return false;
1901 const char* spacer = " ";
1902 if (option_type == NULL) {
1903 option_type = ++spacer; // Set both to the empty string.
1904 }
1906 if (os::obsolete_option(option)) {
1907 jio_fprintf(defaultStream::error_stream(),
1908 "Obsolete %s%soption: %s\n", option_type, spacer,
1909 option->optionString);
1910 return false;
1911 } else {
1912 jio_fprintf(defaultStream::error_stream(),
1913 "Unrecognized %s%soption: %s\n", option_type, spacer,
1914 option->optionString);
1915 return true;
1916 }
1917 }
1919 static const char* user_assertion_options[] = {
1920 "-da", "-ea", "-disableassertions", "-enableassertions", 0
1921 };
1923 static const char* system_assertion_options[] = {
1924 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0
1925 };
1927 // Return true if any of the strings in null-terminated array 'names' matches.
1928 // If tail_allowed is true, then the tail must begin with a colon; otherwise,
1929 // the option must match exactly.
1930 static bool match_option(const JavaVMOption* option, const char** names, const char** tail,
1931 bool tail_allowed) {
1932 for (/* empty */; *names != NULL; ++names) {
1933 if (match_option(option, *names, tail)) {
1934 if (**tail == '\0' || tail_allowed && **tail == ':') {
1935 return true;
1936 }
1937 }
1938 }
1939 return false;
1940 }
1942 bool Arguments::parse_uintx(const char* value,
1943 uintx* uintx_arg,
1944 uintx min_size) {
1946 // Check the sign first since atomull() parses only unsigned values.
1947 bool value_is_positive = !(*value == '-');
1949 if (value_is_positive) {
1950 julong n;
1951 bool good_return = atomull(value, &n);
1952 if (good_return) {
1953 bool above_minimum = n >= min_size;
1954 bool value_is_too_large = n > max_uintx;
1956 if (above_minimum && !value_is_too_large) {
1957 *uintx_arg = n;
1958 return true;
1959 }
1960 }
1961 }
1962 return false;
1963 }
1965 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1966 julong* long_arg,
1967 julong min_size) {
1968 if (!atomull(s, long_arg)) return arg_unreadable;
1969 return check_memory_size(*long_arg, min_size);
1970 }
1972 // Parse JavaVMInitArgs structure
1974 jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) {
1975 // For components of the system classpath.
1976 SysClassPath scp(Arguments::get_sysclasspath());
1977 bool scp_assembly_required = false;
1979 // Save default settings for some mode flags
1980 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1981 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
1982 Arguments::_ClipInlining = ClipInlining;
1983 Arguments::_BackgroundCompilation = BackgroundCompilation;
1985 // Parse JAVA_TOOL_OPTIONS environment variable (if present)
1986 jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required);
1987 if (result != JNI_OK) {
1988 return result;
1989 }
1991 // Parse JavaVMInitArgs structure passed in
1992 result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, COMMAND_LINE);
1993 if (result != JNI_OK) {
1994 return result;
1995 }
1997 if (AggressiveOpts) {
1998 // Insert alt-rt.jar between user-specified bootclasspath
1999 // prefix and the default bootclasspath. os::set_boot_path()
2000 // uses meta_index_dir as the default bootclasspath directory.
2001 const char* altclasses_jar = "alt-rt.jar";
2002 size_t altclasses_path_len = strlen(get_meta_index_dir()) + 1 +
2003 strlen(altclasses_jar);
2004 char* altclasses_path = NEW_C_HEAP_ARRAY(char, altclasses_path_len);
2005 strcpy(altclasses_path, get_meta_index_dir());
2006 strcat(altclasses_path, altclasses_jar);
2007 scp.add_suffix_to_prefix(altclasses_path);
2008 scp_assembly_required = true;
2009 FREE_C_HEAP_ARRAY(char, altclasses_path);
2010 }
2012 // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM)
2013 result = parse_java_options_environment_variable(&scp, &scp_assembly_required);
2014 if (result != JNI_OK) {
2015 return result;
2016 }
2018 // Do final processing now that all arguments have been parsed
2019 result = finalize_vm_init_args(&scp, scp_assembly_required);
2020 if (result != JNI_OK) {
2021 return result;
2022 }
2024 return JNI_OK;
2025 }
2027 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
2028 SysClassPath* scp_p,
2029 bool* scp_assembly_required_p,
2030 FlagValueOrigin origin) {
2031 // Remaining part of option string
2032 const char* tail;
2034 // iterate over arguments
2035 for (int index = 0; index < args->nOptions; index++) {
2036 bool is_absolute_path = false; // for -agentpath vs -agentlib
2038 const JavaVMOption* option = args->options + index;
2040 if (!match_option(option, "-Djava.class.path", &tail) &&
2041 !match_option(option, "-Dsun.java.command", &tail) &&
2042 !match_option(option, "-Dsun.java.launcher", &tail)) {
2044 // add all jvm options to the jvm_args string. This string
2045 // is used later to set the java.vm.args PerfData string constant.
2046 // the -Djava.class.path and the -Dsun.java.command options are
2047 // omitted from jvm_args string as each have their own PerfData
2048 // string constant object.
2049 build_jvm_args(option->optionString);
2050 }
2052 // -verbose:[class/gc/jni]
2053 if (match_option(option, "-verbose", &tail)) {
2054 if (!strcmp(tail, ":class") || !strcmp(tail, "")) {
2055 FLAG_SET_CMDLINE(bool, TraceClassLoading, true);
2056 FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
2057 } else if (!strcmp(tail, ":gc")) {
2058 FLAG_SET_CMDLINE(bool, PrintGC, true);
2059 } else if (!strcmp(tail, ":jni")) {
2060 FLAG_SET_CMDLINE(bool, PrintJNIResolving, true);
2061 }
2062 // -da / -ea / -disableassertions / -enableassertions
2063 // These accept an optional class/package name separated by a colon, e.g.,
2064 // -da:java.lang.Thread.
2065 } else if (match_option(option, user_assertion_options, &tail, true)) {
2066 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e'
2067 if (*tail == '\0') {
2068 JavaAssertions::setUserClassDefault(enable);
2069 } else {
2070 assert(*tail == ':', "bogus match by match_option()");
2071 JavaAssertions::addOption(tail + 1, enable);
2072 }
2073 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions
2074 } else if (match_option(option, system_assertion_options, &tail, false)) {
2075 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e'
2076 JavaAssertions::setSystemClassDefault(enable);
2077 // -bootclasspath:
2078 } else if (match_option(option, "-Xbootclasspath:", &tail)) {
2079 scp_p->reset_path(tail);
2080 *scp_assembly_required_p = true;
2081 // -bootclasspath/a:
2082 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) {
2083 scp_p->add_suffix(tail);
2084 *scp_assembly_required_p = true;
2085 // -bootclasspath/p:
2086 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) {
2087 scp_p->add_prefix(tail);
2088 *scp_assembly_required_p = true;
2089 // -Xrun
2090 } else if (match_option(option, "-Xrun", &tail)) {
2091 if (tail != NULL) {
2092 const char* pos = strchr(tail, ':');
2093 size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
2094 char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
2095 name[len] = '\0';
2097 char *options = NULL;
2098 if(pos != NULL) {
2099 size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied.
2100 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2), pos+1, len2);
2101 }
2102 #ifdef JVMTI_KERNEL
2103 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
2104 warning("profiling and debugging agents are not supported with Kernel VM");
2105 } else
2106 #endif // JVMTI_KERNEL
2107 add_init_library(name, options);
2108 }
2109 // -agentlib and -agentpath
2110 } else if (match_option(option, "-agentlib:", &tail) ||
2111 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2112 if(tail != NULL) {
2113 const char* pos = strchr(tail, '=');
2114 size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
2115 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
2116 name[len] = '\0';
2118 char *options = NULL;
2119 if(pos != NULL) {
2120 options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1), pos + 1);
2121 }
2122 #ifdef JVMTI_KERNEL
2123 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
2124 warning("profiling and debugging agents are not supported with Kernel VM");
2125 } else
2126 #endif // JVMTI_KERNEL
2127 add_init_agent(name, options, is_absolute_path);
2129 }
2130 // -javaagent
2131 } else if (match_option(option, "-javaagent:", &tail)) {
2132 if(tail != NULL) {
2133 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1), tail);
2134 add_init_agent("instrument", options, false);
2135 }
2136 // -Xnoclassgc
2137 } else if (match_option(option, "-Xnoclassgc", &tail)) {
2138 FLAG_SET_CMDLINE(bool, ClassUnloading, false);
2139 // -Xincgc: i-CMS
2140 } else if (match_option(option, "-Xincgc", &tail)) {
2141 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
2142 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, true);
2143 // -Xnoincgc: no i-CMS
2144 } else if (match_option(option, "-Xnoincgc", &tail)) {
2145 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
2146 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, false);
2147 // -Xconcgc
2148 } else if (match_option(option, "-Xconcgc", &tail)) {
2149 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
2150 // -Xnoconcgc
2151 } else if (match_option(option, "-Xnoconcgc", &tail)) {
2152 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
2153 // -Xbatch
2154 } else if (match_option(option, "-Xbatch", &tail)) {
2155 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
2156 // -Xmn for compatibility with other JVM vendors
2157 } else if (match_option(option, "-Xmn", &tail)) {
2158 julong long_initial_eden_size = 0;
2159 ArgsRange errcode = parse_memory_size(tail, &long_initial_eden_size, 1);
2160 if (errcode != arg_in_range) {
2161 jio_fprintf(defaultStream::error_stream(),
2162 "Invalid initial eden size: %s\n", option->optionString);
2163 describe_range_error(errcode);
2164 return JNI_EINVAL;
2165 }
2166 FLAG_SET_CMDLINE(uintx, MaxNewSize, (uintx)long_initial_eden_size);
2167 FLAG_SET_CMDLINE(uintx, NewSize, (uintx)long_initial_eden_size);
2168 // -Xms
2169 } else if (match_option(option, "-Xms", &tail)) {
2170 julong long_initial_heap_size = 0;
2171 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 1);
2172 if (errcode != arg_in_range) {
2173 jio_fprintf(defaultStream::error_stream(),
2174 "Invalid initial heap size: %s\n", option->optionString);
2175 describe_range_error(errcode);
2176 return JNI_EINVAL;
2177 }
2178 FLAG_SET_CMDLINE(uintx, InitialHeapSize, (uintx)long_initial_heap_size);
2179 // Currently the minimum size and the initial heap sizes are the same.
2180 set_min_heap_size(InitialHeapSize);
2181 // -Xmx
2182 } else if (match_option(option, "-Xmx", &tail)) {
2183 julong long_max_heap_size = 0;
2184 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
2185 if (errcode != arg_in_range) {
2186 jio_fprintf(defaultStream::error_stream(),
2187 "Invalid maximum heap size: %s\n", option->optionString);
2188 describe_range_error(errcode);
2189 return JNI_EINVAL;
2190 }
2191 FLAG_SET_CMDLINE(uintx, MaxHeapSize, (uintx)long_max_heap_size);
2192 // Xmaxf
2193 } else if (match_option(option, "-Xmaxf", &tail)) {
2194 int maxf = (int)(atof(tail) * 100);
2195 if (maxf < 0 || maxf > 100) {
2196 jio_fprintf(defaultStream::error_stream(),
2197 "Bad max heap free percentage size: %s\n",
2198 option->optionString);
2199 return JNI_EINVAL;
2200 } else {
2201 FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf);
2202 }
2203 // Xminf
2204 } else if (match_option(option, "-Xminf", &tail)) {
2205 int minf = (int)(atof(tail) * 100);
2206 if (minf < 0 || minf > 100) {
2207 jio_fprintf(defaultStream::error_stream(),
2208 "Bad min heap free percentage size: %s\n",
2209 option->optionString);
2210 return JNI_EINVAL;
2211 } else {
2212 FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf);
2213 }
2214 // -Xss
2215 } else if (match_option(option, "-Xss", &tail)) {
2216 julong long_ThreadStackSize = 0;
2217 ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
2218 if (errcode != arg_in_range) {
2219 jio_fprintf(defaultStream::error_stream(),
2220 "Invalid thread stack size: %s\n", option->optionString);
2221 describe_range_error(errcode);
2222 return JNI_EINVAL;
2223 }
2224 // Internally track ThreadStackSize in units of 1024 bytes.
2225 FLAG_SET_CMDLINE(intx, ThreadStackSize,
2226 round_to((int)long_ThreadStackSize, K) / K);
2227 // -Xoss
2228 } else if (match_option(option, "-Xoss", &tail)) {
2229 // HotSpot does not have separate native and Java stacks, ignore silently for compatibility
2230 // -Xmaxjitcodesize
2231 } else if (match_option(option, "-Xmaxjitcodesize", &tail)) {
2232 julong long_ReservedCodeCacheSize = 0;
2233 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize,
2234 (size_t)InitialCodeCacheSize);
2235 if (errcode != arg_in_range) {
2236 jio_fprintf(defaultStream::error_stream(),
2237 "Invalid maximum code cache size: %s\n",
2238 option->optionString);
2239 describe_range_error(errcode);
2240 return JNI_EINVAL;
2241 }
2242 FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize);
2243 // -green
2244 } else if (match_option(option, "-green", &tail)) {
2245 jio_fprintf(defaultStream::error_stream(),
2246 "Green threads support not available\n");
2247 return JNI_EINVAL;
2248 // -native
2249 } else if (match_option(option, "-native", &tail)) {
2250 // HotSpot always uses native threads, ignore silently for compatibility
2251 // -Xsqnopause
2252 } else if (match_option(option, "-Xsqnopause", &tail)) {
2253 // EVM option, ignore silently for compatibility
2254 // -Xrs
2255 } else if (match_option(option, "-Xrs", &tail)) {
2256 // Classic/EVM option, new functionality
2257 FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true);
2258 } else if (match_option(option, "-Xusealtsigs", &tail)) {
2259 // change default internal VM signals used - lower case for back compat
2260 FLAG_SET_CMDLINE(bool, UseAltSigs, true);
2261 // -Xoptimize
2262 } else if (match_option(option, "-Xoptimize", &tail)) {
2263 // EVM option, ignore silently for compatibility
2264 // -Xprof
2265 } else if (match_option(option, "-Xprof", &tail)) {
2266 #ifndef FPROF_KERNEL
2267 _has_profile = true;
2268 #else // FPROF_KERNEL
2269 // do we have to exit?
2270 warning("Kernel VM does not support flat profiling.");
2271 #endif // FPROF_KERNEL
2272 // -Xaprof
2273 } else if (match_option(option, "-Xaprof", &tail)) {
2274 _has_alloc_profile = true;
2275 // -Xconcurrentio
2276 } else if (match_option(option, "-Xconcurrentio", &tail)) {
2277 FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true);
2278 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
2279 FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1);
2280 FLAG_SET_CMDLINE(bool, UseTLAB, false);
2281 FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K); // 20Kb per thread added to new generation
2283 // -Xinternalversion
2284 } else if (match_option(option, "-Xinternalversion", &tail)) {
2285 jio_fprintf(defaultStream::output_stream(), "%s\n",
2286 VM_Version::internal_vm_info_string());
2287 vm_exit(0);
2288 #ifndef PRODUCT
2289 // -Xprintflags
2290 } else if (match_option(option, "-Xprintflags", &tail)) {
2291 CommandLineFlags::printFlags();
2292 vm_exit(0);
2293 #endif
2294 // -D
2295 } else if (match_option(option, "-D", &tail)) {
2296 if (!add_property(tail)) {
2297 return JNI_ENOMEM;
2298 }
2299 // Out of the box management support
2300 if (match_option(option, "-Dcom.sun.management", &tail)) {
2301 FLAG_SET_CMDLINE(bool, ManagementServer, true);
2302 }
2303 // -Xint
2304 } else if (match_option(option, "-Xint", &tail)) {
2305 set_mode_flags(_int);
2306 // -Xmixed
2307 } else if (match_option(option, "-Xmixed", &tail)) {
2308 set_mode_flags(_mixed);
2309 // -Xcomp
2310 } else if (match_option(option, "-Xcomp", &tail)) {
2311 // for testing the compiler; turn off all flags that inhibit compilation
2312 set_mode_flags(_comp);
2314 // -Xshare:dump
2315 } else if (match_option(option, "-Xshare:dump", &tail)) {
2316 #ifdef TIERED
2317 FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
2318 set_mode_flags(_int); // Prevent compilation, which creates objects
2319 #elif defined(COMPILER2)
2320 vm_exit_during_initialization(
2321 "Dumping a shared archive is not supported on the Server JVM.", NULL);
2322 #elif defined(KERNEL)
2323 vm_exit_during_initialization(
2324 "Dumping a shared archive is not supported on the Kernel JVM.", NULL);
2325 #else
2326 FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
2327 set_mode_flags(_int); // Prevent compilation, which creates objects
2328 #endif
2329 // -Xshare:on
2330 } else if (match_option(option, "-Xshare:on", &tail)) {
2331 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
2332 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true);
2333 #ifdef TIERED
2334 FLAG_SET_CMDLINE(bool, ForceSharedSpaces, true);
2335 #endif // TIERED
2336 // -Xshare:auto
2337 } else if (match_option(option, "-Xshare:auto", &tail)) {
2338 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
2339 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
2340 // -Xshare:off
2341 } else if (match_option(option, "-Xshare:off", &tail)) {
2342 FLAG_SET_CMDLINE(bool, UseSharedSpaces, false);
2343 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
2345 // -Xverify
2346 } else if (match_option(option, "-Xverify", &tail)) {
2347 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) {
2348 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true);
2349 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
2350 } else if (strcmp(tail, ":remote") == 0) {
2351 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
2352 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
2353 } else if (strcmp(tail, ":none") == 0) {
2354 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
2355 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false);
2356 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) {
2357 return JNI_EINVAL;
2358 }
2359 // -Xdebug
2360 } else if (match_option(option, "-Xdebug", &tail)) {
2361 // note this flag has been used, then ignore
2362 set_xdebug_mode(true);
2363 // -Xnoagent
2364 } else if (match_option(option, "-Xnoagent", &tail)) {
2365 // For compatibility with classic. HotSpot refuses to load the old style agent.dll.
2366 } else if (match_option(option, "-Xboundthreads", &tail)) {
2367 // Bind user level threads to kernel threads (Solaris only)
2368 FLAG_SET_CMDLINE(bool, UseBoundThreads, true);
2369 } else if (match_option(option, "-Xloggc:", &tail)) {
2370 // Redirect GC output to the file. -Xloggc:<filename>
2371 // ostream_init_log(), when called will use this filename
2372 // to initialize a fileStream.
2373 _gc_log_filename = strdup(tail);
2374 FLAG_SET_CMDLINE(bool, PrintGC, true);
2375 FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true);
2376 FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
2378 // JNI hooks
2379 } else if (match_option(option, "-Xcheck", &tail)) {
2380 if (!strcmp(tail, ":jni")) {
2381 CheckJNICalls = true;
2382 } else if (is_bad_option(option, args->ignoreUnrecognized,
2383 "check")) {
2384 return JNI_EINVAL;
2385 }
2386 } else if (match_option(option, "vfprintf", &tail)) {
2387 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo);
2388 } else if (match_option(option, "exit", &tail)) {
2389 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
2390 } else if (match_option(option, "abort", &tail)) {
2391 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
2392 // -XX:+AggressiveHeap
2393 } else if (match_option(option, "-XX:+AggressiveHeap", &tail)) {
2395 // This option inspects the machine and attempts to set various
2396 // parameters to be optimal for long-running, memory allocation
2397 // intensive jobs. It is intended for machines with large
2398 // amounts of cpu and memory.
2400 // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
2401 // VM, but we may not be able to represent the total physical memory
2402 // available (like having 8gb of memory on a box but using a 32bit VM).
2403 // Thus, we need to make sure we're using a julong for intermediate
2404 // calculations.
2405 julong initHeapSize;
2406 julong total_memory = os::physical_memory();
2408 if (total_memory < (julong)256*M) {
2409 jio_fprintf(defaultStream::error_stream(),
2410 "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
2411 vm_exit(1);
2412 }
2414 // The heap size is half of available memory, or (at most)
2415 // all of possible memory less 160mb (leaving room for the OS
2416 // when using ISM). This is the maximum; because adaptive sizing
2417 // is turned on below, the actual space used may be smaller.
2419 initHeapSize = MIN2(total_memory / (julong)2,
2420 total_memory - (julong)160*M);
2422 // Make sure that if we have a lot of memory we cap the 32 bit
2423 // process space. The 64bit VM version of this function is a nop.
2424 initHeapSize = os::allocatable_physical_memory(initHeapSize);
2426 // The perm gen is separate but contiguous with the
2427 // object heap (and is reserved with it) so subtract it
2428 // from the heap size.
2429 if (initHeapSize > MaxPermSize) {
2430 initHeapSize = initHeapSize - MaxPermSize;
2431 } else {
2432 warning("AggressiveHeap and MaxPermSize values may conflict");
2433 }
2435 if (FLAG_IS_DEFAULT(MaxHeapSize)) {
2436 FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize);
2437 FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize);
2438 // Currently the minimum size and the initial heap sizes are the same.
2439 set_min_heap_size(initHeapSize);
2440 }
2441 if (FLAG_IS_DEFAULT(NewSize)) {
2442 // Make the young generation 3/8ths of the total heap.
2443 FLAG_SET_CMDLINE(uintx, NewSize,
2444 ((julong)MaxHeapSize / (julong)8) * (julong)3);
2445 FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
2446 }
2448 FLAG_SET_DEFAULT(UseLargePages, true);
2450 // Increase some data structure sizes for efficiency
2451 FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
2452 FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
2453 FLAG_SET_CMDLINE(uintx, TLABSize, 256*K);
2455 // See the OldPLABSize comment below, but replace 'after promotion'
2456 // with 'after copying'. YoungPLABSize is the size of the survivor
2457 // space per-gc-thread buffers. The default is 4kw.
2458 FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256*K); // Note: this is in words
2460 // OldPLABSize is the size of the buffers in the old gen that
2461 // UseParallelGC uses to promote live data that doesn't fit in the
2462 // survivor spaces. At any given time, there's one for each gc thread.
2463 // The default size is 1kw. These buffers are rarely used, since the
2464 // survivor spaces are usually big enough. For specjbb, however, there
2465 // are occasions when there's lots of live data in the young gen
2466 // and we end up promoting some of it. We don't have a definite
2467 // explanation for why bumping OldPLABSize helps, but the theory
2468 // is that a bigger PLAB results in retaining something like the
2469 // original allocation order after promotion, which improves mutator
2470 // locality. A minor effect may be that larger PLABs reduce the
2471 // number of PLAB allocation events during gc. The value of 8kw
2472 // was arrived at by experimenting with specjbb.
2473 FLAG_SET_CMDLINE(uintx, OldPLABSize, 8*K); // Note: this is in words
2475 // CompilationPolicyChoice=0 causes the server compiler to adopt
2476 // a more conservative which-method-do-I-compile policy when one
2477 // of the counters maintained by the interpreter trips. The
2478 // result is reduced startup time and improved specjbb and
2479 // alacrity performance. Zero is the default, but we set it
2480 // explicitly here in case the default changes.
2481 // See runtime/compilationPolicy.*.
2482 FLAG_SET_CMDLINE(intx, CompilationPolicyChoice, 0);
2484 // Enable parallel GC and adaptive generation sizing
2485 FLAG_SET_CMDLINE(bool, UseParallelGC, true);
2486 FLAG_SET_DEFAULT(ParallelGCThreads,
2487 Abstract_VM_Version::parallel_worker_threads());
2489 // Encourage steady state memory management
2490 FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
2492 // This appears to improve mutator locality
2493 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
2495 // Get around early Solaris scheduling bug
2496 // (affinity vs other jobs on system)
2497 // but disallow DR and offlining (5008695).
2498 FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
2500 } else if (match_option(option, "-XX:+NeverTenure", &tail)) {
2501 // The last option must always win.
2502 FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
2503 FLAG_SET_CMDLINE(bool, NeverTenure, true);
2504 } else if (match_option(option, "-XX:+AlwaysTenure", &tail)) {
2505 // The last option must always win.
2506 FLAG_SET_CMDLINE(bool, NeverTenure, false);
2507 FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
2508 } else if (match_option(option, "-XX:+CMSPermGenSweepingEnabled", &tail) ||
2509 match_option(option, "-XX:-CMSPermGenSweepingEnabled", &tail)) {
2510 jio_fprintf(defaultStream::error_stream(),
2511 "Please use CMSClassUnloadingEnabled in place of "
2512 "CMSPermGenSweepingEnabled in the future\n");
2513 } else if (match_option(option, "-XX:+UseGCTimeLimit", &tail)) {
2514 FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, true);
2515 jio_fprintf(defaultStream::error_stream(),
2516 "Please use -XX:+UseGCOverheadLimit in place of "
2517 "-XX:+UseGCTimeLimit in the future\n");
2518 } else if (match_option(option, "-XX:-UseGCTimeLimit", &tail)) {
2519 FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, false);
2520 jio_fprintf(defaultStream::error_stream(),
2521 "Please use -XX:-UseGCOverheadLimit in place of "
2522 "-XX:-UseGCTimeLimit in the future\n");
2523 // The TLE options are for compatibility with 1.3 and will be
2524 // removed without notice in a future release. These options
2525 // are not to be documented.
2526 } else if (match_option(option, "-XX:MaxTLERatio=", &tail)) {
2527 // No longer used.
2528 } else if (match_option(option, "-XX:+ResizeTLE", &tail)) {
2529 FLAG_SET_CMDLINE(bool, ResizeTLAB, true);
2530 } else if (match_option(option, "-XX:-ResizeTLE", &tail)) {
2531 FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
2532 } else if (match_option(option, "-XX:+PrintTLE", &tail)) {
2533 FLAG_SET_CMDLINE(bool, PrintTLAB, true);
2534 } else if (match_option(option, "-XX:-PrintTLE", &tail)) {
2535 FLAG_SET_CMDLINE(bool, PrintTLAB, false);
2536 } else if (match_option(option, "-XX:TLEFragmentationRatio=", &tail)) {
2537 // No longer used.
2538 } else if (match_option(option, "-XX:TLESize=", &tail)) {
2539 julong long_tlab_size = 0;
2540 ArgsRange errcode = parse_memory_size(tail, &long_tlab_size, 1);
2541 if (errcode != arg_in_range) {
2542 jio_fprintf(defaultStream::error_stream(),
2543 "Invalid TLAB size: %s\n", option->optionString);
2544 describe_range_error(errcode);
2545 return JNI_EINVAL;
2546 }
2547 FLAG_SET_CMDLINE(uintx, TLABSize, long_tlab_size);
2548 } else if (match_option(option, "-XX:TLEThreadRatio=", &tail)) {
2549 // No longer used.
2550 } else if (match_option(option, "-XX:+UseTLE", &tail)) {
2551 FLAG_SET_CMDLINE(bool, UseTLAB, true);
2552 } else if (match_option(option, "-XX:-UseTLE", &tail)) {
2553 FLAG_SET_CMDLINE(bool, UseTLAB, false);
2554 SOLARIS_ONLY(
2555 } else if (match_option(option, "-XX:+UsePermISM", &tail)) {
2556 warning("-XX:+UsePermISM is obsolete.");
2557 FLAG_SET_CMDLINE(bool, UseISM, true);
2558 } else if (match_option(option, "-XX:-UsePermISM", &tail)) {
2559 FLAG_SET_CMDLINE(bool, UseISM, false);
2560 )
2561 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr", &tail)) {
2562 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false);
2563 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true);
2564 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout", &tail)) {
2565 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false);
2566 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true);
2567 } else if (match_option(option, "-XX:+ExtendedDTraceProbes", &tail)) {
2568 #ifdef SOLARIS
2569 FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true);
2570 FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true);
2571 FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true);
2572 FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true);
2573 #else // ndef SOLARIS
2574 jio_fprintf(defaultStream::error_stream(),
2575 "ExtendedDTraceProbes flag is only applicable on Solaris\n");
2576 return JNI_EINVAL;
2577 #endif // ndef SOLARIS
2578 #ifdef ASSERT
2579 } else if (match_option(option, "-XX:+FullGCALot", &tail)) {
2580 FLAG_SET_CMDLINE(bool, FullGCALot, true);
2581 // disable scavenge before parallel mark-compact
2582 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
2583 #endif
2584 } else if (match_option(option, "-XX:CMSParPromoteBlocksToClaim=", &tail)) {
2585 julong cms_blocks_to_claim = (julong)atol(tail);
2586 FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim);
2587 jio_fprintf(defaultStream::error_stream(),
2588 "Please use -XX:OldPLABSize in place of "
2589 "-XX:CMSParPromoteBlocksToClaim in the future\n");
2590 } else if (match_option(option, "-XX:ParCMSPromoteBlocksToClaim=", &tail)) {
2591 julong cms_blocks_to_claim = (julong)atol(tail);
2592 FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim);
2593 jio_fprintf(defaultStream::error_stream(),
2594 "Please use -XX:OldPLABSize in place of "
2595 "-XX:ParCMSPromoteBlocksToClaim in the future\n");
2596 } else if (match_option(option, "-XX:ParallelGCOldGenAllocBufferSize=", &tail)) {
2597 julong old_plab_size = 0;
2598 ArgsRange errcode = parse_memory_size(tail, &old_plab_size, 1);
2599 if (errcode != arg_in_range) {
2600 jio_fprintf(defaultStream::error_stream(),
2601 "Invalid old PLAB size: %s\n", option->optionString);
2602 describe_range_error(errcode);
2603 return JNI_EINVAL;
2604 }
2605 FLAG_SET_CMDLINE(uintx, OldPLABSize, old_plab_size);
2606 jio_fprintf(defaultStream::error_stream(),
2607 "Please use -XX:OldPLABSize in place of "
2608 "-XX:ParallelGCOldGenAllocBufferSize in the future\n");
2609 } else if (match_option(option, "-XX:ParallelGCToSpaceAllocBufferSize=", &tail)) {
2610 julong young_plab_size = 0;
2611 ArgsRange errcode = parse_memory_size(tail, &young_plab_size, 1);
2612 if (errcode != arg_in_range) {
2613 jio_fprintf(defaultStream::error_stream(),
2614 "Invalid young PLAB size: %s\n", option->optionString);
2615 describe_range_error(errcode);
2616 return JNI_EINVAL;
2617 }
2618 FLAG_SET_CMDLINE(uintx, YoungPLABSize, young_plab_size);
2619 jio_fprintf(defaultStream::error_stream(),
2620 "Please use -XX:YoungPLABSize in place of "
2621 "-XX:ParallelGCToSpaceAllocBufferSize in the future\n");
2622 } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) ||
2623 match_option(option, "-XX:G1MarkStackSize=", &tail)) {
2624 julong stack_size = 0;
2625 ArgsRange errcode = parse_memory_size(tail, &stack_size, 1);
2626 if (errcode != arg_in_range) {
2627 jio_fprintf(defaultStream::error_stream(),
2628 "Invalid mark stack size: %s\n", option->optionString);
2629 describe_range_error(errcode);
2630 return JNI_EINVAL;
2631 }
2632 FLAG_SET_CMDLINE(uintx, MarkStackSize, stack_size);
2633 } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) {
2634 julong max_stack_size = 0;
2635 ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1);
2636 if (errcode != arg_in_range) {
2637 jio_fprintf(defaultStream::error_stream(),
2638 "Invalid maximum mark stack size: %s\n",
2639 option->optionString);
2640 describe_range_error(errcode);
2641 return JNI_EINVAL;
2642 }
2643 FLAG_SET_CMDLINE(uintx, MarkStackSizeMax, max_stack_size);
2644 } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) ||
2645 match_option(option, "-XX:ParallelCMSThreads=", &tail)) {
2646 uintx conc_threads = 0;
2647 if (!parse_uintx(tail, &conc_threads, 1)) {
2648 jio_fprintf(defaultStream::error_stream(),
2649 "Invalid concurrent threads: %s\n", option->optionString);
2650 return JNI_EINVAL;
2651 }
2652 FLAG_SET_CMDLINE(uintx, ConcGCThreads, conc_threads);
2653 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
2654 // Skip -XX:Flags= since that case has already been handled
2655 if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) {
2656 if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
2657 return JNI_EINVAL;
2658 }
2659 }
2660 // Unknown option
2661 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2662 return JNI_ERR;
2663 }
2664 }
2665 // Change the default value for flags which have different default values
2666 // when working with older JDKs.
2667 if (JDK_Version::current().compare_major(6) <= 0 &&
2668 FLAG_IS_DEFAULT(UseVMInterruptibleIO)) {
2669 FLAG_SET_DEFAULT(UseVMInterruptibleIO, true);
2670 }
2671 #ifdef LINUX
2672 if (JDK_Version::current().compare_major(6) <= 0 &&
2673 FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) {
2674 FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false);
2675 }
2676 #endif // LINUX
2677 return JNI_OK;
2678 }
2680 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) {
2681 // This must be done after all -D arguments have been processed.
2682 scp_p->expand_endorsed();
2684 if (scp_assembly_required || scp_p->get_endorsed() != NULL) {
2685 // Assemble the bootclasspath elements into the final path.
2686 Arguments::set_sysclasspath(scp_p->combined_path());
2687 }
2689 // This must be done after all arguments have been processed.
2690 // java_compiler() true means set to "NONE" or empty.
2691 if (java_compiler() && !xdebug_mode()) {
2692 // For backwards compatibility, we switch to interpreted mode if
2693 // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was
2694 // not specified.
2695 set_mode_flags(_int);
2696 }
2697 if (CompileThreshold == 0) {
2698 set_mode_flags(_int);
2699 }
2701 #ifndef COMPILER2
2702 // Don't degrade server performance for footprint
2703 if (FLAG_IS_DEFAULT(UseLargePages) &&
2704 MaxHeapSize < LargePageHeapSizeThreshold) {
2705 // No need for large granularity pages w/small heaps.
2706 // Note that large pages are enabled/disabled for both the
2707 // Java heap and the code cache.
2708 FLAG_SET_DEFAULT(UseLargePages, false);
2709 SOLARIS_ONLY(FLAG_SET_DEFAULT(UseMPSS, false));
2710 SOLARIS_ONLY(FLAG_SET_DEFAULT(UseISM, false));
2711 }
2713 // Tiered compilation is undefined with C1.
2714 TieredCompilation = false;
2715 #else
2716 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
2717 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
2718 }
2719 // Temporary disable bulk zeroing reduction with G1. See CR 6627983.
2720 if (UseG1GC) {
2721 FLAG_SET_DEFAULT(ReduceBulkZeroing, false);
2722 }
2723 #endif
2725 // If we are running in a headless jre, force java.awt.headless property
2726 // to be true unless the property has already been set.
2727 // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state.
2728 if (os::is_headless_jre()) {
2729 const char* headless = Arguments::get_property("java.awt.headless");
2730 if (headless == NULL) {
2731 char envbuffer[128];
2732 if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof(envbuffer))) {
2733 if (!add_property("java.awt.headless=true")) {
2734 return JNI_ENOMEM;
2735 }
2736 } else {
2737 char buffer[256];
2738 strcpy(buffer, "java.awt.headless=");
2739 strcat(buffer, envbuffer);
2740 if (!add_property(buffer)) {
2741 return JNI_ENOMEM;
2742 }
2743 }
2744 }
2745 }
2747 if (!check_vm_args_consistency()) {
2748 return JNI_ERR;
2749 }
2751 return JNI_OK;
2752 }
2754 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
2755 return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
2756 scp_assembly_required_p);
2757 }
2759 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
2760 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p,
2761 scp_assembly_required_p);
2762 }
2764 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) {
2765 const int N_MAX_OPTIONS = 64;
2766 const int OPTION_BUFFER_SIZE = 1024;
2767 char buffer[OPTION_BUFFER_SIZE];
2769 // The variable will be ignored if it exceeds the length of the buffer.
2770 // Don't check this variable if user has special privileges
2771 // (e.g. unix su command).
2772 if (os::getenv(name, buffer, sizeof(buffer)) &&
2773 !os::have_special_privileges()) {
2774 JavaVMOption options[N_MAX_OPTIONS]; // Construct option array
2775 jio_fprintf(defaultStream::error_stream(),
2776 "Picked up %s: %s\n", name, buffer);
2777 char* rd = buffer; // pointer to the input string (rd)
2778 int i;
2779 for (i = 0; i < N_MAX_OPTIONS;) { // repeat for all options in the input string
2780 while (isspace(*rd)) rd++; // skip whitespace
2781 if (*rd == 0) break; // we re done when the input string is read completely
2783 // The output, option string, overwrites the input string.
2784 // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
2785 // input string (rd).
2786 char* wrt = rd;
2788 options[i++].optionString = wrt; // Fill in option
2789 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL
2790 if (*rd == '\'' || *rd == '"') { // handle a quoted string
2791 int quote = *rd; // matching quote to look for
2792 rd++; // don't copy open quote
2793 while (*rd != quote) { // include everything (even spaces) up until quote
2794 if (*rd == 0) { // string termination means unmatched string
2795 jio_fprintf(defaultStream::error_stream(),
2796 "Unmatched quote in %s\n", name);
2797 return JNI_ERR;
2798 }
2799 *wrt++ = *rd++; // copy to option string
2800 }
2801 rd++; // don't copy close quote
2802 } else {
2803 *wrt++ = *rd++; // copy to option string
2804 }
2805 }
2806 // Need to check if we're done before writing a NULL,
2807 // because the write could be to the byte that rd is pointing to.
2808 if (*rd++ == 0) {
2809 *wrt = 0;
2810 break;
2811 }
2812 *wrt = 0; // Zero terminate option
2813 }
2814 // Construct JavaVMInitArgs structure and parse as if it was part of the command line
2815 JavaVMInitArgs vm_args;
2816 vm_args.version = JNI_VERSION_1_2;
2817 vm_args.options = options;
2818 vm_args.nOptions = i;
2819 vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions;
2821 if (PrintVMOptions) {
2822 const char* tail;
2823 for (int i = 0; i < vm_args.nOptions; i++) {
2824 const JavaVMOption *option = vm_args.options + i;
2825 if (match_option(option, "-XX:", &tail)) {
2826 logOption(tail);
2827 }
2828 }
2829 }
2831 return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, ENVIRON_VAR));
2832 }
2833 return JNI_OK;
2834 }
2836 // Parse entry point called from JNI_CreateJavaVM
2838 jint Arguments::parse(const JavaVMInitArgs* args) {
2840 // Sharing support
2841 // Construct the path to the archive
2842 char jvm_path[JVM_MAXPATHLEN];
2843 os::jvm_path(jvm_path, sizeof(jvm_path));
2844 #ifdef TIERED
2845 if (strstr(jvm_path, "client") != NULL) {
2846 force_client_mode = true;
2847 }
2848 #endif // TIERED
2849 char *end = strrchr(jvm_path, *os::file_separator());
2850 if (end != NULL) *end = '\0';
2851 char *shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(jvm_path) +
2852 strlen(os::file_separator()) + 20);
2853 if (shared_archive_path == NULL) return JNI_ENOMEM;
2854 strcpy(shared_archive_path, jvm_path);
2855 strcat(shared_archive_path, os::file_separator());
2856 strcat(shared_archive_path, "classes");
2857 DEBUG_ONLY(strcat(shared_archive_path, "_g");)
2858 strcat(shared_archive_path, ".jsa");
2859 SharedArchivePath = shared_archive_path;
2861 // Remaining part of option string
2862 const char* tail;
2864 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
2865 bool settings_file_specified = false;
2866 const char* flags_file;
2867 int index;
2868 for (index = 0; index < args->nOptions; index++) {
2869 const JavaVMOption *option = args->options + index;
2870 if (match_option(option, "-XX:Flags=", &tail)) {
2871 flags_file = tail;
2872 settings_file_specified = true;
2873 }
2874 if (match_option(option, "-XX:+PrintVMOptions", &tail)) {
2875 PrintVMOptions = true;
2876 }
2877 if (match_option(option, "-XX:-PrintVMOptions", &tail)) {
2878 PrintVMOptions = false;
2879 }
2880 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions", &tail)) {
2881 IgnoreUnrecognizedVMOptions = true;
2882 }
2883 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions", &tail)) {
2884 IgnoreUnrecognizedVMOptions = false;
2885 }
2886 if (match_option(option, "-XX:+PrintFlagsInitial", &tail)) {
2887 CommandLineFlags::printFlags();
2888 vm_exit(0);
2889 }
2891 #ifndef PRODUCT
2892 if (match_option(option, "-XX:+PrintFlagsWithComments", &tail)) {
2893 CommandLineFlags::printFlags(true);
2894 vm_exit(0);
2895 }
2896 #endif
2897 }
2899 if (IgnoreUnrecognizedVMOptions) {
2900 // uncast const to modify the flag args->ignoreUnrecognized
2901 *(jboolean*)(&args->ignoreUnrecognized) = true;
2902 }
2904 // Parse specified settings file
2905 if (settings_file_specified) {
2906 if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) {
2907 return JNI_EINVAL;
2908 }
2909 }
2911 // Parse default .hotspotrc settings file
2912 if (!settings_file_specified) {
2913 if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) {
2914 return JNI_EINVAL;
2915 }
2916 }
2918 if (PrintVMOptions) {
2919 for (index = 0; index < args->nOptions; index++) {
2920 const JavaVMOption *option = args->options + index;
2921 if (match_option(option, "-XX:", &tail)) {
2922 logOption(tail);
2923 }
2924 }
2925 }
2927 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
2928 jint result = parse_vm_init_args(args);
2929 if (result != JNI_OK) {
2930 return result;
2931 }
2933 #ifndef PRODUCT
2934 if (TraceBytecodesAt != 0) {
2935 TraceBytecodes = true;
2936 }
2937 if (CountCompiledCalls) {
2938 if (UseCounterDecay) {
2939 warning("UseCounterDecay disabled because CountCalls is set");
2940 UseCounterDecay = false;
2941 }
2942 }
2943 #endif // PRODUCT
2945 if (EnableInvokeDynamic && !EnableMethodHandles) {
2946 if (!FLAG_IS_DEFAULT(EnableMethodHandles)) {
2947 warning("forcing EnableMethodHandles true because EnableInvokeDynamic is true");
2948 }
2949 EnableMethodHandles = true;
2950 }
2951 if (EnableMethodHandles && !AnonymousClasses) {
2952 if (!FLAG_IS_DEFAULT(AnonymousClasses)) {
2953 warning("forcing AnonymousClasses true because EnableMethodHandles is true");
2954 }
2955 AnonymousClasses = true;
2956 }
2957 if ((EnableMethodHandles || AnonymousClasses) && ScavengeRootsInCode == 0) {
2958 if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) {
2959 warning("forcing ScavengeRootsInCode non-zero because EnableMethodHandles or AnonymousClasses is true");
2960 }
2961 ScavengeRootsInCode = 1;
2962 }
2963 #ifdef COMPILER2
2964 if (EnableInvokeDynamic && DoEscapeAnalysis) {
2965 // TODO: We need to find rules for invokedynamic and EA. For now,
2966 // simply disable EA by default.
2967 if (FLAG_IS_DEFAULT(DoEscapeAnalysis)) {
2968 DoEscapeAnalysis = false;
2969 }
2970 }
2971 #endif
2973 if (PrintGCDetails) {
2974 // Turn on -verbose:gc options as well
2975 PrintGC = true;
2976 }
2978 #if defined(_LP64) && defined(COMPILER1) && !defined(TIERED)
2979 UseCompressedOops = false;
2980 #endif
2982 #if defined(_LP64)
2983 if ((DumpSharedSpaces || RequireSharedSpaces) && UseCompressedOops) {
2984 // Disable compressed oops with shared spaces
2985 UseCompressedOops = false;
2986 }
2987 #endif
2989 // Set object alignment values.
2990 set_object_alignment();
2992 #ifdef SERIALGC
2993 force_serial_gc();
2994 #endif // SERIALGC
2995 #ifdef KERNEL
2996 no_shared_spaces();
2997 #endif // KERNEL
2999 // Set flags based on ergonomics.
3000 set_ergonomics_flags();
3002 #ifdef _LP64
3003 // XXX JSR 292 currently does not support compressed oops.
3004 if (EnableMethodHandles && UseCompressedOops) {
3005 if (FLAG_IS_DEFAULT(UseCompressedOops) || FLAG_IS_ERGO(UseCompressedOops)) {
3006 UseCompressedOops = false;
3007 }
3008 }
3009 #endif // _LP64
3011 // Check the GC selections again.
3012 if (!check_gc_consistency()) {
3013 return JNI_EINVAL;
3014 }
3016 if (TieredCompilation) {
3017 set_tiered_flags();
3018 } else {
3019 // Check if the policy is valid. Policies 0 and 1 are valid for non-tiered setup.
3020 if (CompilationPolicyChoice >= 2) {
3021 vm_exit_during_initialization(
3022 "Incompatible compilation policy selected", NULL);
3023 }
3024 }
3026 #ifndef KERNEL
3027 if (UseConcMarkSweepGC) {
3028 // Set flags for CMS and ParNew. Check UseConcMarkSweep first
3029 // to ensure that when both UseConcMarkSweepGC and UseParNewGC
3030 // are true, we don't call set_parnew_gc_flags() as well.
3031 set_cms_and_parnew_gc_flags();
3032 } else {
3033 // Set heap size based on available physical memory
3034 set_heap_size();
3035 // Set per-collector flags
3036 if (UseParallelGC || UseParallelOldGC) {
3037 set_parallel_gc_flags();
3038 } else if (UseParNewGC) {
3039 set_parnew_gc_flags();
3040 } else if (UseG1GC) {
3041 set_g1_gc_flags();
3042 }
3043 }
3044 #endif // KERNEL
3046 #ifdef SERIALGC
3047 assert(verify_serial_gc_flags(), "SerialGC unset");
3048 #endif // SERIALGC
3050 // Set bytecode rewriting flags
3051 set_bytecode_flags();
3053 // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled.
3054 set_aggressive_opts_flags();
3056 #ifdef CC_INTERP
3057 // Clear flags not supported by the C++ interpreter
3058 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3059 FLAG_SET_DEFAULT(UseBiasedLocking, false);
3060 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false));
3061 #endif // CC_INTERP
3063 #ifdef COMPILER2
3064 if (!UseBiasedLocking || EmitSync != 0) {
3065 UseOptoBiasInlining = false;
3066 }
3067 #endif
3069 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3070 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3071 DebugNonSafepoints = true;
3072 }
3074 #ifndef PRODUCT
3075 if (CompileTheWorld) {
3076 // Force NmethodSweeper to sweep whole CodeCache each time.
3077 if (FLAG_IS_DEFAULT(NmethodSweepFraction)) {
3078 NmethodSweepFraction = 1;
3079 }
3080 }
3081 #endif
3083 if (PrintCommandLineFlags) {
3084 CommandLineFlags::printSetFlags();
3085 }
3087 // Apply CPU specific policy for the BiasedLocking
3088 if (UseBiasedLocking) {
3089 if (!VM_Version::use_biased_locking() &&
3090 !(FLAG_IS_CMDLINE(UseBiasedLocking))) {
3091 UseBiasedLocking = false;
3092 }
3093 }
3095 return JNI_OK;
3096 }
3098 int Arguments::PropertyList_count(SystemProperty* pl) {
3099 int count = 0;
3100 while(pl != NULL) {
3101 count++;
3102 pl = pl->next();
3103 }
3104 return count;
3105 }
3107 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) {
3108 assert(key != NULL, "just checking");
3109 SystemProperty* prop;
3110 for (prop = pl; prop != NULL; prop = prop->next()) {
3111 if (strcmp(key, prop->key()) == 0) return prop->value();
3112 }
3113 return NULL;
3114 }
3116 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) {
3117 int count = 0;
3118 const char* ret_val = NULL;
3120 while(pl != NULL) {
3121 if(count >= index) {
3122 ret_val = pl->key();
3123 break;
3124 }
3125 count++;
3126 pl = pl->next();
3127 }
3129 return ret_val;
3130 }
3132 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) {
3133 int count = 0;
3134 char* ret_val = NULL;
3136 while(pl != NULL) {
3137 if(count >= index) {
3138 ret_val = pl->value();
3139 break;
3140 }
3141 count++;
3142 pl = pl->next();
3143 }
3145 return ret_val;
3146 }
3148 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) {
3149 SystemProperty* p = *plist;
3150 if (p == NULL) {
3151 *plist = new_p;
3152 } else {
3153 while (p->next() != NULL) {
3154 p = p->next();
3155 }
3156 p->set_next(new_p);
3157 }
3158 }
3160 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) {
3161 if (plist == NULL)
3162 return;
3164 SystemProperty* new_p = new SystemProperty(k, v, true);
3165 PropertyList_add(plist, new_p);
3166 }
3168 // This add maintains unique property key in the list.
3169 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append) {
3170 if (plist == NULL)
3171 return;
3173 // If property key exist then update with new value.
3174 SystemProperty* prop;
3175 for (prop = *plist; prop != NULL; prop = prop->next()) {
3176 if (strcmp(k, prop->key()) == 0) {
3177 if (append) {
3178 prop->append_value(v);
3179 } else {
3180 prop->set_value(v);
3181 }
3182 return;
3183 }
3184 }
3186 PropertyList_add(plist, k, v);
3187 }
3189 #ifdef KERNEL
3190 char *Arguments::get_kernel_properties() {
3191 // Find properties starting with kernel and append them to string
3192 // We need to find out how long they are first because the URL's that they
3193 // might point to could get long.
3194 int length = 0;
3195 SystemProperty* prop;
3196 for (prop = _system_properties; prop != NULL; prop = prop->next()) {
3197 if (strncmp(prop->key(), "kernel.", 7 ) == 0) {
3198 length += (strlen(prop->key()) + strlen(prop->value()) + 5); // "-D ="
3199 }
3200 }
3201 // Add one for null terminator.
3202 char *props = AllocateHeap(length + 1, "get_kernel_properties");
3203 if (length != 0) {
3204 int pos = 0;
3205 for (prop = _system_properties; prop != NULL; prop = prop->next()) {
3206 if (strncmp(prop->key(), "kernel.", 7 ) == 0) {
3207 jio_snprintf(&props[pos], length-pos,
3208 "-D%s=%s ", prop->key(), prop->value());
3209 pos = strlen(props);
3210 }
3211 }
3212 }
3213 // null terminate props in case of null
3214 props[length] = '\0';
3215 return props;
3216 }
3217 #endif // KERNEL
3219 // Copies src into buf, replacing "%%" with "%" and "%p" with pid
3220 // Returns true if all of the source pointed by src has been copied over to
3221 // the destination buffer pointed by buf. Otherwise, returns false.
3222 // Notes:
3223 // 1. If the length (buflen) of the destination buffer excluding the
3224 // NULL terminator character is not long enough for holding the expanded
3225 // pid characters, it also returns false instead of returning the partially
3226 // expanded one.
3227 // 2. The passed in "buflen" should be large enough to hold the null terminator.
3228 bool Arguments::copy_expand_pid(const char* src, size_t srclen,
3229 char* buf, size_t buflen) {
3230 const char* p = src;
3231 char* b = buf;
3232 const char* src_end = &src[srclen];
3233 char* buf_end = &buf[buflen - 1];
3235 while (p < src_end && b < buf_end) {
3236 if (*p == '%') {
3237 switch (*(++p)) {
3238 case '%': // "%%" ==> "%"
3239 *b++ = *p++;
3240 break;
3241 case 'p': { // "%p" ==> current process id
3242 // buf_end points to the character before the last character so
3243 // that we could write '\0' to the end of the buffer.
3244 size_t buf_sz = buf_end - b + 1;
3245 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id());
3247 // if jio_snprintf fails or the buffer is not long enough to hold
3248 // the expanded pid, returns false.
3249 if (ret < 0 || ret >= (int)buf_sz) {
3250 return false;
3251 } else {
3252 b += ret;
3253 assert(*b == '\0', "fail in copy_expand_pid");
3254 if (p == src_end && b == buf_end + 1) {
3255 // reach the end of the buffer.
3256 return true;
3257 }
3258 }
3259 p++;
3260 break;
3261 }
3262 default :
3263 *b++ = '%';
3264 }
3265 } else {
3266 *b++ = *p++;
3267 }
3268 }
3269 *b = '\0';
3270 return (p == src_end); // return false if not all of the source was copied
3271 }