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