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