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