Print this page
Split |
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, 2015, 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/classLoader.hpp"
27 27 #include "classfile/javaAssertions.hpp"
28 28 #include "classfile/stringTable.hpp"
29 29 #include "classfile/symbolTable.hpp"
30 30 #include "compiler/compilerOracle.hpp"
31 31 #include "gc/shared/cardTableRS.hpp"
32 32 #include "gc/shared/genCollectedHeap.hpp"
33 33 #include "gc/shared/referenceProcessor.hpp"
34 34 #include "gc/shared/taskqueue.hpp"
35 35 #include "memory/allocation.inline.hpp"
36 36 #include "memory/universe.inline.hpp"
37 37 #include "oops/oop.inline.hpp"
38 38 #include "prims/jvmtiExport.hpp"
39 39 #include "runtime/arguments.hpp"
40 40 #include "runtime/arguments_ext.hpp"
41 41 #include "runtime/globals_extension.hpp"
42 42 #include "runtime/java.hpp"
43 43 #include "runtime/os.hpp"
44 44 #include "runtime/vm_version.hpp"
45 45 #include "services/management.hpp"
46 46 #include "services/memTracker.hpp"
47 47 #include "utilities/defaultStream.hpp"
48 48 #include "utilities/macros.hpp"
49 49 #include "utilities/stringUtils.hpp"
50 50 #if INCLUDE_ALL_GCS
51 51 #include "gc/cms/compactibleFreeListSpace.hpp"
52 52 #include "gc/g1/g1CollectedHeap.inline.hpp"
53 53 #include "gc/parallel/parallelScavengeHeap.hpp"
54 54 #endif // INCLUDE_ALL_GCS
55 55
56 56 // Note: This is a special bug reporting site for the JVM
57 57 #define DEFAULT_VENDOR_URL_BUG "http://bugreport.java.com/bugreport/crash.jsp"
58 58 #define DEFAULT_JAVA_LAUNCHER "generic"
59 59
60 60 #define UNSUPPORTED_GC_OPTION(gc) \
61 61 do { \
62 62 if (gc) { \
63 63 if (FLAG_IS_CMDLINE(gc)) { \
64 64 warning(#gc " is not supported in this VM. Using Serial GC."); \
65 65 } \
66 66 FLAG_SET_DEFAULT(gc, false); \
67 67 } \
68 68 } while(0)
69 69
70 70 char** Arguments::_jvm_flags_array = NULL;
71 71 int Arguments::_num_jvm_flags = 0;
72 72 char** Arguments::_jvm_args_array = NULL;
73 73 int Arguments::_num_jvm_args = 0;
74 74 char* Arguments::_java_command = NULL;
75 75 SystemProperty* Arguments::_system_properties = NULL;
76 76 const char* Arguments::_gc_log_filename = NULL;
77 77 bool Arguments::_has_profile = false;
78 78 size_t Arguments::_conservative_max_heap_alignment = 0;
79 79 size_t Arguments::_min_heap_size = 0;
80 80 uintx Arguments::_min_heap_free_ratio = 0;
81 81 uintx Arguments::_max_heap_free_ratio = 0;
82 82 Arguments::Mode Arguments::_mode = _mixed;
83 83 bool Arguments::_java_compiler = false;
84 84 bool Arguments::_xdebug_mode = false;
85 85 const char* Arguments::_java_vendor_url_bug = DEFAULT_VENDOR_URL_BUG;
86 86 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
87 87 int Arguments::_sun_java_launcher_pid = -1;
88 88 bool Arguments::_sun_java_launcher_is_altjvm = false;
89 89
90 90 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
91 91 bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
92 92 bool Arguments::_UseOnStackReplacement = UseOnStackReplacement;
93 93 bool Arguments::_BackgroundCompilation = BackgroundCompilation;
94 94 bool Arguments::_ClipInlining = ClipInlining;
95 95 intx Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog;
96 96 intx Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold;
97 97
98 98 char* Arguments::SharedArchivePath = NULL;
99 99
100 100 AgentLibraryList Arguments::_libraryList;
101 101 AgentLibraryList Arguments::_agentList;
102 102
103 103 abort_hook_t Arguments::_abort_hook = NULL;
104 104 exit_hook_t Arguments::_exit_hook = NULL;
105 105 vfprintf_hook_t Arguments::_vfprintf_hook = NULL;
106 106
107 107
108 108 SystemProperty *Arguments::_sun_boot_library_path = NULL;
109 109 SystemProperty *Arguments::_java_library_path = NULL;
110 110 SystemProperty *Arguments::_java_home = NULL;
111 111 SystemProperty *Arguments::_java_class_path = NULL;
112 112 SystemProperty *Arguments::_sun_boot_class_path = NULL;
113 113
114 114 char* Arguments::_ext_dirs = NULL;
115 115
116 116 // Check if head of 'option' matches 'name', and sets 'tail' to the remaining
117 117 // part of the option string.
118 118 static bool match_option(const JavaVMOption *option, const char* name,
119 119 const char** tail) {
120 120 int len = (int)strlen(name);
121 121 if (strncmp(option->optionString, name, len) == 0) {
122 122 *tail = option->optionString + len;
123 123 return true;
124 124 } else {
125 125 return false;
126 126 }
127 127 }
128 128
129 129 // Check if 'option' matches 'name'. No "tail" is allowed.
130 130 static bool match_option(const JavaVMOption *option, const char* name) {
131 131 const char* tail = NULL;
132 132 bool result = match_option(option, name, &tail);
133 133 if (tail != NULL && *tail == '\0') {
134 134 return result;
135 135 } else {
136 136 return false;
137 137 }
138 138 }
139 139
140 140 // Return true if any of the strings in null-terminated array 'names' matches.
141 141 // If tail_allowed is true, then the tail must begin with a colon; otherwise,
142 142 // the option must match exactly.
143 143 static bool match_option(const JavaVMOption* option, const char** names, const char** tail,
144 144 bool tail_allowed) {
145 145 for (/* empty */; *names != NULL; ++names) {
146 146 if (match_option(option, *names, tail)) {
147 147 if (**tail == '\0' || tail_allowed && **tail == ':') {
148 148 return true;
149 149 }
150 150 }
151 151 }
152 152 return false;
153 153 }
154 154
155 155 static void logOption(const char* opt) {
156 156 if (PrintVMOptions) {
157 157 jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
158 158 }
159 159 }
160 160
161 161 // Process java launcher properties.
162 162 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
163 163 // See if sun.java.launcher, sun.java.launcher.is_altjvm or
164 164 // sun.java.launcher.pid is defined.
165 165 // Must do this before setting up other system properties,
166 166 // as some of them may depend on launcher type.
167 167 for (int index = 0; index < args->nOptions; index++) {
168 168 const JavaVMOption* option = args->options + index;
169 169 const char* tail;
170 170
171 171 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
172 172 process_java_launcher_argument(tail, option->extraInfo);
173 173 continue;
174 174 }
175 175 if (match_option(option, "-Dsun.java.launcher.is_altjvm=", &tail)) {
176 176 if (strcmp(tail, "true") == 0) {
177 177 _sun_java_launcher_is_altjvm = true;
178 178 }
179 179 continue;
180 180 }
181 181 if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
182 182 _sun_java_launcher_pid = atoi(tail);
183 183 continue;
184 184 }
185 185 }
186 186 }
187 187
188 188 // Initialize system properties key and value.
189 189 void Arguments::init_system_properties() {
190 190
191 191 PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name",
192 192 "Java Virtual Machine Specification", false));
193 193 PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(), false));
194 194 PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(), false));
195 195 PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(), true));
196 196
197 197 // Following are JVMTI agent writable properties.
198 198 // Properties values are set to NULL and they are
199 199 // os specific they are initialized in os::init_system_properties_values().
200 200 _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL, true);
201 201 _java_library_path = new SystemProperty("java.library.path", NULL, true);
202 202 _java_home = new SystemProperty("java.home", NULL, true);
203 203 _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL, true);
204 204
205 205 _java_class_path = new SystemProperty("java.class.path", "", true);
206 206
207 207 // Add to System Property list.
208 208 PropertyList_add(&_system_properties, _sun_boot_library_path);
209 209 PropertyList_add(&_system_properties, _java_library_path);
210 210 PropertyList_add(&_system_properties, _java_home);
211 211 PropertyList_add(&_system_properties, _java_class_path);
212 212 PropertyList_add(&_system_properties, _sun_boot_class_path);
213 213
214 214 // Set OS specific system properties values
215 215 os::init_system_properties_values();
216 216 }
217 217
218 218
219 219 // Update/Initialize System properties after JDK version number is known
220 220 void Arguments::init_version_specific_system_properties() {
221 221 enum { bufsz = 16 };
222 222 char buffer[bufsz];
223 223 const char* spec_vendor = "Sun Microsystems Inc.";
224 224 uint32_t spec_version = 0;
225 225
226 226 spec_vendor = "Oracle Corporation";
227 227 spec_version = JDK_Version::current().major_version();
228 228 jio_snprintf(buffer, bufsz, "1." UINT32_FORMAT, spec_version);
229 229
230 230 PropertyList_add(&_system_properties,
231 231 new SystemProperty("java.vm.specification.vendor", spec_vendor, false));
232 232 PropertyList_add(&_system_properties,
233 233 new SystemProperty("java.vm.specification.version", buffer, false));
234 234 PropertyList_add(&_system_properties,
235 235 new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(), false));
236 236 }
237 237
238 238 /**
239 239 * Provide a slightly more user-friendly way of eliminating -XX flags.
240 240 * When a flag is eliminated, it can be added to this list in order to
241 241 * continue accepting this flag on the command-line, while issuing a warning
242 242 * and ignoring the value. Once the JDK version reaches the 'accept_until'
243 243 * limit, we flatly refuse to admit the existence of the flag. This allows
244 244 * a flag to die correctly over JDK releases using HSX.
245 245 * But now that HSX is no longer supported only options with a future
246 246 * accept_until value need to be listed, and the list can be pruned
247 247 * on each major release.
248 248 */
249 249 typedef struct {
250 250 const char* name;
251 251 JDK_Version obsoleted_in; // when the flag went away
252 252 JDK_Version accept_until; // which version to start denying the existence
253 253 } ObsoleteFlag;
254 254
255 255 static ObsoleteFlag obsolete_jvm_flags[] = {
256 256 { "UseOldInlining", JDK_Version::jdk(9), JDK_Version::jdk(10) },
257 257 { "SafepointPollOffset", JDK_Version::jdk(9), JDK_Version::jdk(10) },
258 258 { "UseBoundThreads", JDK_Version::jdk(9), JDK_Version::jdk(10) },
259 259 { "DefaultThreadPriority", JDK_Version::jdk(9), JDK_Version::jdk(10) },
260 260 { "NoYieldsInMicrolock", JDK_Version::jdk(9), JDK_Version::jdk(10) },
261 261 { "BackEdgeThreshold", JDK_Version::jdk(9), JDK_Version::jdk(10) },
262 262 { "UseNewReflection", JDK_Version::jdk(9), JDK_Version::jdk(10) },
263 263 { "ReflectionWrapResolutionErrors",JDK_Version::jdk(9), JDK_Version::jdk(10) },
264 264 { "VerifyReflectionBytecodes", JDK_Version::jdk(9), JDK_Version::jdk(10) },
265 265 { "AutoShutdownNMT", JDK_Version::jdk(9), JDK_Version::jdk(10) },
266 266 { "NmethodSweepFraction", JDK_Version::jdk(9), JDK_Version::jdk(10) },
267 267 { "NmethodSweepCheckInterval", JDK_Version::jdk(9), JDK_Version::jdk(10) },
268 268 { "CodeCacheMinimumFreeSpace", JDK_Version::jdk(9), JDK_Version::jdk(10) },
269 269 #ifndef ZERO
270 270 { "UseFastAccessorMethods", JDK_Version::jdk(9), JDK_Version::jdk(10) },
271 271 { "UseFastEmptyMethods", JDK_Version::jdk(9), JDK_Version::jdk(10) },
272 272 #endif // ZERO
273 273 { "UseCompilerSafepoints", JDK_Version::jdk(9), JDK_Version::jdk(10) },
274 274 { "AdaptiveSizePausePolicy", JDK_Version::jdk(9), JDK_Version::jdk(10) },
275 275 { "ParallelGCRetainPLAB", JDK_Version::jdk(9), JDK_Version::jdk(10) },
276 276 { NULL, JDK_Version(0), JDK_Version(0) }
277 277 };
278 278
279 279 // Returns true if the flag is obsolete and fits into the range specified
280 280 // for being ignored. In the case that the flag is ignored, the 'version'
281 281 // value is filled in with the version number when the flag became
282 282 // obsolete so that that value can be displayed to the user.
283 283 bool Arguments::is_newly_obsolete(const char *s, JDK_Version* version) {
284 284 int i = 0;
285 285 assert(version != NULL, "Must provide a version buffer");
286 286 while (obsolete_jvm_flags[i].name != NULL) {
287 287 const ObsoleteFlag& flag_status = obsolete_jvm_flags[i];
288 288 // <flag>=xxx form
289 289 // [-|+]<flag> form
290 290 size_t len = strlen(flag_status.name);
291 291 if ((strncmp(flag_status.name, s, len) == 0) &&
292 292 (strlen(s) == len)){
293 293 if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
294 294 *version = flag_status.obsoleted_in;
295 295 return true;
296 296 }
297 297 }
298 298 i++;
299 299 }
300 300 return false;
301 301 }
302 302
303 303 // Constructs the system class path (aka boot class path) from the following
304 304 // components, in order:
305 305 //
306 306 // prefix // from -Xbootclasspath/p:...
307 307 // base // from os::get_system_properties() or -Xbootclasspath=
308 308 // suffix // from -Xbootclasspath/a:...
309 309 //
310 310 // This could be AllStatic, but it isn't needed after argument processing is
311 311 // complete.
312 312 class SysClassPath: public StackObj {
313 313 public:
314 314 SysClassPath(const char* base);
315 315 ~SysClassPath();
316 316
317 317 inline void set_base(const char* base);
318 318 inline void add_prefix(const char* prefix);
319 319 inline void add_suffix_to_prefix(const char* suffix);
320 320 inline void add_suffix(const char* suffix);
321 321 inline void reset_path(const char* base);
322 322
323 323 inline const char* get_base() const { return _items[_scp_base]; }
324 324 inline const char* get_prefix() const { return _items[_scp_prefix]; }
325 325 inline const char* get_suffix() const { return _items[_scp_suffix]; }
326 326
327 327 // Combine all the components into a single c-heap-allocated string; caller
328 328 // must free the string if/when no longer needed.
329 329 char* combined_path();
330 330
331 331 private:
332 332 // Utility routines.
333 333 static char* add_to_path(const char* path, const char* str, bool prepend);
334 334 static char* add_jars_to_path(char* path, const char* directory);
335 335
336 336 inline void reset_item_at(int index);
337 337
338 338 // Array indices for the items that make up the sysclasspath. All except the
339 339 // base are allocated in the C heap and freed by this class.
340 340 enum {
341 341 _scp_prefix, // from -Xbootclasspath/p:...
342 342 _scp_base, // the default sysclasspath
343 343 _scp_suffix, // from -Xbootclasspath/a:...
344 344 _scp_nitems // the number of items, must be last.
345 345 };
346 346
347 347 const char* _items[_scp_nitems];
348 348 };
349 349
350 350 SysClassPath::SysClassPath(const char* base) {
351 351 memset(_items, 0, sizeof(_items));
352 352 _items[_scp_base] = base;
353 353 }
354 354
355 355 SysClassPath::~SysClassPath() {
356 356 // Free everything except the base.
357 357 for (int i = 0; i < _scp_nitems; ++i) {
358 358 if (i != _scp_base) reset_item_at(i);
359 359 }
360 360 }
361 361
362 362 inline void SysClassPath::set_base(const char* base) {
363 363 _items[_scp_base] = base;
364 364 }
365 365
366 366 inline void SysClassPath::add_prefix(const char* prefix) {
367 367 _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true);
368 368 }
369 369
370 370 inline void SysClassPath::add_suffix_to_prefix(const char* suffix) {
371 371 _items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false);
372 372 }
373 373
374 374 inline void SysClassPath::add_suffix(const char* suffix) {
375 375 _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false);
376 376 }
377 377
378 378 inline void SysClassPath::reset_item_at(int index) {
379 379 assert(index < _scp_nitems && index != _scp_base, "just checking");
380 380 if (_items[index] != NULL) {
381 381 FREE_C_HEAP_ARRAY(char, _items[index]);
382 382 _items[index] = NULL;
383 383 }
384 384 }
385 385
386 386 inline void SysClassPath::reset_path(const char* base) {
387 387 // Clear the prefix and suffix.
388 388 reset_item_at(_scp_prefix);
389 389 reset_item_at(_scp_suffix);
390 390 set_base(base);
391 391 }
392 392
393 393 //------------------------------------------------------------------------------
394 394
395 395
396 396 // Combine the bootclasspath elements, some of which may be null, into a single
397 397 // c-heap-allocated string.
398 398 char* SysClassPath::combined_path() {
399 399 assert(_items[_scp_base] != NULL, "empty default sysclasspath");
400 400
401 401 size_t lengths[_scp_nitems];
402 402 size_t total_len = 0;
403 403
404 404 const char separator = *os::path_separator();
405 405
406 406 // Get the lengths.
407 407 int i;
408 408 for (i = 0; i < _scp_nitems; ++i) {
409 409 if (_items[i] != NULL) {
410 410 lengths[i] = strlen(_items[i]);
411 411 // Include space for the separator char (or a NULL for the last item).
412 412 total_len += lengths[i] + 1;
413 413 }
414 414 }
415 415 assert(total_len > 0, "empty sysclasspath not allowed");
416 416
417 417 // Copy the _items to a single string.
418 418 char* cp = NEW_C_HEAP_ARRAY(char, total_len, mtInternal);
419 419 char* cp_tmp = cp;
420 420 for (i = 0; i < _scp_nitems; ++i) {
421 421 if (_items[i] != NULL) {
422 422 memcpy(cp_tmp, _items[i], lengths[i]);
423 423 cp_tmp += lengths[i];
424 424 *cp_tmp++ = separator;
425 425 }
426 426 }
427 427 *--cp_tmp = '\0'; // Replace the extra separator.
428 428 return cp;
429 429 }
430 430
431 431 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
432 432 char*
433 433 SysClassPath::add_to_path(const char* path, const char* str, bool prepend) {
434 434 char *cp;
435 435
436 436 assert(str != NULL, "just checking");
437 437 if (path == NULL) {
438 438 size_t len = strlen(str) + 1;
439 439 cp = NEW_C_HEAP_ARRAY(char, len, mtInternal);
440 440 memcpy(cp, str, len); // copy the trailing null
441 441 } else {
442 442 const char separator = *os::path_separator();
443 443 size_t old_len = strlen(path);
444 444 size_t str_len = strlen(str);
445 445 size_t len = old_len + str_len + 2;
446 446
447 447 if (prepend) {
448 448 cp = NEW_C_HEAP_ARRAY(char, len, mtInternal);
449 449 char* cp_tmp = cp;
450 450 memcpy(cp_tmp, str, str_len);
451 451 cp_tmp += str_len;
452 452 *cp_tmp = separator;
453 453 memcpy(++cp_tmp, path, old_len + 1); // copy the trailing null
454 454 FREE_C_HEAP_ARRAY(char, path);
455 455 } else {
456 456 cp = REALLOC_C_HEAP_ARRAY(char, path, len, mtInternal);
457 457 char* cp_tmp = cp + old_len;
458 458 *cp_tmp = separator;
459 459 memcpy(++cp_tmp, str, str_len + 1); // copy the trailing null
460 460 }
461 461 }
462 462 return cp;
463 463 }
464 464
465 465 // Scan the directory and append any jar or zip files found to path.
466 466 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
467 467 char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
468 468 DIR* dir = os::opendir(directory);
469 469 if (dir == NULL) return path;
470 470
471 471 char dir_sep[2] = { '\0', '\0' };
472 472 size_t directory_len = strlen(directory);
473 473 const char fileSep = *os::file_separator();
474 474 if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep;
475 475
476 476 /* Scan the directory for jars/zips, appending them to path. */
477 477 struct dirent *entry;
478 478 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal);
479 479 while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
480 480 const char* name = entry->d_name;
481 481 const char* ext = name + strlen(name) - 4;
482 482 bool isJarOrZip = ext > name &&
483 483 (os::file_name_strcmp(ext, ".jar") == 0 ||
484 484 os::file_name_strcmp(ext, ".zip") == 0);
485 485 if (isJarOrZip) {
486 486 char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name), mtInternal);
487 487 sprintf(jarpath, "%s%s%s", directory, dir_sep, name);
488 488 path = add_to_path(path, jarpath, false);
489 489 FREE_C_HEAP_ARRAY(char, jarpath);
490 490 }
491 491 }
492 492 FREE_C_HEAP_ARRAY(char, dbuf);
493 493 os::closedir(dir);
494 494 return path;
495 495 }
496 496
497 497 // Parses a memory size specification string.
498 498 static bool atomull(const char *s, julong* result) {
499 499 julong n = 0;
500 500 int args_read = 0;
501 501 bool is_hex = false;
502 502 // Skip leading 0[xX] for hexadecimal
503 503 if (*s =='0' && (*(s+1) == 'x' || *(s+1) == 'X')) {
504 504 s += 2;
505 505 is_hex = true;
506 506 args_read = sscanf(s, JULONG_FORMAT_X, &n);
507 507 } else {
508 508 args_read = sscanf(s, JULONG_FORMAT, &n);
509 509 }
510 510 if (args_read != 1) {
511 511 return false;
512 512 }
513 513 while (*s != '\0' && (isdigit(*s) || (is_hex && isxdigit(*s)))) {
514 514 s++;
515 515 }
516 516 // 4705540: illegal if more characters are found after the first non-digit
517 517 if (strlen(s) > 1) {
518 518 return false;
519 519 }
520 520 switch (*s) {
521 521 case 'T': case 't':
522 522 *result = n * G * K;
523 523 // Check for overflow.
524 524 if (*result/((julong)G * K) != n) return false;
525 525 return true;
526 526 case 'G': case 'g':
527 527 *result = n * G;
528 528 if (*result/G != n) return false;
529 529 return true;
530 530 case 'M': case 'm':
531 531 *result = n * M;
532 532 if (*result/M != n) return false;
533 533 return true;
534 534 case 'K': case 'k':
535 535 *result = n * K;
536 536 if (*result/K != n) return false;
537 537 return true;
538 538 case '\0':
539 539 *result = n;
540 540 return true;
541 541 default:
542 542 return false;
543 543 }
544 544 }
545 545
546 546 Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size) {
547 547 if (size < min_size) return arg_too_small;
548 548 // Check that size will fit in a size_t (only relevant on 32-bit)
549 549 if (size > max_uintx) return arg_too_big;
550 550 return arg_in_range;
551 551 }
552 552
553 553 // Describe an argument out of range error
554 554 void Arguments::describe_range_error(ArgsRange errcode) {
555 555 switch(errcode) {
556 556 case arg_too_big:
557 557 jio_fprintf(defaultStream::error_stream(),
558 558 "The specified size exceeds the maximum "
559 559 "representable size.\n");
560 560 break;
561 561 case arg_too_small:
562 562 case arg_unreadable:
563 563 case arg_in_range:
564 564 // do nothing for now
565 565 break;
566 566 default:
567 567 ShouldNotReachHere();
568 568 }
569 569 }
570 570
571 571 static bool set_bool_flag(char* name, bool value, Flag::Flags origin) {
572 572 return CommandLineFlags::boolAtPut(name, &value, origin);
573 573 }
574 574
575 575 static bool set_fp_numeric_flag(char* name, char* value, Flag::Flags origin) {
576 576 double v;
577 577 if (sscanf(value, "%lf", &v) != 1) {
578 578 return false;
579 579 }
580 580
581 581 if (CommandLineFlags::doubleAtPut(name, &v, origin)) {
582 582 return true;
583 583 }
584 584 return false;
585 585 }
586 586
587 587 static bool set_numeric_flag(char* name, char* value, Flag::Flags origin) {
588 588 julong v;
589 589 int int_v;
590 590 intx intx_v;
591 591 bool is_neg = false;
592 592 // Check the sign first since atomull() parses only unsigned values.
593 593 if (*value == '-') {
594 594 if (!CommandLineFlags::intxAt(name, &intx_v) && !CommandLineFlags::intAt(name, &int_v)) {
595 595 return false;
596 596 }
597 597 value++;
598 598 is_neg = true;
599 599 }
600 600 if (!atomull(value, &v)) {
601 601 return false;
602 602 }
603 603 int_v = (int) v;
604 604 if (is_neg) {
605 605 int_v = -int_v;
606 606 }
607 607 if (CommandLineFlags::intAtPut(name, &int_v, origin)) {
608 608 return true;
609 609 }
610 610 uint uint_v = (uint) v;
611 611 if (!is_neg && CommandLineFlags::uintAtPut(name, &uint_v, origin)) {
612 612 return true;
613 613 }
614 614 intx_v = (intx) v;
615 615 if (is_neg) {
616 616 intx_v = -intx_v;
617 617 }
618 618 if (CommandLineFlags::intxAtPut(name, &intx_v, origin)) {
619 619 return true;
620 620 }
621 621 uintx uintx_v = (uintx) v;
622 622 if (!is_neg && CommandLineFlags::uintxAtPut(name, &uintx_v, origin)) {
623 623 return true;
624 624 }
625 625 uint64_t uint64_t_v = (uint64_t) v;
626 626 if (!is_neg && CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin)) {
627 627 return true;
628 628 }
629 629 size_t size_t_v = (size_t) v;
630 630 if (!is_neg && CommandLineFlags::size_tAtPut(name, &size_t_v, origin)) {
631 631 return true;
632 632 }
633 633 return false;
634 634 }
635 635
636 636 static bool set_string_flag(char* name, const char* value, Flag::Flags origin) {
637 637 if (!CommandLineFlags::ccstrAtPut(name, &value, origin)) return false;
638 638 // Contract: CommandLineFlags always returns a pointer that needs freeing.
639 639 FREE_C_HEAP_ARRAY(char, value);
640 640 return true;
641 641 }
642 642
643 643 static bool append_to_string_flag(char* name, const char* new_value, Flag::Flags origin) {
644 644 const char* old_value = "";
645 645 if (!CommandLineFlags::ccstrAt(name, &old_value)) return false;
646 646 size_t old_len = old_value != NULL ? strlen(old_value) : 0;
647 647 size_t new_len = strlen(new_value);
648 648 const char* value;
649 649 char* free_this_too = NULL;
650 650 if (old_len == 0) {
651 651 value = new_value;
652 652 } else if (new_len == 0) {
653 653 value = old_value;
654 654 } else {
655 655 char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1, mtInternal);
656 656 // each new setting adds another LINE to the switch:
657 657 sprintf(buf, "%s\n%s", old_value, new_value);
658 658 value = buf;
659 659 free_this_too = buf;
660 660 }
661 661 (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
662 662 // CommandLineFlags always returns a pointer that needs freeing.
663 663 FREE_C_HEAP_ARRAY(char, value);
664 664 if (free_this_too != NULL) {
665 665 // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
666 666 FREE_C_HEAP_ARRAY(char, free_this_too);
667 667 }
668 668 return true;
669 669 }
670 670
671 671 bool Arguments::parse_argument(const char* arg, Flag::Flags origin) {
672 672
673 673 // range of acceptable characters spelled out for portability reasons
674 674 #define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
675 675 #define BUFLEN 255
676 676 char name[BUFLEN+1];
677 677 char dummy;
678 678
679 679 if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
680 680 return set_bool_flag(name, false, origin);
681 681 }
682 682 if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
683 683 return set_bool_flag(name, true, origin);
684 684 }
685 685
686 686 char punct;
687 687 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
688 688 const char* value = strchr(arg, '=') + 1;
689 689 Flag* flag = Flag::find_flag(name, strlen(name));
690 690 if (flag != NULL && flag->is_ccstr()) {
691 691 if (flag->ccstr_accumulates()) {
692 692 return append_to_string_flag(name, value, origin);
693 693 } else {
694 694 if (value[0] == '\0') {
695 695 value = NULL;
696 696 }
697 697 return set_string_flag(name, value, origin);
698 698 }
699 699 }
700 700 }
701 701
702 702 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') {
703 703 const char* value = strchr(arg, '=') + 1;
704 704 // -XX:Foo:=xxx will reset the string flag to the given value.
705 705 if (value[0] == '\0') {
706 706 value = NULL;
707 707 }
708 708 return set_string_flag(name, value, origin);
709 709 }
710 710
711 711 #define SIGNED_FP_NUMBER_RANGE "[-0123456789.]"
712 712 #define SIGNED_NUMBER_RANGE "[-0123456789]"
713 713 #define NUMBER_RANGE "[0123456789]"
714 714 char value[BUFLEN + 1];
715 715 char value2[BUFLEN + 1];
716 716 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) {
717 717 // Looks like a floating-point number -- try again with more lenient format string
718 718 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) {
719 719 return set_fp_numeric_flag(name, value, origin);
720 720 }
721 721 }
722 722
723 723 #define VALUE_RANGE "[-kmgtxKMGTX0123456789abcdefABCDEF]"
724 724 if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
725 725 return set_numeric_flag(name, value, origin);
726 726 }
727 727
728 728 return false;
729 729 }
730 730
731 731 void Arguments::add_string(char*** bldarray, int* count, const char* arg) {
732 732 assert(bldarray != NULL, "illegal argument");
733 733
734 734 if (arg == NULL) {
735 735 return;
736 736 }
737 737
738 738 int new_count = *count + 1;
739 739
740 740 // expand the array and add arg to the last element
741 741 if (*bldarray == NULL) {
742 742 *bldarray = NEW_C_HEAP_ARRAY(char*, new_count, mtInternal);
743 743 } else {
744 744 *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, new_count, mtInternal);
745 745 }
746 746 (*bldarray)[*count] = os::strdup_check_oom(arg);
747 747 *count = new_count;
748 748 }
749 749
750 750 void Arguments::build_jvm_args(const char* arg) {
751 751 add_string(&_jvm_args_array, &_num_jvm_args, arg);
752 752 }
753 753
754 754 void Arguments::build_jvm_flags(const char* arg) {
755 755 add_string(&_jvm_flags_array, &_num_jvm_flags, arg);
756 756 }
757 757
758 758 // utility function to return a string that concatenates all
759 759 // strings in a given char** array
760 760 const char* Arguments::build_resource_string(char** args, int count) {
761 761 if (args == NULL || count == 0) {
762 762 return NULL;
763 763 }
764 764 size_t length = strlen(args[0]) + 1; // add 1 for the null terminator
765 765 for (int i = 1; i < count; i++) {
766 766 length += strlen(args[i]) + 1; // add 1 for a space
767 767 }
768 768 char* s = NEW_RESOURCE_ARRAY(char, length);
769 769 strcpy(s, args[0]);
770 770 for (int j = 1; j < count; j++) {
771 771 strcat(s, " ");
772 772 strcat(s, args[j]);
773 773 }
774 774 return (const char*) s;
775 775 }
776 776
777 777 void Arguments::print_on(outputStream* st) {
778 778 st->print_cr("VM Arguments:");
779 779 if (num_jvm_flags() > 0) {
780 780 st->print("jvm_flags: "); print_jvm_flags_on(st);
781 781 }
782 782 if (num_jvm_args() > 0) {
783 783 st->print("jvm_args: "); print_jvm_args_on(st);
784 784 }
785 785 st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>");
786 786 if (_java_class_path != NULL) {
787 787 char* path = _java_class_path->value();
788 788 st->print_cr("java_class_path (initial): %s", strlen(path) == 0 ? "<not set>" : path );
789 789 }
790 790 st->print_cr("Launcher Type: %s", _sun_java_launcher);
791 791 }
792 792
793 793 void Arguments::print_jvm_flags_on(outputStream* st) {
794 794 if (_num_jvm_flags > 0) {
795 795 for (int i=0; i < _num_jvm_flags; i++) {
796 796 st->print("%s ", _jvm_flags_array[i]);
797 797 }
798 798 st->cr();
799 799 }
800 800 }
801 801
802 802 void Arguments::print_jvm_args_on(outputStream* st) {
803 803 if (_num_jvm_args > 0) {
804 804 for (int i=0; i < _num_jvm_args; i++) {
805 805 st->print("%s ", _jvm_args_array[i]);
806 806 }
807 807 st->cr();
808 808 }
809 809 }
810 810
811 811 bool Arguments::process_argument(const char* arg,
812 812 jboolean ignore_unrecognized, Flag::Flags origin) {
813 813
814 814 JDK_Version since = JDK_Version();
815 815
816 816 if (parse_argument(arg, origin) || ignore_unrecognized) {
817 817 return true;
818 818 }
819 819
820 820 // Determine if the flag has '+', '-', or '=' characters.
821 821 bool has_plus_minus = (*arg == '+' || *arg == '-');
822 822 const char* const argname = has_plus_minus ? arg + 1 : arg;
823 823
824 824 size_t arg_len;
825 825 const char* equal_sign = strchr(argname, '=');
826 826 if (equal_sign == NULL) {
827 827 arg_len = strlen(argname);
828 828 } else {
829 829 arg_len = equal_sign - argname;
830 830 }
831 831
832 832 // Construct a string which consists only of the argument name without '+', '-', or '='.
833 833 char stripped_argname[256];
834 834 strncpy(stripped_argname, argname, arg_len);
835 835 stripped_argname[arg_len] = '\0'; //strncpy doesn't null terminate.
836 836
837 837 if (is_newly_obsolete(stripped_argname, &since)) {
838 838 char version[256];
839 839 since.to_string(version, sizeof(version));
840 840 warning("ignoring option %s; support was removed in %s", stripped_argname, version);
841 841 return true;
842 842 }
843 843
844 844 // For locked flags, report a custom error message if available.
845 845 // Otherwise, report the standard unrecognized VM option.
846 846 Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true, true);
847 847 if (found_flag != NULL) {
848 848 char locked_message_buf[BUFLEN];
849 849 found_flag->get_locked_message(locked_message_buf, BUFLEN);
850 850 if (strlen(locked_message_buf) == 0) {
851 851 if (found_flag->is_bool() && !has_plus_minus) {
852 852 jio_fprintf(defaultStream::error_stream(),
853 853 "Missing +/- setting for VM option '%s'\n", argname);
854 854 } else if (!found_flag->is_bool() && has_plus_minus) {
855 855 jio_fprintf(defaultStream::error_stream(),
856 856 "Unexpected +/- setting in VM option '%s'\n", argname);
857 857 } else {
858 858 jio_fprintf(defaultStream::error_stream(),
859 859 "Improperly specified VM option '%s'\n", argname);
860 860 }
861 861 } else {
862 862 jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
863 863 }
864 864 } else {
865 865 jio_fprintf(defaultStream::error_stream(),
866 866 "Unrecognized VM option '%s'\n", argname);
867 867 Flag* fuzzy_matched = Flag::fuzzy_match((const char*)argname, arg_len, true);
868 868 if (fuzzy_matched != NULL) {
869 869 jio_fprintf(defaultStream::error_stream(),
870 870 "Did you mean '%s%s%s'? ",
871 871 (fuzzy_matched->is_bool()) ? "(+/-)" : "",
872 872 fuzzy_matched->_name,
873 873 (fuzzy_matched->is_bool()) ? "" : "=<value>");
874 874 }
875 875 }
876 876
877 877 // allow for commandline "commenting out" options like -XX:#+Verbose
878 878 return arg[0] == '#';
879 879 }
880 880
881 881 bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
882 882 FILE* stream = fopen(file_name, "rb");
883 883 if (stream == NULL) {
884 884 if (should_exist) {
885 885 jio_fprintf(defaultStream::error_stream(),
886 886 "Could not open settings file %s\n", file_name);
887 887 return false;
888 888 } else {
889 889 return true;
890 890 }
891 891 }
892 892
893 893 char token[1024];
894 894 int pos = 0;
895 895
896 896 bool in_white_space = true;
897 897 bool in_comment = false;
898 898 bool in_quote = false;
899 899 char quote_c = 0;
900 900 bool result = true;
901 901
902 902 int c = getc(stream);
903 903 while(c != EOF && pos < (int)(sizeof(token)-1)) {
904 904 if (in_white_space) {
905 905 if (in_comment) {
906 906 if (c == '\n') in_comment = false;
907 907 } else {
908 908 if (c == '#') in_comment = true;
909 909 else if (!isspace(c)) {
910 910 in_white_space = false;
911 911 token[pos++] = c;
912 912 }
913 913 }
914 914 } else {
915 915 if (c == '\n' || (!in_quote && isspace(c))) {
916 916 // token ends at newline, or at unquoted whitespace
917 917 // this allows a way to include spaces in string-valued options
918 918 token[pos] = '\0';
919 919 logOption(token);
920 920 result &= process_argument(token, ignore_unrecognized, Flag::CONFIG_FILE);
921 921 build_jvm_flags(token);
922 922 pos = 0;
923 923 in_white_space = true;
924 924 in_quote = false;
925 925 } else if (!in_quote && (c == '\'' || c == '"')) {
926 926 in_quote = true;
927 927 quote_c = c;
928 928 } else if (in_quote && (c == quote_c)) {
929 929 in_quote = false;
930 930 } else {
931 931 token[pos++] = c;
932 932 }
933 933 }
934 934 c = getc(stream);
935 935 }
936 936 if (pos > 0) {
937 937 token[pos] = '\0';
938 938 result &= process_argument(token, ignore_unrecognized, Flag::CONFIG_FILE);
939 939 build_jvm_flags(token);
940 940 }
941 941 fclose(stream);
942 942 return result;
943 943 }
944 944
945 945 //=============================================================================================================
946 946 // Parsing of properties (-D)
947 947
948 948 const char* Arguments::get_property(const char* key) {
949 949 return PropertyList_get_value(system_properties(), key);
950 950 }
951 951
952 952 bool Arguments::add_property(const char* prop) {
953 953 const char* eq = strchr(prop, '=');
954 954 char* key;
955 955 // ns must be static--its address may be stored in a SystemProperty object.
956 956 const static char ns[1] = {0};
957 957 char* value = (char *)ns;
958 958
959 959 size_t key_len = (eq == NULL) ? strlen(prop) : (eq - prop);
960 960 key = AllocateHeap(key_len + 1, mtInternal);
961 961 strncpy(key, prop, key_len);
962 962 key[key_len] = '\0';
963 963
964 964 if (eq != NULL) {
965 965 size_t value_len = strlen(prop) - key_len - 1;
966 966 value = AllocateHeap(value_len + 1, mtInternal);
967 967 strncpy(value, &prop[key_len + 1], value_len + 1);
968 968 }
969 969
970 970 if (strcmp(key, "java.compiler") == 0) {
971 971 process_java_compiler_argument(value);
972 972 FreeHeap(key);
973 973 if (eq != NULL) {
974 974 FreeHeap(value);
975 975 }
976 976 return true;
977 977 } else if (strcmp(key, "sun.java.command") == 0) {
978 978 _java_command = value;
979 979
980 980 // Record value in Arguments, but let it get passed to Java.
981 981 } else if (strcmp(key, "sun.java.launcher.is_altjvm") == 0 ||
982 982 strcmp(key, "sun.java.launcher.pid") == 0) {
983 983 // sun.java.launcher.is_altjvm and sun.java.launcher.pid property are
984 984 // private and are processed in process_sun_java_launcher_properties();
985 985 // the sun.java.launcher property is passed on to the java application
986 986 FreeHeap(key);
987 987 if (eq != NULL) {
988 988 FreeHeap(value);
989 989 }
990 990 return true;
991 991 } else if (strcmp(key, "java.vendor.url.bug") == 0) {
992 992 // save it in _java_vendor_url_bug, so JVM fatal error handler can access
993 993 // its value without going through the property list or making a Java call.
994 994 _java_vendor_url_bug = value;
995 995 } else if (strcmp(key, "sun.boot.library.path") == 0) {
996 996 PropertyList_unique_add(&_system_properties, key, value, true);
997 997 return true;
998 998 }
999 999 // Create new property and add at the end of the list
1000 1000 PropertyList_unique_add(&_system_properties, key, value);
1001 1001 return true;
1002 1002 }
1003 1003
1004 1004 //===========================================================================================================
1005 1005 // Setting int/mixed/comp mode flags
1006 1006
1007 1007 void Arguments::set_mode_flags(Mode mode) {
1008 1008 // Set up default values for all flags.
1009 1009 // If you add a flag to any of the branches below,
1010 1010 // add a default value for it here.
1011 1011 set_java_compiler(false);
1012 1012 _mode = mode;
1013 1013
1014 1014 // Ensure Agent_OnLoad has the correct initial values.
1015 1015 // This may not be the final mode; mode may change later in onload phase.
1016 1016 PropertyList_unique_add(&_system_properties, "java.vm.info",
1017 1017 (char*)VM_Version::vm_info_string(), false);
1018 1018
1019 1019 UseInterpreter = true;
1020 1020 UseCompiler = true;
1021 1021 UseLoopCounter = true;
1022 1022
1023 1023 // Default values may be platform/compiler dependent -
1024 1024 // use the saved values
1025 1025 ClipInlining = Arguments::_ClipInlining;
1026 1026 AlwaysCompileLoopMethods = Arguments::_AlwaysCompileLoopMethods;
1027 1027 UseOnStackReplacement = Arguments::_UseOnStackReplacement;
1028 1028 BackgroundCompilation = Arguments::_BackgroundCompilation;
1029 1029 if (TieredCompilation) {
1030 1030 if (FLAG_IS_DEFAULT(Tier3InvokeNotifyFreqLog)) {
1031 1031 Tier3InvokeNotifyFreqLog = Arguments::_Tier3InvokeNotifyFreqLog;
1032 1032 }
1033 1033 if (FLAG_IS_DEFAULT(Tier4InvocationThreshold)) {
1034 1034 Tier4InvocationThreshold = Arguments::_Tier4InvocationThreshold;
1035 1035 }
1036 1036 }
1037 1037
1038 1038 // Change from defaults based on mode
1039 1039 switch (mode) {
1040 1040 default:
1041 1041 ShouldNotReachHere();
1042 1042 break;
1043 1043 case _int:
1044 1044 UseCompiler = false;
1045 1045 UseLoopCounter = false;
1046 1046 AlwaysCompileLoopMethods = false;
1047 1047 UseOnStackReplacement = false;
1048 1048 break;
1049 1049 case _mixed:
1050 1050 // same as default
1051 1051 break;
1052 1052 case _comp:
1053 1053 UseInterpreter = false;
1054 1054 BackgroundCompilation = false;
1055 1055 ClipInlining = false;
1056 1056 // Be much more aggressive in tiered mode with -Xcomp and exercise C2 more.
1057 1057 // We will first compile a level 3 version (C1 with full profiling), then do one invocation of it and
1058 1058 // compile a level 4 (C2) and then continue executing it.
1059 1059 if (TieredCompilation) {
1060 1060 Tier3InvokeNotifyFreqLog = 0;
1061 1061 Tier4InvocationThreshold = 0;
1062 1062 }
1063 1063 break;
1064 1064 }
1065 1065 }
1066 1066
1067 1067 #if defined(COMPILER2) || defined(_LP64) || !INCLUDE_CDS
1068 1068 // Conflict: required to use shared spaces (-Xshare:on), but
1069 1069 // incompatible command line options were chosen.
1070 1070
1071 1071 static void no_shared_spaces(const char* message) {
1072 1072 if (RequireSharedSpaces) {
1073 1073 jio_fprintf(defaultStream::error_stream(),
1074 1074 "Class data sharing is inconsistent with other specified options.\n");
1075 1075 vm_exit_during_initialization("Unable to use shared archive.", message);
1076 1076 } else {
1077 1077 FLAG_SET_DEFAULT(UseSharedSpaces, false);
1078 1078 }
1079 1079 }
1080 1080 #endif
1081 1081
1082 1082 // Returns threshold scaled with the value of scale.
1083 1083 // If scale < 0.0, threshold is returned without scaling.
1084 1084 intx Arguments::scaled_compile_threshold(intx threshold, double scale) {
1085 1085 if (scale == 1.0 || scale < 0.0) {
1086 1086 return threshold;
1087 1087 } else {
1088 1088 return (intx)(threshold * scale);
1089 1089 }
1090 1090 }
1091 1091
1092 1092 // Returns freq_log scaled with the value of scale.
1093 1093 // Returned values are in the range of [0, InvocationCounter::number_of_count_bits + 1].
1094 1094 // If scale < 0.0, freq_log is returned without scaling.
1095 1095 intx Arguments::scaled_freq_log(intx freq_log, double scale) {
1096 1096 // Check if scaling is necessary or if negative value was specified.
1097 1097 if (scale == 1.0 || scale < 0.0) {
1098 1098 return freq_log;
1099 1099 }
1100 1100 // Check values to avoid calculating log2 of 0.
1101 1101 if (scale == 0.0 || freq_log == 0) {
1102 1102 return 0;
1103 1103 }
1104 1104 // Determine the maximum notification frequency value currently supported.
1105 1105 // The largest mask value that the interpreter/C1 can handle is
1106 1106 // of length InvocationCounter::number_of_count_bits. Mask values are always
1107 1107 // one bit shorter then the value of the notification frequency. Set
1108 1108 // max_freq_bits accordingly.
1109 1109 intx max_freq_bits = InvocationCounter::number_of_count_bits + 1;
1110 1110 intx scaled_freq = scaled_compile_threshold((intx)1 << freq_log, scale);
1111 1111 if (scaled_freq == 0) {
1112 1112 // Return 0 right away to avoid calculating log2 of 0.
1113 1113 return 0;
1114 1114 } else if (scaled_freq > nth_bit(max_freq_bits)) {
1115 1115 return max_freq_bits;
1116 1116 } else {
1117 1117 return log2_intptr(scaled_freq);
1118 1118 }
1119 1119 }
1120 1120
1121 1121 void Arguments::set_tiered_flags() {
1122 1122 // With tiered, set default policy to AdvancedThresholdPolicy, which is 3.
1123 1123 if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
1124 1124 FLAG_SET_DEFAULT(CompilationPolicyChoice, 3);
1125 1125 }
1126 1126 if (CompilationPolicyChoice < 2) {
1127 1127 vm_exit_during_initialization(
1128 1128 "Incompatible compilation policy selected", NULL);
1129 1129 }
1130 1130 // Increase the code cache size - tiered compiles a lot more.
1131 1131 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
1132 1132 FLAG_SET_ERGO(uintx, ReservedCodeCacheSize,
1133 1133 MIN2(CODE_CACHE_DEFAULT_LIMIT, ReservedCodeCacheSize * 5));
1134 1134 }
1135 1135 // Enable SegmentedCodeCache if TieredCompilation is enabled and ReservedCodeCacheSize >= 240M
1136 1136 if (FLAG_IS_DEFAULT(SegmentedCodeCache) && ReservedCodeCacheSize >= 240*M) {
1137 1137 FLAG_SET_ERGO(bool, SegmentedCodeCache, true);
1138 1138
1139 1139 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
1140 1140 // Multiply sizes by 5 but fix NonNMethodCodeHeapSize (distribute among non-profiled and profiled code heap)
1141 1141 if (FLAG_IS_DEFAULT(ProfiledCodeHeapSize)) {
1142 1142 FLAG_SET_ERGO(uintx, ProfiledCodeHeapSize, ProfiledCodeHeapSize * 5 + NonNMethodCodeHeapSize * 2);
1143 1143 }
1144 1144 if (FLAG_IS_DEFAULT(NonProfiledCodeHeapSize)) {
1145 1145 FLAG_SET_ERGO(uintx, NonProfiledCodeHeapSize, NonProfiledCodeHeapSize * 5 + NonNMethodCodeHeapSize * 2);
1146 1146 }
1147 1147 // Check consistency of code heap sizes
1148 1148 if ((NonNMethodCodeHeapSize + NonProfiledCodeHeapSize + ProfiledCodeHeapSize) != ReservedCodeCacheSize) {
1149 1149 jio_fprintf(defaultStream::error_stream(),
1150 1150 "Invalid code heap sizes: NonNMethodCodeHeapSize(%dK) + ProfiledCodeHeapSize(%dK) + NonProfiledCodeHeapSize(%dK) = %dK. Must be equal to ReservedCodeCacheSize = %uK.\n",
1151 1151 NonNMethodCodeHeapSize/K, ProfiledCodeHeapSize/K, NonProfiledCodeHeapSize/K,
1152 1152 (NonNMethodCodeHeapSize + ProfiledCodeHeapSize + NonProfiledCodeHeapSize)/K, ReservedCodeCacheSize/K);
1153 1153 vm_exit(1);
1154 1154 }
1155 1155 }
1156 1156 }
1157 1157 if (!UseInterpreter) { // -Xcomp
1158 1158 Tier3InvokeNotifyFreqLog = 0;
1159 1159 Tier4InvocationThreshold = 0;
1160 1160 }
1161 1161
1162 1162 if (CompileThresholdScaling < 0) {
1163 1163 vm_exit_during_initialization("Negative value specified for CompileThresholdScaling", NULL);
1164 1164 }
1165 1165
1166 1166 // Scale tiered compilation thresholds.
1167 1167 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves compilation thresholds unchanged.
1168 1168 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) {
1169 1169 FLAG_SET_ERGO(intx, Tier0InvokeNotifyFreqLog, scaled_freq_log(Tier0InvokeNotifyFreqLog));
1170 1170 FLAG_SET_ERGO(intx, Tier0BackedgeNotifyFreqLog, scaled_freq_log(Tier0BackedgeNotifyFreqLog));
1171 1171
1172 1172 FLAG_SET_ERGO(intx, Tier3InvocationThreshold, scaled_compile_threshold(Tier3InvocationThreshold));
1173 1173 FLAG_SET_ERGO(intx, Tier3MinInvocationThreshold, scaled_compile_threshold(Tier3MinInvocationThreshold));
1174 1174 FLAG_SET_ERGO(intx, Tier3CompileThreshold, scaled_compile_threshold(Tier3CompileThreshold));
1175 1175 FLAG_SET_ERGO(intx, Tier3BackEdgeThreshold, scaled_compile_threshold(Tier3BackEdgeThreshold));
1176 1176
1177 1177 // Tier2{Invocation,MinInvocation,Compile,Backedge}Threshold should be scaled here
1178 1178 // once these thresholds become supported.
1179 1179
1180 1180 FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog));
1181 1181 FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog));
1182 1182
1183 1183 FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog));
1184 1184 FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog));
1185 1185
1186 1186 FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog));
1187 1187
1188 1188 FLAG_SET_ERGO(intx, Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold));
1189 1189 FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold));
1190 1190 FLAG_SET_ERGO(intx, Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold));
1191 1191 FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold));
1192 1192 }
1193 1193 }
1194 1194
1195 1195 /**
1196 1196 * Returns the minimum number of compiler threads needed to run the JVM. The following
1197 1197 * configurations are possible.
1198 1198 *
1199 1199 * 1) The JVM is build using an interpreter only. As a result, the minimum number of
1200 1200 * compiler threads is 0.
1201 1201 * 2) The JVM is build using the compiler(s) and tiered compilation is disabled. As
1202 1202 * a result, either C1 or C2 is used, so the minimum number of compiler threads is 1.
1203 1203 * 3) The JVM is build using the compiler(s) and tiered compilation is enabled. However,
1204 1204 * the option "TieredStopAtLevel < CompLevel_full_optimization". As a result, only
1205 1205 * C1 can be used, so the minimum number of compiler threads is 1.
1206 1206 * 4) The JVM is build using the compilers and tiered compilation is enabled. The option
1207 1207 * 'TieredStopAtLevel = CompLevel_full_optimization' (the default value). As a result,
1208 1208 * the minimum number of compiler threads is 2.
1209 1209 */
1210 1210 int Arguments::get_min_number_of_compiler_threads() {
1211 1211 #if !defined(COMPILER1) && !defined(COMPILER2) && !defined(SHARK)
1212 1212 return 0; // case 1
1213 1213 #else
1214 1214 if (!TieredCompilation || (TieredStopAtLevel < CompLevel_full_optimization)) {
1215 1215 return 1; // case 2 or case 3
1216 1216 }
1217 1217 return 2; // case 4 (tiered)
1218 1218 #endif
1219 1219 }
1220 1220
1221 1221 #if INCLUDE_ALL_GCS
1222 1222 static void disable_adaptive_size_policy(const char* collector_name) {
1223 1223 if (UseAdaptiveSizePolicy) {
1224 1224 if (FLAG_IS_CMDLINE(UseAdaptiveSizePolicy)) {
1225 1225 warning("disabling UseAdaptiveSizePolicy; it is incompatible with %s.",
1226 1226 collector_name);
1227 1227 }
1228 1228 FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
1229 1229 }
1230 1230 }
1231 1231
1232 1232 void Arguments::set_parnew_gc_flags() {
1233 1233 assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
1234 1234 "control point invariant");
1235 1235 assert(UseConcMarkSweepGC, "CMS is expected to be on here");
1236 1236 assert(UseParNewGC, "ParNew should always be used with CMS");
1237 1237
1238 1238 if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
1239 1239 FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
1240 1240 assert(ParallelGCThreads > 0, "We should always have at least one thread by default");
1241 1241 } else if (ParallelGCThreads == 0) {
1242 1242 jio_fprintf(defaultStream::error_stream(),
1243 1243 "The ParNew GC can not be combined with -XX:ParallelGCThreads=0\n");
1244 1244 vm_exit(1);
1245 1245 }
1246 1246
1247 1247 // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 respectively,
1248 1248 // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration
1249 1249 // we set them to 1024 and 1024.
1250 1250 // See CR 6362902.
1251 1251 if (FLAG_IS_DEFAULT(YoungPLABSize)) {
1252 1252 FLAG_SET_DEFAULT(YoungPLABSize, (intx)1024);
1253 1253 }
1254 1254 if (FLAG_IS_DEFAULT(OldPLABSize)) {
1255 1255 FLAG_SET_DEFAULT(OldPLABSize, (intx)1024);
1256 1256 }
1257 1257
1258 1258 // When using compressed oops, we use local overflow stacks,
1259 1259 // rather than using a global overflow list chained through
1260 1260 // the klass word of the object's pre-image.
1261 1261 if (UseCompressedOops && !ParGCUseLocalOverflow) {
1262 1262 if (!FLAG_IS_DEFAULT(ParGCUseLocalOverflow)) {
1263 1263 warning("Forcing +ParGCUseLocalOverflow: needed if using compressed references");
1264 1264 }
1265 1265 FLAG_SET_DEFAULT(ParGCUseLocalOverflow, true);
1266 1266 }
1267 1267 assert(ParGCUseLocalOverflow || !UseCompressedOops, "Error");
1268 1268 }
1269 1269
1270 1270 // Adjust some sizes to suit CMS and/or ParNew needs; these work well on
1271 1271 // sparc/solaris for certain applications, but would gain from
1272 1272 // further optimization and tuning efforts, and would almost
1273 1273 // certainly gain from analysis of platform and environment.
1274 1274 void Arguments::set_cms_and_parnew_gc_flags() {
1275 1275 assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error");
1276 1276 assert(UseConcMarkSweepGC, "CMS is expected to be on here");
1277 1277 assert(UseParNewGC, "ParNew should always be used with CMS");
1278 1278
1279 1279 // Turn off AdaptiveSizePolicy by default for cms until it is complete.
1280 1280 disable_adaptive_size_policy("UseConcMarkSweepGC");
1281 1281
1282 1282 set_parnew_gc_flags();
1283 1283
1284 1284 size_t max_heap = align_size_down(MaxHeapSize,
1285 1285 CardTableRS::ct_max_alignment_constraint());
1286 1286
1287 1287 // Now make adjustments for CMS
1288 1288 intx tenuring_default = (intx)6;
1289 1289 size_t young_gen_per_worker = CMSYoungGenPerWorker;
1290 1290
1291 1291 // Preferred young gen size for "short" pauses:
1292 1292 // upper bound depends on # of threads and NewRatio.
1293 1293 const size_t preferred_max_new_size_unaligned =
1294 1294 MIN2(max_heap/(NewRatio+1), ScaleForWordSize(young_gen_per_worker * ParallelGCThreads));
1295 1295 size_t preferred_max_new_size =
1296 1296 align_size_up(preferred_max_new_size_unaligned, os::vm_page_size());
1297 1297
1298 1298 // Unless explicitly requested otherwise, size young gen
1299 1299 // for "short" pauses ~ CMSYoungGenPerWorker*ParallelGCThreads
1300 1300
1301 1301 // If either MaxNewSize or NewRatio is set on the command line,
1302 1302 // assume the user is trying to set the size of the young gen.
1303 1303 if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) {
1304 1304
1305 1305 // Set MaxNewSize to our calculated preferred_max_new_size unless
1306 1306 // NewSize was set on the command line and it is larger than
1307 1307 // preferred_max_new_size.
1308 1308 if (!FLAG_IS_DEFAULT(NewSize)) { // NewSize explicitly set at command-line
1309 1309 FLAG_SET_ERGO(size_t, MaxNewSize, MAX2(NewSize, preferred_max_new_size));
1310 1310 } else {
1311 1311 FLAG_SET_ERGO(size_t, MaxNewSize, preferred_max_new_size);
1312 1312 }
1313 1313 if (PrintGCDetails && Verbose) {
1314 1314 // Too early to use gclog_or_tty
1315 1315 tty->print_cr("CMS ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize);
1316 1316 }
1317 1317
1318 1318 // Code along this path potentially sets NewSize and OldSize
1319 1319 if (PrintGCDetails && Verbose) {
1320 1320 // Too early to use gclog_or_tty
1321 1321 tty->print_cr("CMS set min_heap_size: " SIZE_FORMAT
1322 1322 " initial_heap_size: " SIZE_FORMAT
1323 1323 " max_heap: " SIZE_FORMAT,
1324 1324 min_heap_size(), InitialHeapSize, max_heap);
1325 1325 }
1326 1326 size_t min_new = preferred_max_new_size;
1327 1327 if (FLAG_IS_CMDLINE(NewSize)) {
1328 1328 min_new = NewSize;
1329 1329 }
1330 1330 if (max_heap > min_new && min_heap_size() > min_new) {
1331 1331 // Unless explicitly requested otherwise, make young gen
1332 1332 // at least min_new, and at most preferred_max_new_size.
1333 1333 if (FLAG_IS_DEFAULT(NewSize)) {
1334 1334 FLAG_SET_ERGO(size_t, NewSize, MAX2(NewSize, min_new));
1335 1335 FLAG_SET_ERGO(size_t, NewSize, MIN2(preferred_max_new_size, NewSize));
1336 1336 if (PrintGCDetails && Verbose) {
1337 1337 // Too early to use gclog_or_tty
1338 1338 tty->print_cr("CMS ergo set NewSize: " SIZE_FORMAT, NewSize);
1339 1339 }
1340 1340 }
1341 1341 // Unless explicitly requested otherwise, size old gen
1342 1342 // so it's NewRatio x of NewSize.
1343 1343 if (FLAG_IS_DEFAULT(OldSize)) {
1344 1344 if (max_heap > NewSize) {
1345 1345 FLAG_SET_ERGO(size_t, OldSize, MIN2(NewRatio*NewSize, max_heap - NewSize));
1346 1346 if (PrintGCDetails && Verbose) {
1347 1347 // Too early to use gclog_or_tty
1348 1348 tty->print_cr("CMS ergo set OldSize: " SIZE_FORMAT, OldSize);
1349 1349 }
1350 1350 }
1351 1351 }
1352 1352 }
1353 1353 }
1354 1354 // Unless explicitly requested otherwise, definitely
1355 1355 // promote all objects surviving "tenuring_default" scavenges.
1356 1356 if (FLAG_IS_DEFAULT(MaxTenuringThreshold) &&
1357 1357 FLAG_IS_DEFAULT(SurvivorRatio)) {
1358 1358 FLAG_SET_ERGO(uintx, MaxTenuringThreshold, tenuring_default);
1359 1359 }
1360 1360 // If we decided above (or user explicitly requested)
1361 1361 // `promote all' (via MaxTenuringThreshold := 0),
1362 1362 // prefer minuscule survivor spaces so as not to waste
1363 1363 // space for (non-existent) survivors
1364 1364 if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) {
1365 1365 FLAG_SET_ERGO(uintx, SurvivorRatio, MAX2((uintx)1024, SurvivorRatio));
1366 1366 }
1367 1367
1368 1368 // OldPLABSize is interpreted in CMS as not the size of the PLAB in words,
1369 1369 // but rather the number of free blocks of a given size that are used when
1370 1370 // replenishing the local per-worker free list caches.
1371 1371 if (FLAG_IS_DEFAULT(OldPLABSize)) {
1372 1372 if (!FLAG_IS_DEFAULT(ResizeOldPLAB) && !ResizeOldPLAB) {
1373 1373 // OldPLAB sizing manually turned off: Use a larger default setting,
1374 1374 // unless it was manually specified. This is because a too-low value
1375 1375 // will slow down scavenges.
1376 1376 FLAG_SET_ERGO(size_t, OldPLABSize, CFLS_LAB::_default_static_old_plab_size); // default value before 6631166
1377 1377 } else {
1378 1378 FLAG_SET_DEFAULT(OldPLABSize, CFLS_LAB::_default_dynamic_old_plab_size); // old CMSParPromoteBlocksToClaim default
1379 1379 }
1380 1380 }
1381 1381
1382 1382 // If either of the static initialization defaults have changed, note this
1383 1383 // modification.
1384 1384 if (!FLAG_IS_DEFAULT(OldPLABSize) || !FLAG_IS_DEFAULT(OldPLABWeight)) {
1385 1385 CFLS_LAB::modify_initialization(OldPLABSize, OldPLABWeight);
1386 1386 }
1387 1387 if (PrintGCDetails && Verbose) {
1388 1388 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk",
1389 1389 (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
1390 1390 tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
1391 1391 }
1392 1392 }
1393 1393 #endif // INCLUDE_ALL_GCS
1394 1394
1395 1395 void set_object_alignment() {
1396 1396 // Object alignment.
1397 1397 assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2");
1398 1398 MinObjAlignmentInBytes = ObjectAlignmentInBytes;
1399 1399 assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small");
1400 1400 MinObjAlignment = MinObjAlignmentInBytes / HeapWordSize;
1401 1401 assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect");
1402 1402 MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1;
1403 1403
1404 1404 LogMinObjAlignmentInBytes = exact_log2(ObjectAlignmentInBytes);
1405 1405 LogMinObjAlignment = LogMinObjAlignmentInBytes - LogHeapWordSize;
1406 1406
1407 1407 // Oop encoding heap max
1408 1408 OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes;
1409 1409
1410 1410 #if INCLUDE_ALL_GCS
1411 1411 // Set CMS global values
1412 1412 CompactibleFreeListSpace::set_cms_values();
1413 1413 #endif // INCLUDE_ALL_GCS
1414 1414 }
1415 1415
1416 1416 bool verify_object_alignment() {
1417 1417 // Object alignment.
1418 1418 if (!is_power_of_2(ObjectAlignmentInBytes)) {
1419 1419 jio_fprintf(defaultStream::error_stream(),
1420 1420 "error: ObjectAlignmentInBytes=%d must be power of 2\n",
1421 1421 (int)ObjectAlignmentInBytes);
1422 1422 return false;
1423 1423 }
1424 1424 if ((int)ObjectAlignmentInBytes < BytesPerLong) {
1425 1425 jio_fprintf(defaultStream::error_stream(),
1426 1426 "error: ObjectAlignmentInBytes=%d must be greater or equal %d\n",
1427 1427 (int)ObjectAlignmentInBytes, BytesPerLong);
1428 1428 return false;
1429 1429 }
1430 1430 // It does not make sense to have big object alignment
1431 1431 // since a space lost due to alignment will be greater
1432 1432 // then a saved space from compressed oops.
1433 1433 if ((int)ObjectAlignmentInBytes > 256) {
1434 1434 jio_fprintf(defaultStream::error_stream(),
1435 1435 "error: ObjectAlignmentInBytes=%d must not be greater than 256\n",
1436 1436 (int)ObjectAlignmentInBytes);
1437 1437 return false;
1438 1438 }
1439 1439 // In case page size is very small.
1440 1440 if ((int)ObjectAlignmentInBytes >= os::vm_page_size()) {
1441 1441 jio_fprintf(defaultStream::error_stream(),
1442 1442 "error: ObjectAlignmentInBytes=%d must be less than page size %d\n",
1443 1443 (int)ObjectAlignmentInBytes, os::vm_page_size());
1444 1444 return false;
1445 1445 }
1446 1446 if(SurvivorAlignmentInBytes == 0) {
1447 1447 SurvivorAlignmentInBytes = ObjectAlignmentInBytes;
1448 1448 } else {
1449 1449 if (!is_power_of_2(SurvivorAlignmentInBytes)) {
1450 1450 jio_fprintf(defaultStream::error_stream(),
1451 1451 "error: SurvivorAlignmentInBytes=%d must be power of 2\n",
1452 1452 (int)SurvivorAlignmentInBytes);
1453 1453 return false;
1454 1454 }
1455 1455 if (SurvivorAlignmentInBytes < ObjectAlignmentInBytes) {
1456 1456 jio_fprintf(defaultStream::error_stream(),
1457 1457 "error: SurvivorAlignmentInBytes=%d must be greater than ObjectAlignmentInBytes=%d \n",
1458 1458 (int)SurvivorAlignmentInBytes, (int)ObjectAlignmentInBytes);
1459 1459 return false;
1460 1460 }
1461 1461 }
1462 1462 return true;
1463 1463 }
1464 1464
1465 1465 size_t Arguments::max_heap_for_compressed_oops() {
1466 1466 // Avoid sign flip.
1467 1467 assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size");
1468 1468 // We need to fit both the NULL page and the heap into the memory budget, while
1469 1469 // keeping alignment constraints of the heap. To guarantee the latter, as the
1470 1470 // NULL page is located before the heap, we pad the NULL page to the conservative
1471 1471 // maximum alignment that the GC may ever impose upon the heap.
1472 1472 size_t displacement_due_to_null_page = align_size_up_(os::vm_page_size(),
1473 1473 _conservative_max_heap_alignment);
1474 1474
1475 1475 LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page);
1476 1476 NOT_LP64(ShouldNotReachHere(); return 0);
1477 1477 }
1478 1478
1479 1479 bool Arguments::should_auto_select_low_pause_collector() {
1480 1480 if (UseAutoGCSelectPolicy &&
1481 1481 !FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
1482 1482 (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
1483 1483 if (PrintGCDetails) {
1484 1484 // Cannot use gclog_or_tty yet.
1485 1485 tty->print_cr("Automatic selection of the low pause collector"
1486 1486 " based on pause goal of %d (ms)", (int) MaxGCPauseMillis);
1487 1487 }
1488 1488 return true;
1489 1489 }
1490 1490 return false;
1491 1491 }
1492 1492
1493 1493 void Arguments::set_use_compressed_oops() {
1494 1494 #ifndef ZERO
1495 1495 #ifdef _LP64
1496 1496 // MaxHeapSize is not set up properly at this point, but
1497 1497 // the only value that can override MaxHeapSize if we are
1498 1498 // to use UseCompressedOops is InitialHeapSize.
1499 1499 size_t max_heap_size = MAX2(MaxHeapSize, InitialHeapSize);
1500 1500
1501 1501 if (max_heap_size <= max_heap_for_compressed_oops()) {
1502 1502 #if !defined(COMPILER1) || defined(TIERED)
1503 1503 if (FLAG_IS_DEFAULT(UseCompressedOops)) {
1504 1504 FLAG_SET_ERGO(bool, UseCompressedOops, true);
1505 1505 }
1506 1506 #endif
1507 1507 } else {
1508 1508 if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
1509 1509 warning("Max heap size too large for Compressed Oops");
1510 1510 FLAG_SET_DEFAULT(UseCompressedOops, false);
1511 1511 FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1512 1512 }
1513 1513 }
1514 1514 #endif // _LP64
1515 1515 #endif // ZERO
1516 1516 }
1517 1517
1518 1518
1519 1519 // NOTE: set_use_compressed_klass_ptrs() must be called after calling
1520 1520 // set_use_compressed_oops().
1521 1521 void Arguments::set_use_compressed_klass_ptrs() {
1522 1522 #ifndef ZERO
1523 1523 #ifdef _LP64
1524 1524 // UseCompressedOops must be on for UseCompressedClassPointers to be on.
1525 1525 if (!UseCompressedOops) {
1526 1526 if (UseCompressedClassPointers) {
1527 1527 warning("UseCompressedClassPointers requires UseCompressedOops");
1528 1528 }
1529 1529 FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1530 1530 } else {
1531 1531 // Turn on UseCompressedClassPointers too
1532 1532 if (FLAG_IS_DEFAULT(UseCompressedClassPointers)) {
1533 1533 FLAG_SET_ERGO(bool, UseCompressedClassPointers, true);
1534 1534 }
1535 1535 // Check the CompressedClassSpaceSize to make sure we use compressed klass ptrs.
1536 1536 if (UseCompressedClassPointers) {
1537 1537 if (CompressedClassSpaceSize > KlassEncodingMetaspaceMax) {
1538 1538 warning("CompressedClassSpaceSize is too large for UseCompressedClassPointers");
1539 1539 FLAG_SET_DEFAULT(UseCompressedClassPointers, false);
1540 1540 }
1541 1541 }
1542 1542 }
1543 1543 #endif // _LP64
1544 1544 #endif // !ZERO
1545 1545 }
1546 1546
1547 1547 void Arguments::set_conservative_max_heap_alignment() {
1548 1548 // The conservative maximum required alignment for the heap is the maximum of
1549 1549 // the alignments imposed by several sources: any requirements from the heap
1550 1550 // itself, the collector policy and the maximum page size we may run the VM
1551 1551 // with.
1552 1552 size_t heap_alignment = GenCollectedHeap::conservative_max_heap_alignment();
1553 1553 #if INCLUDE_ALL_GCS
1554 1554 if (UseParallelGC) {
1555 1555 heap_alignment = ParallelScavengeHeap::conservative_max_heap_alignment();
1556 1556 } else if (UseG1GC) {
1557 1557 heap_alignment = G1CollectedHeap::conservative_max_heap_alignment();
1558 1558 }
1559 1559 #endif // INCLUDE_ALL_GCS
1560 1560 _conservative_max_heap_alignment = MAX4(heap_alignment,
1561 1561 (size_t)os::vm_allocation_granularity(),
1562 1562 os::max_page_size(),
1563 1563 CollectorPolicy::compute_heap_alignment());
1564 1564 }
1565 1565
1566 1566 void Arguments::select_gc_ergonomically() {
1567 1567 if (os::is_server_class_machine()) {
1568 1568 if (should_auto_select_low_pause_collector()) {
1569 1569 FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
1570 1570 } else {
1571 1571 FLAG_SET_ERGO(bool, UseParallelGC, true);
1572 1572 }
1573 1573 } else {
1574 1574 FLAG_SET_ERGO(bool, UseSerialGC, true);
1575 1575 }
1576 1576 }
1577 1577
1578 1578 void Arguments::select_gc() {
1579 1579 if (!gc_selected()) {
1580 1580 select_gc_ergonomically();
1581 1581 guarantee(gc_selected(), "No GC selected");
1582 1582 }
1583 1583 }
1584 1584
1585 1585 void Arguments::set_ergonomics_flags() {
1586 1586 select_gc();
1587 1587
1588 1588 #ifdef COMPILER2
1589 1589 // Shared spaces work fine with other GCs but causes bytecode rewriting
1590 1590 // to be disabled, which hurts interpreter performance and decreases
1591 1591 // server performance. When -server is specified, keep the default off
1592 1592 // unless it is asked for. Future work: either add bytecode rewriting
1593 1593 // at link time, or rewrite bytecodes in non-shared methods.
1594 1594 if (!DumpSharedSpaces && !RequireSharedSpaces &&
1595 1595 (FLAG_IS_DEFAULT(UseSharedSpaces) || !UseSharedSpaces)) {
1596 1596 no_shared_spaces("COMPILER2 default: -Xshare:auto | off, have to manually setup to on.");
1597 1597 }
1598 1598 #endif
1599 1599
1600 1600 set_conservative_max_heap_alignment();
1601 1601
1602 1602 #ifndef ZERO
1603 1603 #ifdef _LP64
1604 1604 set_use_compressed_oops();
1605 1605
1606 1606 // set_use_compressed_klass_ptrs() must be called after calling
1607 1607 // set_use_compressed_oops().
1608 1608 set_use_compressed_klass_ptrs();
1609 1609
1610 1610 // Also checks that certain machines are slower with compressed oops
1611 1611 // in vm_version initialization code.
1612 1612 #endif // _LP64
1613 1613 #endif // !ZERO
1614 1614 }
1615 1615
1616 1616 void Arguments::set_parallel_gc_flags() {
1617 1617 assert(UseParallelGC || UseParallelOldGC, "Error");
1618 1618 // Enable ParallelOld unless it was explicitly disabled (cmd line or rc file).
1619 1619 if (FLAG_IS_DEFAULT(UseParallelOldGC)) {
1620 1620 FLAG_SET_DEFAULT(UseParallelOldGC, true);
1621 1621 }
1622 1622 FLAG_SET_DEFAULT(UseParallelGC, true);
1623 1623
1624 1624 // If no heap maximum was requested explicitly, use some reasonable fraction
1625 1625 // of the physical memory, up to a maximum of 1GB.
1626 1626 FLAG_SET_DEFAULT(ParallelGCThreads,
1627 1627 Abstract_VM_Version::parallel_worker_threads());
1628 1628 if (ParallelGCThreads == 0) {
1629 1629 jio_fprintf(defaultStream::error_stream(),
1630 1630 "The Parallel GC can not be combined with -XX:ParallelGCThreads=0\n");
1631 1631 vm_exit(1);
1632 1632 }
1633 1633
1634 1634 if (UseAdaptiveSizePolicy) {
1635 1635 // We don't want to limit adaptive heap sizing's freedom to adjust the heap
1636 1636 // unless the user actually sets these flags.
1637 1637 if (FLAG_IS_DEFAULT(MinHeapFreeRatio)) {
1638 1638 FLAG_SET_DEFAULT(MinHeapFreeRatio, 0);
1639 1639 _min_heap_free_ratio = MinHeapFreeRatio;
1640 1640 }
1641 1641 if (FLAG_IS_DEFAULT(MaxHeapFreeRatio)) {
1642 1642 FLAG_SET_DEFAULT(MaxHeapFreeRatio, 100);
1643 1643 _max_heap_free_ratio = MaxHeapFreeRatio;
1644 1644 }
1645 1645 }
1646 1646
1647 1647 // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the
1648 1648 // SurvivorRatio has been set, reset their default values to SurvivorRatio +
1649 1649 // 2. By doing this we make SurvivorRatio also work for Parallel Scavenger.
1650 1650 // See CR 6362902 for details.
1651 1651 if (!FLAG_IS_DEFAULT(SurvivorRatio)) {
1652 1652 if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) {
1653 1653 FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2);
1654 1654 }
1655 1655 if (FLAG_IS_DEFAULT(MinSurvivorRatio)) {
1656 1656 FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2);
1657 1657 }
1658 1658 }
1659 1659
1660 1660 if (UseParallelOldGC) {
1661 1661 // Par compact uses lower default values since they are treated as
1662 1662 // minimums. These are different defaults because of the different
1663 1663 // interpretation and are not ergonomically set.
1664 1664 if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) {
1665 1665 FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1);
1666 1666 }
1667 1667 }
1668 1668 }
1669 1669
1670 1670 void Arguments::set_g1_gc_flags() {
1671 1671 assert(UseG1GC, "Error");
1672 1672 #ifdef COMPILER1
1673 1673 FastTLABRefill = false;
1674 1674 #endif
1675 1675 FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
1676 1676 if (ParallelGCThreads == 0) {
1677 1677 assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0.");
1678 1678 vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL);
1679 1679 }
1680 1680
1681 1681 #if INCLUDE_ALL_GCS
1682 1682 if (G1ConcRefinementThreads == 0) {
1683 1683 FLAG_SET_DEFAULT(G1ConcRefinementThreads, ParallelGCThreads);
1684 1684 }
1685 1685 #endif
1686 1686
1687 1687 // MarkStackSize will be set (if it hasn't been set by the user)
1688 1688 // when concurrent marking is initialized.
1689 1689 // Its value will be based upon the number of parallel marking threads.
1690 1690 // But we do set the maximum mark stack size here.
1691 1691 if (FLAG_IS_DEFAULT(MarkStackSizeMax)) {
1692 1692 FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE);
1693 1693 }
1694 1694
1695 1695 if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
1696 1696 // In G1, we want the default GC overhead goal to be higher than
1697 1697 // say in PS. So we set it here to 10%. Otherwise the heap might
1698 1698 // be expanded more aggressively than we would like it to. In
1699 1699 // fact, even 10% seems to not be high enough in some cases
1700 1700 // (especially small GC stress tests that the main thing they do
1701 1701 // is allocation). We might consider increase it further.
1702 1702 FLAG_SET_DEFAULT(GCTimeRatio, 9);
1703 1703 }
1704 1704
1705 1705 if (PrintGCDetails && Verbose) {
1706 1706 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk",
1707 1707 (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
1708 1708 tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
1709 1709 }
1710 1710 }
1711 1711
1712 1712 #if !INCLUDE_ALL_GCS
1713 1713 #ifdef ASSERT
1714 1714 static bool verify_serial_gc_flags() {
1715 1715 return (UseSerialGC &&
1716 1716 !(UseParNewGC || (UseConcMarkSweepGC) || UseG1GC ||
1717 1717 UseParallelGC || UseParallelOldGC));
1718 1718 }
1719 1719 #endif // ASSERT
1720 1720 #endif // INCLUDE_ALL_GCS
1721 1721
1722 1722 void Arguments::set_gc_specific_flags() {
1723 1723 #if INCLUDE_ALL_GCS
1724 1724 // Set per-collector flags
1725 1725 if (UseParallelGC || UseParallelOldGC) {
1726 1726 set_parallel_gc_flags();
1727 1727 } else if (UseConcMarkSweepGC) {
1728 1728 set_cms_and_parnew_gc_flags();
1729 1729 } else if (UseG1GC) {
1730 1730 set_g1_gc_flags();
1731 1731 }
1732 1732 check_deprecated_gc_flags();
1733 1733 if (AssumeMP && !UseSerialGC) {
1734 1734 if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) {
1735 1735 warning("If the number of processors is expected to increase from one, then"
1736 1736 " you should configure the number of parallel GC threads appropriately"
1737 1737 " using -XX:ParallelGCThreads=N");
1738 1738 }
1739 1739 }
1740 1740 if (MinHeapFreeRatio == 100) {
1741 1741 // Keeping the heap 100% free is hard ;-) so limit it to 99%.
1742 1742 FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99);
1743 1743 }
1744 1744 #else // INCLUDE_ALL_GCS
1745 1745 assert(verify_serial_gc_flags(), "SerialGC unset");
1746 1746 #endif // INCLUDE_ALL_GCS
1747 1747 }
1748 1748
1749 1749 julong Arguments::limit_by_allocatable_memory(julong limit) {
1750 1750 julong max_allocatable;
1751 1751 julong result = limit;
1752 1752 if (os::has_allocatable_memory_limit(&max_allocatable)) {
1753 1753 result = MIN2(result, max_allocatable / MaxVirtMemFraction);
1754 1754 }
1755 1755 return result;
1756 1756 }
1757 1757
1758 1758 // Use static initialization to get the default before parsing
1759 1759 static const size_t DefaultHeapBaseMinAddress = HeapBaseMinAddress;
1760 1760
1761 1761 void Arguments::set_heap_size() {
1762 1762 if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) {
1763 1763 // Deprecated flag
1764 1764 FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction);
1765 1765 }
1766 1766
1767 1767 const julong phys_mem =
1768 1768 FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM)
1769 1769 : (julong)MaxRAM;
1770 1770
1771 1771 // If the maximum heap size has not been set with -Xmx,
1772 1772 // then set it as fraction of the size of physical memory,
1773 1773 // respecting the maximum and minimum sizes of the heap.
1774 1774 if (FLAG_IS_DEFAULT(MaxHeapSize)) {
1775 1775 julong reasonable_max = phys_mem / MaxRAMFraction;
1776 1776
1777 1777 if (phys_mem <= MaxHeapSize * MinRAMFraction) {
1778 1778 // Small physical memory, so use a minimum fraction of it for the heap
1779 1779 reasonable_max = phys_mem / MinRAMFraction;
1780 1780 } else {
1781 1781 // Not-small physical memory, so require a heap at least
1782 1782 // as large as MaxHeapSize
1783 1783 reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
1784 1784 }
1785 1785 if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
1786 1786 // Limit the heap size to ErgoHeapSizeLimit
1787 1787 reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit);
1788 1788 }
1789 1789 if (UseCompressedOops) {
1790 1790 // Limit the heap size to the maximum possible when using compressed oops
1791 1791 julong max_coop_heap = (julong)max_heap_for_compressed_oops();
1792 1792
1793 1793 // HeapBaseMinAddress can be greater than default but not less than.
1794 1794 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress)) {
1795 1795 if (HeapBaseMinAddress < DefaultHeapBaseMinAddress) {
1796 1796 // matches compressed oops printing flags
1797 1797 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) {
1798 1798 jio_fprintf(defaultStream::error_stream(),
1799 1799 "HeapBaseMinAddress must be at least " SIZE_FORMAT
1800 1800 " (" SIZE_FORMAT "G) which is greater than value given "
1801 1801 SIZE_FORMAT "\n",
1802 1802 DefaultHeapBaseMinAddress,
1803 1803 DefaultHeapBaseMinAddress/G,
1804 1804 HeapBaseMinAddress);
1805 1805 }
1806 1806 FLAG_SET_ERGO(size_t, HeapBaseMinAddress, DefaultHeapBaseMinAddress);
1807 1807 }
1808 1808 }
1809 1809
1810 1810 if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) {
1811 1811 // Heap should be above HeapBaseMinAddress to get zero based compressed oops
1812 1812 // but it should be not less than default MaxHeapSize.
1813 1813 max_coop_heap -= HeapBaseMinAddress;
1814 1814 }
1815 1815 reasonable_max = MIN2(reasonable_max, max_coop_heap);
1816 1816 }
1817 1817 reasonable_max = limit_by_allocatable_memory(reasonable_max);
1818 1818
1819 1819 if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
1820 1820 // An initial heap size was specified on the command line,
1821 1821 // so be sure that the maximum size is consistent. Done
1822 1822 // after call to limit_by_allocatable_memory because that
1823 1823 // method might reduce the allocation size.
1824 1824 reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
1825 1825 }
1826 1826
1827 1827 if (PrintGCDetails && Verbose) {
1828 1828 // Cannot use gclog_or_tty yet.
1829 1829 tty->print_cr(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max);
1830 1830 }
1831 1831 FLAG_SET_ERGO(size_t, MaxHeapSize, (size_t)reasonable_max);
1832 1832 }
1833 1833
1834 1834 // If the minimum or initial heap_size have not been set or requested to be set
1835 1835 // ergonomically, set them accordingly.
1836 1836 if (InitialHeapSize == 0 || min_heap_size() == 0) {
1837 1837 julong reasonable_minimum = (julong)(OldSize + NewSize);
1838 1838
1839 1839 reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
1840 1840
1841 1841 reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
1842 1842
1843 1843 if (InitialHeapSize == 0) {
1844 1844 julong reasonable_initial = phys_mem / InitialRAMFraction;
1845 1845
1846 1846 reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size());
1847 1847 reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
1848 1848
1849 1849 reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
1850 1850
1851 1851 if (PrintGCDetails && Verbose) {
1852 1852 // Cannot use gclog_or_tty yet.
1853 1853 tty->print_cr(" Initial heap size " SIZE_FORMAT, (size_t)reasonable_initial);
1854 1854 }
1855 1855 FLAG_SET_ERGO(size_t, InitialHeapSize, (size_t)reasonable_initial);
1856 1856 }
1857 1857 // If the minimum heap size has not been set (via -Xms),
1858 1858 // synchronize with InitialHeapSize to avoid errors with the default value.
1859 1859 if (min_heap_size() == 0) {
1860 1860 set_min_heap_size(MIN2((size_t)reasonable_minimum, InitialHeapSize));
1861 1861 if (PrintGCDetails && Verbose) {
1862 1862 // Cannot use gclog_or_tty yet.
1863 1863 tty->print_cr(" Minimum heap size " SIZE_FORMAT, min_heap_size());
1864 1864 }
1865 1865 }
1866 1866 }
1867 1867 }
1868 1868
1869 1869 // This must be called after ergonomics.
1870 1870 void Arguments::set_bytecode_flags() {
1871 1871 if (!RewriteBytecodes) {
1872 1872 FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1873 1873 }
1874 1874 }
1875 1875
1876 1876 // Aggressive optimization flags -XX:+AggressiveOpts
1877 1877 void Arguments::set_aggressive_opts_flags() {
1878 1878 #ifdef COMPILER2
1879 1879 if (AggressiveUnboxing) {
1880 1880 if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
1881 1881 FLAG_SET_DEFAULT(EliminateAutoBox, true);
1882 1882 } else if (!EliminateAutoBox) {
1883 1883 // warning("AggressiveUnboxing is disabled because EliminateAutoBox is disabled");
1884 1884 AggressiveUnboxing = false;
1885 1885 }
1886 1886 if (FLAG_IS_DEFAULT(DoEscapeAnalysis)) {
1887 1887 FLAG_SET_DEFAULT(DoEscapeAnalysis, true);
1888 1888 } else if (!DoEscapeAnalysis) {
1889 1889 // warning("AggressiveUnboxing is disabled because DoEscapeAnalysis is disabled");
1890 1890 AggressiveUnboxing = false;
1891 1891 }
1892 1892 }
1893 1893 if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
1894 1894 if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
1895 1895 FLAG_SET_DEFAULT(EliminateAutoBox, true);
1896 1896 }
1897 1897 if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
1898 1898 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000);
1899 1899 }
1900 1900
1901 1901 // Feed the cache size setting into the JDK
1902 1902 char buffer[1024];
1903 1903 sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
1904 1904 add_property(buffer);
1905 1905 }
1906 1906 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) {
1907 1907 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500);
1908 1908 }
1909 1909 #endif
1910 1910
1911 1911 if (AggressiveOpts) {
1912 1912 // Sample flag setting code
1913 1913 // if (FLAG_IS_DEFAULT(EliminateZeroing)) {
1914 1914 // FLAG_SET_DEFAULT(EliminateZeroing, true);
1915 1915 // }
1916 1916 }
1917 1917 }
1918 1918
1919 1919 //===========================================================================================================
1920 1920 // Parsing of java.compiler property
1921 1921
1922 1922 void Arguments::process_java_compiler_argument(char* arg) {
1923 1923 // For backwards compatibility, Djava.compiler=NONE or ""
1924 1924 // causes us to switch to -Xint mode UNLESS -Xdebug
1925 1925 // is also specified.
1926 1926 if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) {
1927 1927 set_java_compiler(true); // "-Djava.compiler[=...]" most recently seen.
1928 1928 }
1929 1929 }
1930 1930
1931 1931 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) {
1932 1932 _sun_java_launcher = os::strdup_check_oom(launcher);
1933 1933 }
1934 1934
1935 1935 bool Arguments::created_by_java_launcher() {
1936 1936 assert(_sun_java_launcher != NULL, "property must have value");
1937 1937 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1938 1938 }
1939 1939
1940 1940 bool Arguments::sun_java_launcher_is_altjvm() {
1941 1941 return _sun_java_launcher_is_altjvm;
1942 1942 }
1943 1943
1944 1944 //===========================================================================================================
1945 1945 // Parsing of main arguments
1946 1946
1947 1947 bool Arguments::verify_interval(uintx val, uintx min,
1948 1948 uintx max, const char* name) {
1949 1949 // Returns true iff value is in the inclusive interval [min..max]
1950 1950 // false, otherwise.
1951 1951 if (val >= min && val <= max) {
1952 1952 return true;
1953 1953 }
1954 1954 jio_fprintf(defaultStream::error_stream(),
1955 1955 "%s of " UINTX_FORMAT " is invalid; must be between " UINTX_FORMAT
1956 1956 " and " UINTX_FORMAT "\n",
1957 1957 name, val, min, max);
1958 1958 return false;
1959 1959 }
1960 1960
1961 1961 bool Arguments::verify_min_value(intx val, intx min, const char* name) {
1962 1962 // Returns true if given value is at least specified min threshold
1963 1963 // false, otherwise.
1964 1964 if (val >= min ) {
1965 1965 return true;
1966 1966 }
1967 1967 jio_fprintf(defaultStream::error_stream(),
1968 1968 "%s of " INTX_FORMAT " is invalid; must be at least " INTX_FORMAT "\n",
1969 1969 name, val, min);
1970 1970 return false;
1971 1971 }
1972 1972
1973 1973 bool Arguments::verify_percentage(uintx value, const char* name) {
1974 1974 if (is_percentage(value)) {
1975 1975 return true;
1976 1976 }
1977 1977 jio_fprintf(defaultStream::error_stream(),
1978 1978 "%s of " UINTX_FORMAT " is invalid; must be between 0 and 100\n",
1979 1979 name, value);
1980 1980 return false;
1981 1981 }
1982 1982
1983 1983 // check if do gclog rotation
1984 1984 // +UseGCLogFileRotation is a must,
1985 1985 // no gc log rotation when log file not supplied or
1986 1986 // NumberOfGCLogFiles is 0
1987 1987 void check_gclog_consistency() {
1988 1988 if (UseGCLogFileRotation) {
1989 1989 if ((Arguments::gc_log_filename() == NULL) || (NumberOfGCLogFiles == 0)) {
1990 1990 jio_fprintf(defaultStream::output_stream(),
1991 1991 "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files>\n"
1992 1992 "where num_of_file > 0\n"
1993 1993 "GC log rotation is turned off\n");
1994 1994 UseGCLogFileRotation = false;
1995 1995 }
1996 1996 }
1997 1997
1998 1998 if (UseGCLogFileRotation && (GCLogFileSize != 0) && (GCLogFileSize < 8*K)) {
1999 1999 FLAG_SET_CMDLINE(size_t, GCLogFileSize, 8*K);
2000 2000 jio_fprintf(defaultStream::output_stream(),
2001 2001 "GCLogFileSize changed to minimum 8K\n");
2002 2002 }
2003 2003 }
2004 2004
2005 2005 // This function is called for -Xloggc:<filename>, it can be used
2006 2006 // to check if a given file name(or string) conforms to the following
2007 2007 // specification:
2008 2008 // A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]"
2009 2009 // %p and %t only allowed once. We only limit usage of filename not path
2010 2010 bool is_filename_valid(const char *file_name) {
2011 2011 const char* p = file_name;
2012 2012 char file_sep = os::file_separator()[0];
2013 2013 const char* cp;
2014 2014 // skip prefix path
2015 2015 for (cp = file_name; *cp != '\0'; cp++) {
2016 2016 if (*cp == '/' || *cp == file_sep) {
2017 2017 p = cp + 1;
2018 2018 }
2019 2019 }
2020 2020
2021 2021 int count_p = 0;
2022 2022 int count_t = 0;
2023 2023 while (*p != '\0') {
2024 2024 if ((*p >= '0' && *p <= '9') ||
2025 2025 (*p >= 'A' && *p <= 'Z') ||
2026 2026 (*p >= 'a' && *p <= 'z') ||
2027 2027 *p == '-' ||
2028 2028 *p == '_' ||
2029 2029 *p == '.') {
2030 2030 p++;
2031 2031 continue;
2032 2032 }
2033 2033 if (*p == '%') {
2034 2034 if(*(p + 1) == 'p') {
2035 2035 p += 2;
2036 2036 count_p ++;
2037 2037 continue;
2038 2038 }
2039 2039 if (*(p + 1) == 't') {
2040 2040 p += 2;
2041 2041 count_t ++;
2042 2042 continue;
2043 2043 }
2044 2044 }
2045 2045 return false;
2046 2046 }
2047 2047 return count_p < 2 && count_t < 2;
2048 2048 }
2049 2049
2050 2050 bool Arguments::verify_MinHeapFreeRatio(FormatBuffer<80>& err_msg, uintx min_heap_free_ratio) {
2051 2051 if (!is_percentage(min_heap_free_ratio)) {
2052 2052 err_msg.print("MinHeapFreeRatio must have a value between 0 and 100");
2053 2053 return false;
2054 2054 }
2055 2055 if (min_heap_free_ratio > MaxHeapFreeRatio) {
2056 2056 err_msg.print("MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or "
2057 2057 "equal to MaxHeapFreeRatio (" UINTX_FORMAT ")", min_heap_free_ratio,
2058 2058 MaxHeapFreeRatio);
2059 2059 return false;
2060 2060 }
2061 2061 // This does not set the flag itself, but stores the value in a safe place for later usage.
2062 2062 _min_heap_free_ratio = min_heap_free_ratio;
2063 2063 return true;
2064 2064 }
2065 2065
2066 2066 bool Arguments::verify_MaxHeapFreeRatio(FormatBuffer<80>& err_msg, uintx max_heap_free_ratio) {
2067 2067 if (!is_percentage(max_heap_free_ratio)) {
2068 2068 err_msg.print("MaxHeapFreeRatio must have a value between 0 and 100");
2069 2069 return false;
2070 2070 }
2071 2071 if (max_heap_free_ratio < MinHeapFreeRatio) {
2072 2072 err_msg.print("MaxHeapFreeRatio (" UINTX_FORMAT ") must be greater than or "
2073 2073 "equal to MinHeapFreeRatio (" UINTX_FORMAT ")", max_heap_free_ratio,
2074 2074 MinHeapFreeRatio);
2075 2075 return false;
2076 2076 }
2077 2077 // This does not set the flag itself, but stores the value in a safe place for later usage.
2078 2078 _max_heap_free_ratio = max_heap_free_ratio;
2079 2079 return true;
2080 2080 }
2081 2081
2082 2082 // Check consistency of GC selection
2083 2083 bool Arguments::check_gc_consistency() {
2084 2084 check_gclog_consistency();
2085 2085 // Ensure that the user has not selected conflicting sets
2086 2086 // of collectors.
2087 2087 uint i = 0;
2088 2088 if (UseSerialGC) i++;
2089 2089 if (UseConcMarkSweepGC) i++;
2090 2090 if (UseParallelGC || UseParallelOldGC) i++;
2091 2091 if (UseG1GC) i++;
2092 2092 if (i > 1) {
2093 2093 jio_fprintf(defaultStream::error_stream(),
2094 2094 "Conflicting collector combinations in option list; "
2095 2095 "please refer to the release notes for the combinations "
2096 2096 "allowed\n");
2097 2097 return false;
2098 2098 }
2099 2099
2100 2100 if (UseConcMarkSweepGC && !UseParNewGC) {
2101 2101 jio_fprintf(defaultStream::error_stream(),
2102 2102 "It is not possible to combine the DefNew young collector with the CMS collector.\n");
2103 2103 return false;
2104 2104 }
2105 2105
2106 2106 if (UseParNewGC && !UseConcMarkSweepGC) {
2107 2107 jio_fprintf(defaultStream::error_stream(),
2108 2108 "It is not possible to combine the ParNew young collector with any collector other than CMS.\n");
2109 2109 return false;
2110 2110 }
2111 2111
2112 2112 return true;
2113 2113 }
2114 2114
2115 2115 void Arguments::check_deprecated_gc_flags() {
2116 2116 if (FLAG_IS_CMDLINE(UseParNewGC)) {
2117 2117 warning("The UseParNewGC flag is deprecated and will likely be removed in a future release");
2118 2118 }
2119 2119 if (FLAG_IS_CMDLINE(MaxGCMinorPauseMillis)) {
2120 2120 warning("Using MaxGCMinorPauseMillis as minor pause goal is deprecated"
2121 2121 "and will likely be removed in future release");
2122 2122 }
2123 2123 if (FLAG_IS_CMDLINE(DefaultMaxRAMFraction)) {
2124 2124 warning("DefaultMaxRAMFraction is deprecated and will likely be removed in a future release. "
2125 2125 "Use MaxRAMFraction instead.");
2126 2126 }
2127 2127 }
2128 2128
2129 2129 // Check stack pages settings
2130 2130 bool Arguments::check_stack_pages()
2131 2131 {
2132 2132 bool status = true;
2133 2133 status = status && verify_min_value(StackYellowPages, 1, "StackYellowPages");
2134 2134 status = status && verify_min_value(StackRedPages, 1, "StackRedPages");
2135 2135 // greater stack shadow pages can't generate instruction to bang stack
2136 2136 status = status && verify_interval(StackShadowPages, 1, 50, "StackShadowPages");
2137 2137 return status;
2138 2138 }
2139 2139
2140 2140 // Check the consistency of vm_init_args
2141 2141 bool Arguments::check_vm_args_consistency() {
2142 2142 // Method for adding checks for flag consistency.
2143 2143 // The intent is to warn the user of all possible conflicts,
2144 2144 // before returning an error.
2145 2145 // Note: Needs platform-dependent factoring.
2146 2146 bool status = true;
2147 2147
2148 2148 if (TLABRefillWasteFraction == 0) {
2149 2149 jio_fprintf(defaultStream::error_stream(),
2150 2150 "TLABRefillWasteFraction should be a denominator, "
2151 2151 "not " SIZE_FORMAT "\n",
2152 2152 TLABRefillWasteFraction);
2153 2153 status = false;
2154 2154 }
2155 2155
2156 2156 status = status && verify_interval(AdaptiveSizePolicyWeight, 0, 100,
2157 2157 "AdaptiveSizePolicyWeight");
2158 2158 status = status && verify_percentage(ThresholdTolerance, "ThresholdTolerance");
2159 2159
2160 2160 // Divide by bucket size to prevent a large size from causing rollover when
2161 2161 // calculating amount of memory needed to be allocated for the String table.
2162 2162 status = status && verify_interval(StringTableSize, minimumStringTableSize,
2163 2163 (max_uintx / StringTable::bucket_size()), "StringTable size");
2164 2164
2165 2165 status = status && verify_interval(SymbolTableSize, minimumSymbolTableSize,
2166 2166 (max_uintx / SymbolTable::bucket_size()), "SymbolTable size");
2167 2167
2168 2168 {
2169 2169 // Using "else if" below to avoid printing two error messages if min > max.
2170 2170 // This will also prevent us from reporting both min>100 and max>100 at the
2171 2171 // same time, but that is less annoying than printing two identical errors IMHO.
2172 2172 FormatBuffer<80> err_msg("%s","");
2173 2173 if (!verify_MinHeapFreeRatio(err_msg, MinHeapFreeRatio)) {
2174 2174 jio_fprintf(defaultStream::error_stream(), "%s\n", err_msg.buffer());
2175 2175 status = false;
2176 2176 } else if (!verify_MaxHeapFreeRatio(err_msg, MaxHeapFreeRatio)) {
2177 2177 jio_fprintf(defaultStream::error_stream(), "%s\n", err_msg.buffer());
2178 2178 status = false;
2179 2179 }
2180 2180 }
2181 2181
2182 2182 // Min/MaxMetaspaceFreeRatio
2183 2183 status = status && verify_percentage(MinMetaspaceFreeRatio, "MinMetaspaceFreeRatio");
2184 2184 status = status && verify_percentage(MaxMetaspaceFreeRatio, "MaxMetaspaceFreeRatio");
2185 2185
2186 2186 if (MinMetaspaceFreeRatio > MaxMetaspaceFreeRatio) {
2187 2187 jio_fprintf(defaultStream::error_stream(),
2188 2188 "MinMetaspaceFreeRatio (%s" UINTX_FORMAT ") must be less than or "
2189 2189 "equal to MaxMetaspaceFreeRatio (%s" UINTX_FORMAT ")\n",
2190 2190 FLAG_IS_DEFAULT(MinMetaspaceFreeRatio) ? "Default: " : "",
2191 2191 MinMetaspaceFreeRatio,
2192 2192 FLAG_IS_DEFAULT(MaxMetaspaceFreeRatio) ? "Default: " : "",
2193 2193 MaxMetaspaceFreeRatio);
2194 2194 status = false;
2195 2195 }
2196 2196
2197 2197 // Trying to keep 100% free is not practical
2198 2198 MinMetaspaceFreeRatio = MIN2(MinMetaspaceFreeRatio, (uintx) 99);
2199 2199
2200 2200 if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
2201 2201 MarkSweepAlwaysCompactCount = 1; // Move objects every gc.
2202 2202 }
2203 2203
2204 2204 if (UseParallelOldGC && ParallelOldGCSplitALot) {
2205 2205 // Settings to encourage splitting.
2206 2206 if (!FLAG_IS_CMDLINE(NewRatio)) {
2207 2207 FLAG_SET_CMDLINE(uintx, NewRatio, 2);
2208 2208 }
2209 2209 if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) {
2210 2210 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
2211 2211 }
2212 2212 }
2213 2213
2214 2214 if (!(UseParallelGC || UseParallelOldGC) && FLAG_IS_DEFAULT(ScavengeBeforeFullGC)) {
2215 2215 FLAG_SET_DEFAULT(ScavengeBeforeFullGC, false);
2216 2216 }
2217 2217
2218 2218 status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
2219 2219 status = status && verify_percentage(GCTimeLimit, "GCTimeLimit");
2220 2220 if (GCTimeLimit == 100) {
2221 2221 // Turn off gc-overhead-limit-exceeded checks
2222 2222 FLAG_SET_DEFAULT(UseGCOverheadLimit, false);
2223 2223 }
2224 2224
2225 2225 status = status && check_gc_consistency();
2226 2226 status = status && check_stack_pages();
2227 2227
2228 2228 status = status && verify_percentage(CMSIncrementalSafetyFactor,
2229 2229 "CMSIncrementalSafetyFactor");
2230 2230
2231 2231 // CMS space iteration, which FLSVerifyAllHeapreferences entails,
2232 2232 // insists that we hold the requisite locks so that the iteration is
2233 2233 // MT-safe. For the verification at start-up and shut-down, we don't
2234 2234 // yet have a good way of acquiring and releasing these locks,
2235 2235 // which are not visible at the CollectedHeap level. We want to
2236 2236 // be able to acquire these locks and then do the iteration rather
2237 2237 // than just disable the lock verification. This will be fixed under
2238 2238 // bug 4788986.
2239 2239 if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) {
2240 2240 if (VerifyDuringStartup) {
2241 2241 warning("Heap verification at start-up disabled "
2242 2242 "(due to current incompatibility with FLSVerifyAllHeapReferences)");
2243 2243 VerifyDuringStartup = false; // Disable verification at start-up
2244 2244 }
2245 2245
2246 2246 if (VerifyBeforeExit) {
2247 2247 warning("Heap verification at shutdown disabled "
2248 2248 "(due to current incompatibility with FLSVerifyAllHeapReferences)");
2249 2249 VerifyBeforeExit = false; // Disable verification at shutdown
2250 2250 }
2251 2251 }
2252 2252
2253 2253 // Note: only executed in non-PRODUCT mode
2254 2254 if (!UseAsyncConcMarkSweepGC &&
2255 2255 (ExplicitGCInvokesConcurrent ||
2256 2256 ExplicitGCInvokesConcurrentAndUnloadsClasses)) {
2257 2257 jio_fprintf(defaultStream::error_stream(),
2258 2258 "error: +ExplicitGCInvokesConcurrent[AndUnloadsClasses] conflicts"
2259 2259 " with -UseAsyncConcMarkSweepGC");
2260 2260 status = false;
2261 2261 }
2262 2262
2263 2263 status = status && verify_min_value(ParGCArrayScanChunk, 1, "ParGCArrayScanChunk");
2264 2264
2265 2265 #if INCLUDE_ALL_GCS
2266 2266 if (UseG1GC) {
2267 2267 status = status && verify_percentage(G1NewSizePercent, "G1NewSizePercent");
2268 2268 status = status && verify_percentage(G1MaxNewSizePercent, "G1MaxNewSizePercent");
2269 2269 status = status && verify_interval(G1NewSizePercent, 0, G1MaxNewSizePercent, "G1NewSizePercent");
2270 2270
2271 2271 status = status && verify_percentage(G1ConfidencePercent, "G1ConfidencePercent");
2272 2272 status = status && verify_percentage(InitiatingHeapOccupancyPercent,
2273 2273 "InitiatingHeapOccupancyPercent");
2274 2274 status = status && verify_min_value(G1RefProcDrainInterval, 1,
2275 2275 "G1RefProcDrainInterval");
2276 2276 status = status && verify_min_value((intx)G1ConcMarkStepDurationMillis, 1,
2277 2277 "G1ConcMarkStepDurationMillis");
2278 2278 status = status && verify_interval(G1ConcRSHotCardLimit, 0, max_jubyte,
2279 2279 "G1ConcRSHotCardLimit");
2280 2280 status = status && verify_interval(G1ConcRSLogCacheSize, 0, 27,
2281 2281 "G1ConcRSLogCacheSize");
2282 2282 status = status && verify_interval(StringDeduplicationAgeThreshold, 1, markOopDesc::max_age,
2283 2283 "StringDeduplicationAgeThreshold");
2284 2284 }
2285 2285 if (UseConcMarkSweepGC) {
2286 2286 status = status && verify_min_value(CMSOldPLABNumRefills, 1, "CMSOldPLABNumRefills");
2287 2287 status = status && verify_min_value(CMSOldPLABToleranceFactor, 1, "CMSOldPLABToleranceFactor");
2288 2288 status = status && verify_min_value(CMSOldPLABMax, 1, "CMSOldPLABMax");
2289 2289 status = status && verify_interval(CMSOldPLABMin, 1, CMSOldPLABMax, "CMSOldPLABMin");
2290 2290
2291 2291 status = status && verify_min_value(CMSYoungGenPerWorker, 1, "CMSYoungGenPerWorker");
2292 2292
2293 2293 status = status && verify_min_value(CMSSamplingGrain, 1, "CMSSamplingGrain");
2294 2294 status = status && verify_interval(CMS_SweepWeight, 0, 100, "CMS_SweepWeight");
2295 2295 status = status && verify_interval(CMS_FLSWeight, 0, 100, "CMS_FLSWeight");
2296 2296
2297 2297 status = status && verify_interval(FLSCoalescePolicy, 0, 4, "FLSCoalescePolicy");
2298 2298
2299 2299 status = status && verify_min_value(CMSRescanMultiple, 1, "CMSRescanMultiple");
2300 2300 status = status && verify_min_value(CMSConcMarkMultiple, 1, "CMSConcMarkMultiple");
2301 2301
2302 2302 status = status && verify_interval(CMSPrecleanIter, 0, 9, "CMSPrecleanIter");
2303 2303 status = status && verify_min_value(CMSPrecleanDenominator, 1, "CMSPrecleanDenominator");
2304 2304 status = status && verify_interval(CMSPrecleanNumerator, 0, CMSPrecleanDenominator - 1, "CMSPrecleanNumerator");
2305 2305
2306 2306 status = status && verify_percentage(CMSBootstrapOccupancy, "CMSBootstrapOccupancy");
2307 2307
2308 2308 status = status && verify_min_value(CMSPrecleanThreshold, 100, "CMSPrecleanThreshold");
2309 2309
2310 2310 status = status && verify_percentage(CMSScheduleRemarkEdenPenetration, "CMSScheduleRemarkEdenPenetration");
2311 2311 status = status && verify_min_value(CMSScheduleRemarkSamplingRatio, 1, "CMSScheduleRemarkSamplingRatio");
2312 2312 status = status && verify_min_value(CMSBitMapYieldQuantum, 1, "CMSBitMapYieldQuantum");
2313 2313 status = status && verify_percentage(CMSTriggerRatio, "CMSTriggerRatio");
2314 2314 status = status && verify_percentage(CMSIsTooFullPercentage, "CMSIsTooFullPercentage");
2315 2315 }
2316 2316
2317 2317 if (UseParallelGC || UseParallelOldGC) {
2318 2318 status = status && verify_interval(ParallelOldDeadWoodLimiterMean, 0, 100, "ParallelOldDeadWoodLimiterMean");
2319 2319 status = status && verify_interval(ParallelOldDeadWoodLimiterStdDev, 0, 100, "ParallelOldDeadWoodLimiterStdDev");
2320 2320
2321 2321 status = status && verify_percentage(YoungGenerationSizeIncrement, "YoungGenerationSizeIncrement");
2322 2322 status = status && verify_percentage(TenuredGenerationSizeIncrement, "TenuredGenerationSizeIncrement");
2323 2323
2324 2324 status = status && verify_min_value(YoungGenerationSizeSupplementDecay, 1, "YoungGenerationSizeSupplementDecay");
2325 2325 status = status && verify_min_value(TenuredGenerationSizeSupplementDecay, 1, "TenuredGenerationSizeSupplementDecay");
2326 2326
2327 2327 status = status && verify_min_value(ParGCCardsPerStrideChunk, 1, "ParGCCardsPerStrideChunk");
2328 2328
2329 2329 status = status && verify_min_value(ParallelOldGCSplitInterval, 0, "ParallelOldGCSplitInterval");
2330 2330 }
2331 2331 #endif // INCLUDE_ALL_GCS
2332 2332
2333 2333 status = status && verify_interval(RefDiscoveryPolicy,
2334 2334 ReferenceProcessor::DiscoveryPolicyMin,
2335 2335 ReferenceProcessor::DiscoveryPolicyMax,
2336 2336 "RefDiscoveryPolicy");
2337 2337
2338 2338 // Limit the lower bound of this flag to 1 as it is used in a division
2339 2339 // expression.
2340 2340 status = status && verify_interval(TLABWasteTargetPercent,
2341 2341 1, 100, "TLABWasteTargetPercent");
2342 2342
2343 2343 status = status && verify_object_alignment();
2344 2344
2345 2345 status = status && verify_interval(CompressedClassSpaceSize, 1*M, 3*G,
2346 2346 "CompressedClassSpaceSize");
2347 2347
2348 2348 status = status && verify_interval(MarkStackSizeMax,
2349 2349 1, (max_jint - 1), "MarkStackSizeMax");
2350 2350 status = status && verify_interval(NUMAChunkResizeWeight, 0, 100, "NUMAChunkResizeWeight");
2351 2351
2352 2352 status = status && verify_min_value(LogEventsBufferEntries, 1, "LogEventsBufferEntries");
2353 2353
2354 2354 status = status && verify_min_value(HeapSizePerGCThread, (size_t) os::vm_page_size(), "HeapSizePerGCThread");
2355 2355
2356 2356 status = status && verify_min_value(GCTaskTimeStampEntries, 1, "GCTaskTimeStampEntries");
2357 2357
2358 2358 status = status && verify_percentage(ParallelGCBufferWastePct, "ParallelGCBufferWastePct");
2359 2359 status = status && verify_interval(TargetPLABWastePct, 1, 100, "TargetPLABWastePct");
2360 2360
2361 2361 status = status && verify_min_value(ParGCStridesPerThread, 1, "ParGCStridesPerThread");
2362 2362
2363 2363 status = status && verify_min_value(MinRAMFraction, 1, "MinRAMFraction");
2364 2364 status = status && verify_min_value(InitialRAMFraction, 1, "InitialRAMFraction");
2365 2365 status = status && verify_min_value(MaxRAMFraction, 1, "MaxRAMFraction");
2366 2366 status = status && verify_min_value(DefaultMaxRAMFraction, 1, "DefaultMaxRAMFraction");
2367 2367
2368 2368 status = status && verify_interval(AdaptiveTimeWeight, 0, 100, "AdaptiveTimeWeight");
2369 2369 status = status && verify_min_value(AdaptiveSizeDecrementScaleFactor, 1, "AdaptiveSizeDecrementScaleFactor");
2370 2370
2371 2371 status = status && verify_interval(TLABAllocationWeight, 0, 100, "TLABAllocationWeight");
2372 2372 status = status && verify_min_value(MinTLABSize, 1, "MinTLABSize");
2373 2373 status = status && verify_min_value(TLABRefillWasteFraction, 1, "TLABRefillWasteFraction");
2374 2374
2375 2375 status = status && verify_percentage(YoungGenerationSizeSupplement, "YoungGenerationSizeSupplement");
2376 2376 status = status && verify_percentage(TenuredGenerationSizeSupplement, "TenuredGenerationSizeSupplement");
2377 2377
2378 2378 status = status && verify_interval(MaxTenuringThreshold, 0, markOopDesc::max_age + 1, "MaxTenuringThreshold");
2379 2379 status = status && verify_interval(InitialTenuringThreshold, 0, MaxTenuringThreshold, "InitialTenuringThreshold");
2380 2380 status = status && verify_percentage(TargetSurvivorRatio, "TargetSurvivorRatio");
2381 2381 status = status && verify_percentage(MarkSweepDeadRatio, "MarkSweepDeadRatio");
2382 2382
2383 2383 status = status && verify_min_value(MarkSweepAlwaysCompactCount, 1, "MarkSweepAlwaysCompactCount");
2384 2384 #ifdef COMPILER1
2385 2385 status = status && verify_min_value(ValueMapInitialSize, 1, "ValueMapInitialSize");
2386 2386 #endif
2387 2387 status = status && verify_min_value(HeapSearchSteps, 1, "HeapSearchSteps");
2388 2388
2389 2389 if (PrintNMTStatistics) {
2390 2390 #if INCLUDE_NMT
2391 2391 if (MemTracker::tracking_level() == NMT_off) {
2392 2392 #endif // INCLUDE_NMT
2393 2393 warning("PrintNMTStatistics is disabled, because native memory tracking is not enabled");
2394 2394 PrintNMTStatistics = false;
2395 2395 #if INCLUDE_NMT
2396 2396 }
2397 2397 #endif
2398 2398 }
2399 2399
2400 2400 // Need to limit the extent of the padding to reasonable size.
2401 2401 // 8K is well beyond the reasonable HW cache line size, even with the
2402 2402 // aggressive prefetching, while still leaving the room for segregating
2403 2403 // among the distinct pages.
2404 2404 if (ContendedPaddingWidth < 0 || ContendedPaddingWidth > 8192) {
2405 2405 jio_fprintf(defaultStream::error_stream(),
2406 2406 "ContendedPaddingWidth=" INTX_FORMAT " must be in between %d and %d\n",
2407 2407 ContendedPaddingWidth, 0, 8192);
2408 2408 status = false;
2409 2409 }
2410 2410
2411 2411 // Need to enforce the padding not to break the existing field alignments.
2412 2412 // It is sufficient to check against the largest type size.
2413 2413 if ((ContendedPaddingWidth % BytesPerLong) != 0) {
2414 2414 jio_fprintf(defaultStream::error_stream(),
2415 2415 "ContendedPaddingWidth=" INTX_FORMAT " must be a multiple of %d\n",
2416 2416 ContendedPaddingWidth, BytesPerLong);
2417 2417 status = false;
2418 2418 }
2419 2419
2420 2420 // Check lower bounds of the code cache
2421 2421 // Template Interpreter code is approximately 3X larger in debug builds.
2422 2422 uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3);
2423 2423 if (InitialCodeCacheSize < (uintx)os::vm_page_size()) {
2424 2424 jio_fprintf(defaultStream::error_stream(),
2425 2425 "Invalid InitialCodeCacheSize=%dK. Must be at least %dK.\n", InitialCodeCacheSize/K,
2426 2426 os::vm_page_size()/K);
2427 2427 status = false;
2428 2428 } else if (ReservedCodeCacheSize < InitialCodeCacheSize) {
2429 2429 jio_fprintf(defaultStream::error_stream(),
2430 2430 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",
2431 2431 ReservedCodeCacheSize/K, InitialCodeCacheSize/K);
2432 2432 status = false;
2433 2433 } else if (ReservedCodeCacheSize < min_code_cache_size) {
2434 2434 jio_fprintf(defaultStream::error_stream(),
2435 2435 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K,
2436 2436 min_code_cache_size/K);
2437 2437 status = false;
2438 2438 } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) {
2439 2439 // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported.
2440 2440 jio_fprintf(defaultStream::error_stream(),
2441 2441 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M,
2442 2442 CODE_CACHE_SIZE_LIMIT/M);
2443 2443 status = false;
2444 2444 } else if (NonNMethodCodeHeapSize < min_code_cache_size){
2445 2445 jio_fprintf(defaultStream::error_stream(),
2446 2446 "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K,
2447 2447 min_code_cache_size/K);
2448 2448 status = false;
2449 2449 } else if ((!FLAG_IS_DEFAULT(NonNMethodCodeHeapSize) || !FLAG_IS_DEFAULT(ProfiledCodeHeapSize) || !FLAG_IS_DEFAULT(NonProfiledCodeHeapSize))
2450 2450 && (NonNMethodCodeHeapSize + NonProfiledCodeHeapSize + ProfiledCodeHeapSize) != ReservedCodeCacheSize) {
2451 2451 jio_fprintf(defaultStream::error_stream(),
2452 2452 "Invalid code heap sizes: NonNMethodCodeHeapSize(%dK) + ProfiledCodeHeapSize(%dK) + NonProfiledCodeHeapSize(%dK) = %dK. Must be equal to ReservedCodeCacheSize = %uK.\n",
2453 2453 NonNMethodCodeHeapSize/K, ProfiledCodeHeapSize/K, NonProfiledCodeHeapSize/K,
2454 2454 (NonNMethodCodeHeapSize + ProfiledCodeHeapSize + NonProfiledCodeHeapSize)/K, ReservedCodeCacheSize/K);
2455 2455 status = false;
2456 2456 }
2457 2457
2458 2458 status &= verify_interval(NmethodSweepActivity, 0, 2000, "NmethodSweepActivity");
2459 2459 status &= verify_interval(CodeCacheMinBlockLength, 1, 100, "CodeCacheMinBlockLength");
2460 2460 status &= verify_interval(CodeCacheSegmentSize, 1, 1024, "CodeCacheSegmentSize");
2461 2461 status &= verify_interval(StartAggressiveSweepingAt, 0, 100, "StartAggressiveSweepingAt");
2462 2462
2463 2463
2464 2464 int min_number_of_compiler_threads = get_min_number_of_compiler_threads();
2465 2465 // The default CICompilerCount's value is CI_COMPILER_COUNT.
2466 2466 assert(min_number_of_compiler_threads <= CI_COMPILER_COUNT, "minimum should be less or equal default number");
2467 2467 // Check the minimum number of compiler threads
2468 2468 status &=verify_min_value(CICompilerCount, min_number_of_compiler_threads, "CICompilerCount");
2469 2469
2470 2470 if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) {
2471 2471 warning("The VM option CICompilerCountPerCPU overrides CICompilerCount.");
2472 2472 }
2473 2473
2474 2474 return status;
2475 2475 }
2476 2476
2477 2477 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore,
2478 2478 const char* option_type) {
2479 2479 if (ignore) return false;
2480 2480
2481 2481 const char* spacer = " ";
2482 2482 if (option_type == NULL) {
2483 2483 option_type = ++spacer; // Set both to the empty string.
2484 2484 }
2485 2485
2486 2486 if (os::obsolete_option(option)) {
2487 2487 jio_fprintf(defaultStream::error_stream(),
2488 2488 "Obsolete %s%soption: %s\n", option_type, spacer,
2489 2489 option->optionString);
2490 2490 return false;
2491 2491 } else {
2492 2492 jio_fprintf(defaultStream::error_stream(),
2493 2493 "Unrecognized %s%soption: %s\n", option_type, spacer,
2494 2494 option->optionString);
2495 2495 return true;
2496 2496 }
2497 2497 }
2498 2498
2499 2499 static const char* user_assertion_options[] = {
2500 2500 "-da", "-ea", "-disableassertions", "-enableassertions", 0
2501 2501 };
2502 2502
2503 2503 static const char* system_assertion_options[] = {
2504 2504 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0
2505 2505 };
2506 2506
2507 2507 bool Arguments::parse_uintx(const char* value,
2508 2508 uintx* uintx_arg,
2509 2509 uintx min_size) {
2510 2510
2511 2511 // Check the sign first since atomull() parses only unsigned values.
2512 2512 bool value_is_positive = !(*value == '-');
2513 2513
2514 2514 if (value_is_positive) {
2515 2515 julong n;
2516 2516 bool good_return = atomull(value, &n);
2517 2517 if (good_return) {
2518 2518 bool above_minimum = n >= min_size;
2519 2519 bool value_is_too_large = n > max_uintx;
2520 2520
2521 2521 if (above_minimum && !value_is_too_large) {
2522 2522 *uintx_arg = n;
2523 2523 return true;
2524 2524 }
2525 2525 }
2526 2526 }
2527 2527 return false;
2528 2528 }
2529 2529
2530 2530 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2531 2531 julong* long_arg,
2532 2532 julong min_size) {
2533 2533 if (!atomull(s, long_arg)) return arg_unreadable;
2534 2534 return check_memory_size(*long_arg, min_size);
2535 2535 }
2536 2536
2537 2537 // Parse JavaVMInitArgs structure
2538 2538
2539 2539 jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) {
2540 2540 // For components of the system classpath.
2541 2541 SysClassPath scp(Arguments::get_sysclasspath());
2542 2542 bool scp_assembly_required = false;
2543 2543
2544 2544 // Save default settings for some mode flags
2545 2545 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
2546 2546 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
2547 2547 Arguments::_ClipInlining = ClipInlining;
2548 2548 Arguments::_BackgroundCompilation = BackgroundCompilation;
2549 2549 if (TieredCompilation) {
2550 2550 Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog;
2551 2551 Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold;
2552 2552 }
2553 2553
2554 2554 // Setup flags for mixed which is the default
2555 2555 set_mode_flags(_mixed);
2556 2556
2557 2557 // Parse JAVA_TOOL_OPTIONS environment variable (if present)
2558 2558 jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required);
2559 2559 if (result != JNI_OK) {
2560 2560 return result;
2561 2561 }
2562 2562
2563 2563 // Parse JavaVMInitArgs structure passed in
2564 2564 result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, Flag::COMMAND_LINE);
2565 2565 if (result != JNI_OK) {
2566 2566 return result;
2567 2567 }
2568 2568
2569 2569 // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM)
2570 2570 result = parse_java_options_environment_variable(&scp, &scp_assembly_required);
2571 2571 if (result != JNI_OK) {
2572 2572 return result;
2573 2573 }
2574 2574
2575 2575 // Do final processing now that all arguments have been parsed
2576 2576 result = finalize_vm_init_args(&scp, scp_assembly_required);
2577 2577 if (result != JNI_OK) {
2578 2578 return result;
2579 2579 }
2580 2580
2581 2581 return JNI_OK;
2582 2582 }
2583 2583
2584 2584 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2585 2585 // represents a valid HPROF of JDWP agent. is_path==true denotes that we
2586 2586 // are dealing with -agentpath (case where name is a path), otherwise with
2587 2587 // -agentlib
2588 2588 bool valid_hprof_or_jdwp_agent(char *name, bool is_path) {
2589 2589 char *_name;
2590 2590 const char *_hprof = "hprof", *_jdwp = "jdwp";
2591 2591 size_t _len_hprof, _len_jdwp, _len_prefix;
2592 2592
2593 2593 if (is_path) {
2594 2594 if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) {
2595 2595 return false;
2596 2596 }
2597 2597
2598 2598 _name++; // skip past last path separator
2599 2599 _len_prefix = strlen(JNI_LIB_PREFIX);
2600 2600
2601 2601 if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) {
2602 2602 return false;
2603 2603 }
2604 2604
2605 2605 _name += _len_prefix;
2606 2606 _len_hprof = strlen(_hprof);
2607 2607 _len_jdwp = strlen(_jdwp);
2608 2608
2609 2609 if (strncmp(_name, _hprof, _len_hprof) == 0) {
2610 2610 _name += _len_hprof;
2611 2611 }
2612 2612 else if (strncmp(_name, _jdwp, _len_jdwp) == 0) {
2613 2613 _name += _len_jdwp;
2614 2614 }
2615 2615 else {
2616 2616 return false;
2617 2617 }
2618 2618
2619 2619 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2620 2620 return false;
2621 2621 }
2622 2622
2623 2623 return true;
2624 2624 }
2625 2625
2626 2626 if (strcmp(name, _hprof) == 0 || strcmp(name, _jdwp) == 0) {
2627 2627 return true;
2628 2628 }
2629 2629
2630 2630 return false;
2631 2631 }
2632 2632
2633 2633 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
2634 2634 SysClassPath* scp_p,
2635 2635 bool* scp_assembly_required_p,
2636 2636 Flag::Flags origin) {
2637 2637 // Remaining part of option string
2638 2638 const char* tail;
2639 2639
2640 2640 // iterate over arguments
2641 2641 for (int index = 0; index < args->nOptions; index++) {
2642 2642 bool is_absolute_path = false; // for -agentpath vs -agentlib
2643 2643
2644 2644 const JavaVMOption* option = args->options + index;
2645 2645
2646 2646 if (!match_option(option, "-Djava.class.path", &tail) &&
2647 2647 !match_option(option, "-Dsun.java.command", &tail) &&
2648 2648 !match_option(option, "-Dsun.java.launcher", &tail)) {
2649 2649
2650 2650 // add all jvm options to the jvm_args string. This string
2651 2651 // is used later to set the java.vm.args PerfData string constant.
2652 2652 // the -Djava.class.path and the -Dsun.java.command options are
2653 2653 // omitted from jvm_args string as each have their own PerfData
2654 2654 // string constant object.
2655 2655 build_jvm_args(option->optionString);
2656 2656 }
2657 2657
2658 2658 // -verbose:[class/gc/jni]
2659 2659 if (match_option(option, "-verbose", &tail)) {
2660 2660 if (!strcmp(tail, ":class") || !strcmp(tail, "")) {
2661 2661 FLAG_SET_CMDLINE(bool, TraceClassLoading, true);
2662 2662 FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
2663 2663 } else if (!strcmp(tail, ":gc")) {
2664 2664 FLAG_SET_CMDLINE(bool, PrintGC, true);
2665 2665 } else if (!strcmp(tail, ":jni")) {
2666 2666 FLAG_SET_CMDLINE(bool, PrintJNIResolving, true);
2667 2667 }
2668 2668 // -da / -ea / -disableassertions / -enableassertions
2669 2669 // These accept an optional class/package name separated by a colon, e.g.,
2670 2670 // -da:java.lang.Thread.
2671 2671 } else if (match_option(option, user_assertion_options, &tail, true)) {
2672 2672 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e'
2673 2673 if (*tail == '\0') {
2674 2674 JavaAssertions::setUserClassDefault(enable);
2675 2675 } else {
2676 2676 assert(*tail == ':', "bogus match by match_option()");
2677 2677 JavaAssertions::addOption(tail + 1, enable);
2678 2678 }
2679 2679 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions
2680 2680 } else if (match_option(option, system_assertion_options, &tail, false)) {
2681 2681 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e'
2682 2682 JavaAssertions::setSystemClassDefault(enable);
2683 2683 // -bootclasspath:
2684 2684 } else if (match_option(option, "-Xbootclasspath:", &tail)) {
2685 2685 scp_p->reset_path(tail);
2686 2686 *scp_assembly_required_p = true;
2687 2687 // -bootclasspath/a:
2688 2688 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) {
2689 2689 scp_p->add_suffix(tail);
2690 2690 *scp_assembly_required_p = true;
2691 2691 // -bootclasspath/p:
2692 2692 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) {
2693 2693 scp_p->add_prefix(tail);
2694 2694 *scp_assembly_required_p = true;
2695 2695 // -Xrun
2696 2696 } else if (match_option(option, "-Xrun", &tail)) {
2697 2697 if (tail != NULL) {
2698 2698 const char* pos = strchr(tail, ':');
2699 2699 size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
2700 2700 char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len);
2701 2701 name[len] = '\0';
2702 2702
2703 2703 char *options = NULL;
2704 2704 if(pos != NULL) {
2705 2705 size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied.
2706 2706 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2, mtInternal), pos+1, len2);
2707 2707 }
2708 2708 #if !INCLUDE_JVMTI
2709 2709 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
2710 2710 jio_fprintf(defaultStream::error_stream(),
2711 2711 "Profiling and debugging agents are not supported in this VM\n");
2712 2712 return JNI_ERR;
2713 2713 }
2714 2714 #endif // !INCLUDE_JVMTI
2715 2715 add_init_library(name, options);
2716 2716 }
2717 2717 // -agentlib and -agentpath
2718 2718 } else if (match_option(option, "-agentlib:", &tail) ||
2719 2719 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2720 2720 if(tail != NULL) {
2721 2721 const char* pos = strchr(tail, '=');
2722 2722 size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
2723 2723 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len);
2724 2724 name[len] = '\0';
2725 2725
2726 2726 char *options = NULL;
2727 2727 if(pos != NULL) {
2728 2728 options = os::strdup_check_oom(pos + 1, mtInternal);
2729 2729 }
2730 2730 #if !INCLUDE_JVMTI
2731 2731 if (valid_hprof_or_jdwp_agent(name, is_absolute_path)) {
2732 2732 jio_fprintf(defaultStream::error_stream(),
2733 2733 "Profiling and debugging agents are not supported in this VM\n");
2734 2734 return JNI_ERR;
2735 2735 }
2736 2736 #endif // !INCLUDE_JVMTI
2737 2737 add_init_agent(name, options, is_absolute_path);
2738 2738 }
2739 2739 // -javaagent
2740 2740 } else if (match_option(option, "-javaagent:", &tail)) {
2741 2741 #if !INCLUDE_JVMTI
2742 2742 jio_fprintf(defaultStream::error_stream(),
2743 2743 "Instrumentation agents are not supported in this VM\n");
↓ open down ↓ |
2743 lines elided |
↑ open up ↑ |
2744 2744 return JNI_ERR;
2745 2745 #else
2746 2746 if(tail != NULL) {
2747 2747 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtInternal), tail);
2748 2748 add_init_agent("instrument", options, false);
2749 2749 }
2750 2750 #endif // !INCLUDE_JVMTI
2751 2751 // -Xnoclassgc
2752 2752 } else if (match_option(option, "-Xnoclassgc")) {
2753 2753 FLAG_SET_CMDLINE(bool, ClassUnloading, false);
2754 + FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false);
2754 2755 // -Xconcgc
2755 2756 } else if (match_option(option, "-Xconcgc")) {
2756 2757 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
2757 2758 // -Xnoconcgc
2758 2759 } else if (match_option(option, "-Xnoconcgc")) {
2759 2760 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
2760 2761 // -Xbatch
2761 2762 } else if (match_option(option, "-Xbatch")) {
2762 2763 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
2763 2764 // -Xmn for compatibility with other JVM vendors
2764 2765 } else if (match_option(option, "-Xmn", &tail)) {
2765 2766 julong long_initial_young_size = 0;
2766 2767 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2767 2768 if (errcode != arg_in_range) {
2768 2769 jio_fprintf(defaultStream::error_stream(),
2769 2770 "Invalid initial young generation size: %s\n", option->optionString);
2770 2771 describe_range_error(errcode);
2771 2772 return JNI_EINVAL;
2772 2773 }
2773 2774 FLAG_SET_CMDLINE(size_t, MaxNewSize, (size_t)long_initial_young_size);
2774 2775 FLAG_SET_CMDLINE(size_t, NewSize, (size_t)long_initial_young_size);
2775 2776 // -Xms
2776 2777 } else if (match_option(option, "-Xms", &tail)) {
2777 2778 julong long_initial_heap_size = 0;
2778 2779 // an initial heap size of 0 means automatically determine
2779 2780 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0);
2780 2781 if (errcode != arg_in_range) {
2781 2782 jio_fprintf(defaultStream::error_stream(),
2782 2783 "Invalid initial heap size: %s\n", option->optionString);
2783 2784 describe_range_error(errcode);
2784 2785 return JNI_EINVAL;
2785 2786 }
2786 2787 set_min_heap_size((size_t)long_initial_heap_size);
2787 2788 // Currently the minimum size and the initial heap sizes are the same.
2788 2789 // Can be overridden with -XX:InitialHeapSize.
2789 2790 FLAG_SET_CMDLINE(size_t, InitialHeapSize, (size_t)long_initial_heap_size);
2790 2791 // -Xmx
2791 2792 } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) {
2792 2793 julong long_max_heap_size = 0;
2793 2794 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
2794 2795 if (errcode != arg_in_range) {
2795 2796 jio_fprintf(defaultStream::error_stream(),
2796 2797 "Invalid maximum heap size: %s\n", option->optionString);
2797 2798 describe_range_error(errcode);
2798 2799 return JNI_EINVAL;
2799 2800 }
2800 2801 FLAG_SET_CMDLINE(size_t, MaxHeapSize, (size_t)long_max_heap_size);
2801 2802 // Xmaxf
2802 2803 } else if (match_option(option, "-Xmaxf", &tail)) {
2803 2804 char* err;
2804 2805 int maxf = (int)(strtod(tail, &err) * 100);
2805 2806 if (*err != '\0' || *tail == '\0' || maxf < 0 || maxf > 100) {
2806 2807 jio_fprintf(defaultStream::error_stream(),
2807 2808 "Bad max heap free percentage size: %s\n",
2808 2809 option->optionString);
2809 2810 return JNI_EINVAL;
2810 2811 } else {
2811 2812 FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf);
2812 2813 }
2813 2814 // Xminf
2814 2815 } else if (match_option(option, "-Xminf", &tail)) {
2815 2816 char* err;
2816 2817 int minf = (int)(strtod(tail, &err) * 100);
2817 2818 if (*err != '\0' || *tail == '\0' || minf < 0 || minf > 100) {
2818 2819 jio_fprintf(defaultStream::error_stream(),
2819 2820 "Bad min heap free percentage size: %s\n",
2820 2821 option->optionString);
2821 2822 return JNI_EINVAL;
2822 2823 } else {
2823 2824 FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf);
2824 2825 }
2825 2826 // -Xss
2826 2827 } else if (match_option(option, "-Xss", &tail)) {
2827 2828 julong long_ThreadStackSize = 0;
2828 2829 ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
2829 2830 if (errcode != arg_in_range) {
2830 2831 jio_fprintf(defaultStream::error_stream(),
2831 2832 "Invalid thread stack size: %s\n", option->optionString);
2832 2833 describe_range_error(errcode);
2833 2834 return JNI_EINVAL;
2834 2835 }
2835 2836 // Internally track ThreadStackSize in units of 1024 bytes.
2836 2837 FLAG_SET_CMDLINE(intx, ThreadStackSize,
2837 2838 round_to((int)long_ThreadStackSize, K) / K);
2838 2839 // -Xoss
2839 2840 } else if (match_option(option, "-Xoss", &tail)) {
2840 2841 // HotSpot does not have separate native and Java stacks, ignore silently for compatibility
2841 2842 } else if (match_option(option, "-XX:CodeCacheExpansionSize=", &tail)) {
2842 2843 julong long_CodeCacheExpansionSize = 0;
2843 2844 ArgsRange errcode = parse_memory_size(tail, &long_CodeCacheExpansionSize, os::vm_page_size());
2844 2845 if (errcode != arg_in_range) {
2845 2846 jio_fprintf(defaultStream::error_stream(),
2846 2847 "Invalid argument: %s. Must be at least %luK.\n", option->optionString,
2847 2848 os::vm_page_size()/K);
2848 2849 return JNI_EINVAL;
2849 2850 }
2850 2851 FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx)long_CodeCacheExpansionSize);
2851 2852 } else if (match_option(option, "-Xmaxjitcodesize", &tail) ||
2852 2853 match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) {
2853 2854 julong long_ReservedCodeCacheSize = 0;
2854 2855
2855 2856 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1);
2856 2857 if (errcode != arg_in_range) {
2857 2858 jio_fprintf(defaultStream::error_stream(),
2858 2859 "Invalid maximum code cache size: %s.\n", option->optionString);
2859 2860 return JNI_EINVAL;
2860 2861 }
2861 2862 FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize);
2862 2863 // -XX:NonNMethodCodeHeapSize=
2863 2864 } else if (match_option(option, "-XX:NonNMethodCodeHeapSize=", &tail)) {
2864 2865 julong long_NonNMethodCodeHeapSize = 0;
2865 2866
2866 2867 ArgsRange errcode = parse_memory_size(tail, &long_NonNMethodCodeHeapSize, 1);
2867 2868 if (errcode != arg_in_range) {
2868 2869 jio_fprintf(defaultStream::error_stream(),
2869 2870 "Invalid maximum non-nmethod code heap size: %s.\n", option->optionString);
2870 2871 return JNI_EINVAL;
2871 2872 }
2872 2873 FLAG_SET_CMDLINE(uintx, NonNMethodCodeHeapSize, (uintx)long_NonNMethodCodeHeapSize);
2873 2874 // -XX:ProfiledCodeHeapSize=
2874 2875 } else if (match_option(option, "-XX:ProfiledCodeHeapSize=", &tail)) {
2875 2876 julong long_ProfiledCodeHeapSize = 0;
2876 2877
2877 2878 ArgsRange errcode = parse_memory_size(tail, &long_ProfiledCodeHeapSize, 1);
2878 2879 if (errcode != arg_in_range) {
2879 2880 jio_fprintf(defaultStream::error_stream(),
2880 2881 "Invalid maximum profiled code heap size: %s.\n", option->optionString);
2881 2882 return JNI_EINVAL;
2882 2883 }
2883 2884 FLAG_SET_CMDLINE(uintx, ProfiledCodeHeapSize, (uintx)long_ProfiledCodeHeapSize);
2884 2885 // -XX:NonProfiledCodeHeapSizee=
2885 2886 } else if (match_option(option, "-XX:NonProfiledCodeHeapSize=", &tail)) {
2886 2887 julong long_NonProfiledCodeHeapSize = 0;
2887 2888
2888 2889 ArgsRange errcode = parse_memory_size(tail, &long_NonProfiledCodeHeapSize, 1);
2889 2890 if (errcode != arg_in_range) {
2890 2891 jio_fprintf(defaultStream::error_stream(),
2891 2892 "Invalid maximum non-profiled code heap size: %s.\n", option->optionString);
2892 2893 return JNI_EINVAL;
2893 2894 }
2894 2895 FLAG_SET_CMDLINE(uintx, NonProfiledCodeHeapSize, (uintx)long_NonProfiledCodeHeapSize);
2895 2896 //-XX:IncreaseFirstTierCompileThresholdAt=
2896 2897 } else if (match_option(option, "-XX:IncreaseFirstTierCompileThresholdAt=", &tail)) {
2897 2898 uintx uint_IncreaseFirstTierCompileThresholdAt = 0;
2898 2899 if (!parse_uintx(tail, &uint_IncreaseFirstTierCompileThresholdAt, 0) || uint_IncreaseFirstTierCompileThresholdAt > 99) {
2899 2900 jio_fprintf(defaultStream::error_stream(),
2900 2901 "Invalid value for IncreaseFirstTierCompileThresholdAt: %s. Should be between 0 and 99.\n",
2901 2902 option->optionString);
2902 2903 return JNI_EINVAL;
2903 2904 }
2904 2905 FLAG_SET_CMDLINE(uintx, IncreaseFirstTierCompileThresholdAt, (uintx)uint_IncreaseFirstTierCompileThresholdAt);
2905 2906 // -green
2906 2907 } else if (match_option(option, "-green")) {
2907 2908 jio_fprintf(defaultStream::error_stream(),
2908 2909 "Green threads support not available\n");
2909 2910 return JNI_EINVAL;
2910 2911 // -native
2911 2912 } else if (match_option(option, "-native")) {
2912 2913 // HotSpot always uses native threads, ignore silently for compatibility
2913 2914 // -Xsqnopause
2914 2915 } else if (match_option(option, "-Xsqnopause")) {
2915 2916 // EVM option, ignore silently for compatibility
2916 2917 // -Xrs
2917 2918 } else if (match_option(option, "-Xrs")) {
2918 2919 // Classic/EVM option, new functionality
2919 2920 FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true);
2920 2921 } else if (match_option(option, "-Xusealtsigs")) {
2921 2922 // change default internal VM signals used - lower case for back compat
2922 2923 FLAG_SET_CMDLINE(bool, UseAltSigs, true);
2923 2924 // -Xoptimize
2924 2925 } else if (match_option(option, "-Xoptimize")) {
2925 2926 // EVM option, ignore silently for compatibility
2926 2927 // -Xprof
2927 2928 } else if (match_option(option, "-Xprof")) {
2928 2929 #if INCLUDE_FPROF
2929 2930 _has_profile = true;
2930 2931 #else // INCLUDE_FPROF
2931 2932 jio_fprintf(defaultStream::error_stream(),
2932 2933 "Flat profiling is not supported in this VM.\n");
2933 2934 return JNI_ERR;
2934 2935 #endif // INCLUDE_FPROF
2935 2936 // -Xconcurrentio
2936 2937 } else if (match_option(option, "-Xconcurrentio")) {
2937 2938 FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true);
2938 2939 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
2939 2940 FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1);
2940 2941 FLAG_SET_CMDLINE(bool, UseTLAB, false);
2941 2942 FLAG_SET_CMDLINE(size_t, NewSizeThreadIncrease, 16 * K); // 20Kb per thread added to new generation
2942 2943
2943 2944 // -Xinternalversion
2944 2945 } else if (match_option(option, "-Xinternalversion")) {
2945 2946 jio_fprintf(defaultStream::output_stream(), "%s\n",
2946 2947 VM_Version::internal_vm_info_string());
2947 2948 vm_exit(0);
2948 2949 #ifndef PRODUCT
2949 2950 // -Xprintflags
2950 2951 } else if (match_option(option, "-Xprintflags")) {
2951 2952 CommandLineFlags::printFlags(tty, false);
2952 2953 vm_exit(0);
2953 2954 #endif
2954 2955 // -D
2955 2956 } else if (match_option(option, "-D", &tail)) {
2956 2957 const char* value;
2957 2958 if (match_option(option, "-Djava.endorsed.dirs=", &value) &&
2958 2959 *value!= '\0' && strcmp(value, "\"\"") != 0) {
2959 2960 // abort if -Djava.endorsed.dirs is set
2960 2961 jio_fprintf(defaultStream::output_stream(),
2961 2962 "-Djava.endorsed.dirs=%s is not supported. Endorsed standards and standalone APIs\n"
2962 2963 "in modular form will be supported via the concept of upgradeable modules.\n", value);
2963 2964 return JNI_EINVAL;
2964 2965 }
2965 2966 if (match_option(option, "-Djava.ext.dirs=", &value) &&
2966 2967 *value != '\0' && strcmp(value, "\"\"") != 0) {
2967 2968 // abort if -Djava.ext.dirs is set
2968 2969 jio_fprintf(defaultStream::output_stream(),
2969 2970 "-Djava.ext.dirs=%s is not supported. Use -classpath instead.\n", value);
2970 2971 return JNI_EINVAL;
2971 2972 }
2972 2973
2973 2974 if (!add_property(tail)) {
2974 2975 return JNI_ENOMEM;
2975 2976 }
2976 2977 // Out of the box management support
2977 2978 if (match_option(option, "-Dcom.sun.management", &tail)) {
2978 2979 #if INCLUDE_MANAGEMENT
2979 2980 FLAG_SET_CMDLINE(bool, ManagementServer, true);
2980 2981 #else
2981 2982 jio_fprintf(defaultStream::output_stream(),
2982 2983 "-Dcom.sun.management is not supported in this VM.\n");
2983 2984 return JNI_ERR;
2984 2985 #endif
2985 2986 }
2986 2987 // -Xint
2987 2988 } else if (match_option(option, "-Xint")) {
2988 2989 set_mode_flags(_int);
2989 2990 // -Xmixed
2990 2991 } else if (match_option(option, "-Xmixed")) {
2991 2992 set_mode_flags(_mixed);
2992 2993 // -Xcomp
2993 2994 } else if (match_option(option, "-Xcomp")) {
2994 2995 // for testing the compiler; turn off all flags that inhibit compilation
2995 2996 set_mode_flags(_comp);
2996 2997 // -Xshare:dump
2997 2998 } else if (match_option(option, "-Xshare:dump")) {
2998 2999 FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
2999 3000 set_mode_flags(_int); // Prevent compilation, which creates objects
3000 3001 // -Xshare:on
3001 3002 } else if (match_option(option, "-Xshare:on")) {
3002 3003 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
3003 3004 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true);
3004 3005 // -Xshare:auto
3005 3006 } else if (match_option(option, "-Xshare:auto")) {
3006 3007 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
3007 3008 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
3008 3009 // -Xshare:off
3009 3010 } else if (match_option(option, "-Xshare:off")) {
3010 3011 FLAG_SET_CMDLINE(bool, UseSharedSpaces, false);
3011 3012 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
3012 3013 // -Xverify
3013 3014 } else if (match_option(option, "-Xverify", &tail)) {
3014 3015 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) {
3015 3016 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true);
3016 3017 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
3017 3018 } else if (strcmp(tail, ":remote") == 0) {
3018 3019 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
3019 3020 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
3020 3021 } else if (strcmp(tail, ":none") == 0) {
3021 3022 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
3022 3023 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false);
3023 3024 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) {
3024 3025 return JNI_EINVAL;
3025 3026 }
3026 3027 // -Xdebug
3027 3028 } else if (match_option(option, "-Xdebug")) {
3028 3029 // note this flag has been used, then ignore
3029 3030 set_xdebug_mode(true);
3030 3031 // -Xnoagent
3031 3032 } else if (match_option(option, "-Xnoagent")) {
3032 3033 // For compatibility with classic. HotSpot refuses to load the old style agent.dll.
3033 3034 } else if (match_option(option, "-Xboundthreads")) {
3034 3035 // Ignore silently for compatibility
3035 3036 } else if (match_option(option, "-Xloggc:", &tail)) {
3036 3037 // Redirect GC output to the file. -Xloggc:<filename>
3037 3038 // ostream_init_log(), when called will use this filename
3038 3039 // to initialize a fileStream.
3039 3040 _gc_log_filename = os::strdup_check_oom(tail);
3040 3041 if (!is_filename_valid(_gc_log_filename)) {
3041 3042 jio_fprintf(defaultStream::output_stream(),
3042 3043 "Invalid file name for use with -Xloggc: Filename can only contain the "
3043 3044 "characters [A-Z][a-z][0-9]-_.%%[p|t] but it has been %s\n"
3044 3045 "Note %%p or %%t can only be used once\n", _gc_log_filename);
3045 3046 return JNI_EINVAL;
3046 3047 }
3047 3048 FLAG_SET_CMDLINE(bool, PrintGC, true);
3048 3049 FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true);
3049 3050
3050 3051 // JNI hooks
3051 3052 } else if (match_option(option, "-Xcheck", &tail)) {
3052 3053 if (!strcmp(tail, ":jni")) {
3053 3054 #if !INCLUDE_JNI_CHECK
3054 3055 warning("JNI CHECKING is not supported in this VM");
3055 3056 #else
3056 3057 CheckJNICalls = true;
3057 3058 #endif // INCLUDE_JNI_CHECK
3058 3059 } else if (is_bad_option(option, args->ignoreUnrecognized,
3059 3060 "check")) {
3060 3061 return JNI_EINVAL;
3061 3062 }
3062 3063 } else if (match_option(option, "vfprintf")) {
3063 3064 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo);
3064 3065 } else if (match_option(option, "exit")) {
3065 3066 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
3066 3067 } else if (match_option(option, "abort")) {
3067 3068 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
3068 3069 // -XX:+AggressiveHeap
3069 3070 } else if (match_option(option, "-XX:+AggressiveHeap")) {
3070 3071
3071 3072 // This option inspects the machine and attempts to set various
3072 3073 // parameters to be optimal for long-running, memory allocation
3073 3074 // intensive jobs. It is intended for machines with large
3074 3075 // amounts of cpu and memory.
3075 3076
3076 3077 // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
3077 3078 // VM, but we may not be able to represent the total physical memory
3078 3079 // available (like having 8gb of memory on a box but using a 32bit VM).
3079 3080 // Thus, we need to make sure we're using a julong for intermediate
3080 3081 // calculations.
3081 3082 julong initHeapSize;
3082 3083 julong total_memory = os::physical_memory();
3083 3084
3084 3085 if (total_memory < (julong)256*M) {
3085 3086 jio_fprintf(defaultStream::error_stream(),
3086 3087 "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
3087 3088 vm_exit(1);
3088 3089 }
3089 3090
3090 3091 // The heap size is half of available memory, or (at most)
3091 3092 // all of possible memory less 160mb (leaving room for the OS
3092 3093 // when using ISM). This is the maximum; because adaptive sizing
3093 3094 // is turned on below, the actual space used may be smaller.
3094 3095
3095 3096 initHeapSize = MIN2(total_memory / (julong)2,
3096 3097 total_memory - (julong)160*M);
3097 3098
3098 3099 initHeapSize = limit_by_allocatable_memory(initHeapSize);
3099 3100
3100 3101 if (FLAG_IS_DEFAULT(MaxHeapSize)) {
3101 3102 FLAG_SET_CMDLINE(size_t, MaxHeapSize, initHeapSize);
3102 3103 FLAG_SET_CMDLINE(size_t, InitialHeapSize, initHeapSize);
3103 3104 // Currently the minimum size and the initial heap sizes are the same.
3104 3105 set_min_heap_size(initHeapSize);
3105 3106 }
3106 3107 if (FLAG_IS_DEFAULT(NewSize)) {
3107 3108 // Make the young generation 3/8ths of the total heap.
3108 3109 FLAG_SET_CMDLINE(size_t, NewSize,
3109 3110 ((julong)MaxHeapSize / (julong)8) * (julong)3);
3110 3111 FLAG_SET_CMDLINE(size_t, MaxNewSize, NewSize);
3111 3112 }
3112 3113
3113 3114 #if !defined(_ALLBSD_SOURCE) && !defined(AIX) // UseLargePages is not yet supported on BSD and AIX.
3114 3115 FLAG_SET_DEFAULT(UseLargePages, true);
3115 3116 #endif
3116 3117
3117 3118 // Increase some data structure sizes for efficiency
3118 3119 FLAG_SET_CMDLINE(size_t, BaseFootPrintEstimate, MaxHeapSize);
3119 3120 FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
3120 3121 FLAG_SET_CMDLINE(size_t, TLABSize, 256*K);
3121 3122
3122 3123 // See the OldPLABSize comment below, but replace 'after promotion'
3123 3124 // with 'after copying'. YoungPLABSize is the size of the survivor
3124 3125 // space per-gc-thread buffers. The default is 4kw.
3125 3126 FLAG_SET_CMDLINE(size_t, YoungPLABSize, 256*K); // Note: this is in words
3126 3127
3127 3128 // OldPLABSize is the size of the buffers in the old gen that
3128 3129 // UseParallelGC uses to promote live data that doesn't fit in the
3129 3130 // survivor spaces. At any given time, there's one for each gc thread.
3130 3131 // The default size is 1kw. These buffers are rarely used, since the
3131 3132 // survivor spaces are usually big enough. For specjbb, however, there
3132 3133 // are occasions when there's lots of live data in the young gen
3133 3134 // and we end up promoting some of it. We don't have a definite
3134 3135 // explanation for why bumping OldPLABSize helps, but the theory
3135 3136 // is that a bigger PLAB results in retaining something like the
3136 3137 // original allocation order after promotion, which improves mutator
3137 3138 // locality. A minor effect may be that larger PLABs reduce the
3138 3139 // number of PLAB allocation events during gc. The value of 8kw
3139 3140 // was arrived at by experimenting with specjbb.
3140 3141 FLAG_SET_CMDLINE(size_t, OldPLABSize, 8*K); // Note: this is in words
3141 3142
3142 3143 // Enable parallel GC and adaptive generation sizing
3143 3144 FLAG_SET_CMDLINE(bool, UseParallelGC, true);
3144 3145 FLAG_SET_DEFAULT(ParallelGCThreads,
3145 3146 Abstract_VM_Version::parallel_worker_threads());
3146 3147
3147 3148 // Encourage steady state memory management
3148 3149 FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
3149 3150
3150 3151 // This appears to improve mutator locality
3151 3152 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
3152 3153
3153 3154 // Get around early Solaris scheduling bug
3154 3155 // (affinity vs other jobs on system)
3155 3156 // but disallow DR and offlining (5008695).
3156 3157 FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
3157 3158
3158 3159 // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure;
3159 3160 // and the last option wins.
3160 3161 } else if (match_option(option, "-XX:+NeverTenure")) {
3161 3162 FLAG_SET_CMDLINE(bool, NeverTenure, true);
3162 3163 FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
3163 3164 FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1);
3164 3165 } else if (match_option(option, "-XX:+AlwaysTenure")) {
3165 3166 FLAG_SET_CMDLINE(bool, NeverTenure, false);
3166 3167 FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
3167 3168 FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0);
3168 3169 } else if (match_option(option, "-XX:MaxTenuringThreshold=", &tail)) {
3169 3170 uintx max_tenuring_thresh = 0;
3170 3171 if(!parse_uintx(tail, &max_tenuring_thresh, 0)) {
3171 3172 jio_fprintf(defaultStream::error_stream(),
3172 3173 "Improperly specified VM option 'MaxTenuringThreshold=%s'\n", tail);
3173 3174 return JNI_EINVAL;
3174 3175 }
3175 3176 FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, max_tenuring_thresh);
3176 3177
3177 3178 if (MaxTenuringThreshold == 0) {
3178 3179 FLAG_SET_CMDLINE(bool, NeverTenure, false);
3179 3180 FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
3180 3181 } else {
3181 3182 FLAG_SET_CMDLINE(bool, NeverTenure, false);
3182 3183 FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
3183 3184 }
3184 3185 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr")) {
3185 3186 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false);
3186 3187 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true);
3187 3188 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout")) {
3188 3189 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false);
3189 3190 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true);
3190 3191 } else if (match_option(option, "-XX:+ExtendedDTraceProbes")) {
3191 3192 #if defined(DTRACE_ENABLED)
3192 3193 FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true);
3193 3194 FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true);
3194 3195 FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true);
3195 3196 FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true);
3196 3197 #else // defined(DTRACE_ENABLED)
3197 3198 jio_fprintf(defaultStream::error_stream(),
3198 3199 "ExtendedDTraceProbes flag is not applicable for this configuration\n");
3199 3200 return JNI_EINVAL;
3200 3201 #endif // defined(DTRACE_ENABLED)
3201 3202 #ifdef ASSERT
3202 3203 } else if (match_option(option, "-XX:+FullGCALot")) {
3203 3204 FLAG_SET_CMDLINE(bool, FullGCALot, true);
3204 3205 // disable scavenge before parallel mark-compact
3205 3206 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
3206 3207 #endif
3207 3208 } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) ||
3208 3209 match_option(option, "-XX:G1MarkStackSize=", &tail)) {
3209 3210 julong stack_size = 0;
3210 3211 ArgsRange errcode = parse_memory_size(tail, &stack_size, 1);
3211 3212 if (errcode != arg_in_range) {
3212 3213 jio_fprintf(defaultStream::error_stream(),
3213 3214 "Invalid mark stack size: %s\n", option->optionString);
3214 3215 describe_range_error(errcode);
3215 3216 return JNI_EINVAL;
3216 3217 }
3217 3218 jio_fprintf(defaultStream::error_stream(),
3218 3219 "Please use -XX:MarkStackSize in place of "
3219 3220 "-XX:CMSMarkStackSize or -XX:G1MarkStackSize in the future\n");
3220 3221 FLAG_SET_CMDLINE(size_t, MarkStackSize, stack_size);
3221 3222 } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) {
3222 3223 julong max_stack_size = 0;
3223 3224 ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1);
3224 3225 if (errcode != arg_in_range) {
3225 3226 jio_fprintf(defaultStream::error_stream(),
3226 3227 "Invalid maximum mark stack size: %s\n",
3227 3228 option->optionString);
3228 3229 describe_range_error(errcode);
3229 3230 return JNI_EINVAL;
3230 3231 }
3231 3232 jio_fprintf(defaultStream::error_stream(),
3232 3233 "Please use -XX:MarkStackSizeMax in place of "
3233 3234 "-XX:CMSMarkStackSizeMax in the future\n");
3234 3235 FLAG_SET_CMDLINE(size_t, MarkStackSizeMax, max_stack_size);
3235 3236 } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) ||
3236 3237 match_option(option, "-XX:ParallelCMSThreads=", &tail)) {
3237 3238 uintx conc_threads = 0;
3238 3239 if (!parse_uintx(tail, &conc_threads, 1)) {
3239 3240 jio_fprintf(defaultStream::error_stream(),
3240 3241 "Invalid concurrent threads: %s\n", option->optionString);
3241 3242 return JNI_EINVAL;
3242 3243 }
3243 3244 jio_fprintf(defaultStream::error_stream(),
3244 3245 "Please use -XX:ConcGCThreads in place of "
3245 3246 "-XX:ParallelMarkingThreads or -XX:ParallelCMSThreads in the future\n");
3246 3247 FLAG_SET_CMDLINE(uint, ConcGCThreads, conc_threads);
3247 3248 } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) {
3248 3249 julong max_direct_memory_size = 0;
3249 3250 ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0);
3250 3251 if (errcode != arg_in_range) {
3251 3252 jio_fprintf(defaultStream::error_stream(),
3252 3253 "Invalid maximum direct memory size: %s\n",
3253 3254 option->optionString);
3254 3255 describe_range_error(errcode);
3255 3256 return JNI_EINVAL;
3256 3257 }
3257 3258 FLAG_SET_CMDLINE(size_t, MaxDirectMemorySize, max_direct_memory_size);
3258 3259 #if !INCLUDE_MANAGEMENT
3259 3260 } else if (match_option(option, "-XX:+ManagementServer")) {
3260 3261 jio_fprintf(defaultStream::error_stream(),
3261 3262 "ManagementServer is not supported in this VM.\n");
3262 3263 return JNI_ERR;
3263 3264 #endif // INCLUDE_MANAGEMENT
3264 3265 // CreateMinidumpOnCrash is removed, and replaced by CreateCoredumpOnCrash
3265 3266 } else if (match_option(option, "-XX:+CreateMinidumpOnCrash")) {
3266 3267 FLAG_SET_CMDLINE(bool, CreateCoredumpOnCrash, true);
3267 3268 jio_fprintf(defaultStream::output_stream(),
3268 3269 "CreateMinidumpOnCrash is replaced by CreateCoredumpOnCrash: CreateCoredumpOnCrash is on\n");
3269 3270 } else if (match_option(option, "-XX:-CreateMinidumpOnCrash")) {
3270 3271 FLAG_SET_CMDLINE(bool, CreateCoredumpOnCrash, false);
3271 3272 jio_fprintf(defaultStream::output_stream(),
3272 3273 "CreateMinidumpOnCrash is replaced by CreateCoredumpOnCrash: CreateCoredumpOnCrash is off\n");
3273 3274 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
3274 3275 // Skip -XX:Flags= since that case has already been handled
3275 3276 if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) {
3276 3277 if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
3277 3278 return JNI_EINVAL;
3278 3279 }
3279 3280 }
3280 3281 // Unknown option
3281 3282 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
3282 3283 return JNI_ERR;
3283 3284 }
3284 3285 }
3285 3286
3286 3287 // PrintSharedArchiveAndExit will turn on
3287 3288 // -Xshare:on
3288 3289 // -XX:+TraceClassPaths
3289 3290 if (PrintSharedArchiveAndExit) {
3290 3291 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
3291 3292 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true);
3292 3293 FLAG_SET_CMDLINE(bool, TraceClassPaths, true);
3293 3294 }
3294 3295
3295 3296 // Change the default value for flags which have different default values
3296 3297 // when working with older JDKs.
3297 3298 #ifdef LINUX
3298 3299 if (JDK_Version::current().compare_major(6) <= 0 &&
3299 3300 FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) {
3300 3301 FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false);
3301 3302 }
3302 3303 #endif // LINUX
3303 3304 fix_appclasspath();
3304 3305 return JNI_OK;
3305 3306 }
3306 3307
3307 3308 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
3308 3309 //
3309 3310 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
3310 3311 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
3311 3312 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
3312 3313 // path is treated as the current directory.
3313 3314 //
3314 3315 // This causes problems with CDS, which requires that all directories specified in the classpath
3315 3316 // must be empty. In most cases, applications do NOT want to load classes from the current
3316 3317 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
3317 3318 // scripts compatible with CDS.
3318 3319 void Arguments::fix_appclasspath() {
3319 3320 if (IgnoreEmptyClassPaths) {
3320 3321 const char separator = *os::path_separator();
3321 3322 const char* src = _java_class_path->value();
3322 3323
3323 3324 // skip over all the leading empty paths
3324 3325 while (*src == separator) {
3325 3326 src ++;
3326 3327 }
3327 3328
3328 3329 char* copy = os::strdup_check_oom(src, mtInternal);
3329 3330
3330 3331 // trim all trailing empty paths
3331 3332 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
3332 3333 *tail = '\0';
3333 3334 }
3334 3335
3335 3336 char from[3] = {separator, separator, '\0'};
3336 3337 char to [2] = {separator, '\0'};
3337 3338 while (StringUtils::replace_no_expand(copy, from, to) > 0) {
3338 3339 // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
3339 3340 // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
3340 3341 }
3341 3342
3342 3343 _java_class_path->set_value(copy);
3343 3344 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
3344 3345 }
3345 3346
3346 3347 if (!PrintSharedArchiveAndExit) {
3347 3348 ClassLoader::trace_class_path("[classpath: ", _java_class_path->value());
3348 3349 }
3349 3350 }
3350 3351
3351 3352 static bool has_jar_files(const char* directory) {
3352 3353 DIR* dir = os::opendir(directory);
3353 3354 if (dir == NULL) return false;
3354 3355
3355 3356 struct dirent *entry;
3356 3357 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal);
3357 3358 bool hasJarFile = false;
3358 3359 while (!hasJarFile && (entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
3359 3360 const char* name = entry->d_name;
3360 3361 const char* ext = name + strlen(name) - 4;
3361 3362 hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0);
3362 3363 }
3363 3364 FREE_C_HEAP_ARRAY(char, dbuf);
3364 3365 os::closedir(dir);
3365 3366 return hasJarFile ;
3366 3367 }
3367 3368
3368 3369 static int check_non_empty_dirs(const char* path) {
3369 3370 const char separator = *os::path_separator();
3370 3371 const char* const end = path + strlen(path);
3371 3372 int nonEmptyDirs = 0;
3372 3373 while (path < end) {
3373 3374 const char* tmp_end = strchr(path, separator);
3374 3375 if (tmp_end == NULL) {
3375 3376 if (has_jar_files(path)) {
3376 3377 nonEmptyDirs++;
3377 3378 jio_fprintf(defaultStream::output_stream(),
3378 3379 "Non-empty directory: %s\n", path);
3379 3380 }
3380 3381 path = end;
3381 3382 } else {
3382 3383 char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtInternal);
3383 3384 memcpy(dirpath, path, tmp_end - path);
3384 3385 dirpath[tmp_end - path] = '\0';
3385 3386 if (has_jar_files(dirpath)) {
3386 3387 nonEmptyDirs++;
3387 3388 jio_fprintf(defaultStream::output_stream(),
3388 3389 "Non-empty directory: %s\n", dirpath);
3389 3390 }
3390 3391 FREE_C_HEAP_ARRAY(char, dirpath);
3391 3392 path = tmp_end + 1;
3392 3393 }
3393 3394 }
3394 3395 return nonEmptyDirs;
3395 3396 }
3396 3397
3397 3398 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) {
3398 3399 // check if the default lib/endorsed directory exists; if so, error
3399 3400 char path[JVM_MAXPATHLEN];
3400 3401 const char* fileSep = os::file_separator();
3401 3402 sprintf(path, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
3402 3403
3403 3404 if (CheckEndorsedAndExtDirs) {
3404 3405 int nonEmptyDirs = 0;
3405 3406 // check endorsed directory
3406 3407 nonEmptyDirs += check_non_empty_dirs(path);
3407 3408 // check the extension directories
3408 3409 nonEmptyDirs += check_non_empty_dirs(Arguments::get_ext_dirs());
3409 3410 if (nonEmptyDirs > 0) {
3410 3411 return JNI_ERR;
3411 3412 }
3412 3413 }
3413 3414
3414 3415 DIR* dir = os::opendir(path);
3415 3416 if (dir != NULL) {
3416 3417 jio_fprintf(defaultStream::output_stream(),
3417 3418 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
3418 3419 "in modular form will be supported via the concept of upgradeable modules.\n");
3419 3420 os::closedir(dir);
3420 3421 return JNI_ERR;
3421 3422 }
3422 3423
3423 3424 sprintf(path, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
3424 3425 dir = os::opendir(path);
3425 3426 if (dir != NULL) {
3426 3427 jio_fprintf(defaultStream::output_stream(),
3427 3428 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
3428 3429 "Use -classpath instead.\n.");
3429 3430 os::closedir(dir);
3430 3431 return JNI_ERR;
3431 3432 }
3432 3433
3433 3434 if (scp_assembly_required) {
3434 3435 // Assemble the bootclasspath elements into the final path.
3435 3436 Arguments::set_sysclasspath(scp_p->combined_path());
3436 3437 }
3437 3438
3438 3439 // This must be done after all arguments have been processed.
3439 3440 // java_compiler() true means set to "NONE" or empty.
3440 3441 if (java_compiler() && !xdebug_mode()) {
3441 3442 // For backwards compatibility, we switch to interpreted mode if
3442 3443 // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was
3443 3444 // not specified.
3444 3445 set_mode_flags(_int);
3445 3446 }
3446 3447
3447 3448 // CompileThresholdScaling == 0.0 is same as -Xint: Disable compilation (enable interpreter-only mode),
3448 3449 // but like -Xint, leave compilation thresholds unaffected.
3449 3450 // With tiered compilation disabled, setting CompileThreshold to 0 disables compilation as well.
3450 3451 if ((CompileThresholdScaling == 0.0) || (!TieredCompilation && CompileThreshold == 0)) {
3451 3452 set_mode_flags(_int);
3452 3453 }
3453 3454
3454 3455 // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set
3455 3456 if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) {
3456 3457 FLAG_SET_ERGO(uintx, InitialTenuringThreshold, MaxTenuringThreshold);
3457 3458 }
3458 3459
3459 3460 #ifndef COMPILER2
3460 3461 // Don't degrade server performance for footprint
3461 3462 if (FLAG_IS_DEFAULT(UseLargePages) &&
3462 3463 MaxHeapSize < LargePageHeapSizeThreshold) {
3463 3464 // No need for large granularity pages w/small heaps.
3464 3465 // Note that large pages are enabled/disabled for both the
3465 3466 // Java heap and the code cache.
3466 3467 FLAG_SET_DEFAULT(UseLargePages, false);
3467 3468 }
3468 3469
3469 3470 #else
3470 3471 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
3471 3472 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
3472 3473 }
3473 3474 #endif
3474 3475
3475 3476 #ifndef TIERED
3476 3477 // Tiered compilation is undefined.
3477 3478 UNSUPPORTED_OPTION(TieredCompilation, "TieredCompilation");
3478 3479 #endif
3479 3480
3480 3481 // If we are running in a headless jre, force java.awt.headless property
3481 3482 // to be true unless the property has already been set.
3482 3483 // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state.
3483 3484 if (os::is_headless_jre()) {
3484 3485 const char* headless = Arguments::get_property("java.awt.headless");
3485 3486 if (headless == NULL) {
3486 3487 const char *headless_env = ::getenv("JAVA_AWT_HEADLESS");
3487 3488 if (headless_env == NULL) {
3488 3489 if (!add_property("java.awt.headless=true")) {
3489 3490 return JNI_ENOMEM;
3490 3491 }
3491 3492 } else {
3492 3493 char buffer[256];
3493 3494 jio_snprintf(buffer, sizeof(buffer), "java.awt.headless=%s", headless_env);
3494 3495 if (!add_property(buffer)) {
3495 3496 return JNI_ENOMEM;
3496 3497 }
3497 3498 }
3498 3499 }
3499 3500 }
3500 3501
3501 3502 if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) {
3502 3503 // CMS can only be used with ParNew
3503 3504 FLAG_SET_ERGO(bool, UseParNewGC, true);
3504 3505 }
3505 3506
3506 3507 if (!check_vm_args_consistency()) {
3507 3508 return JNI_ERR;
3508 3509 }
3509 3510
3510 3511 return JNI_OK;
3511 3512 }
3512 3513
3513 3514 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
3514 3515 return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
3515 3516 scp_assembly_required_p);
3516 3517 }
3517 3518
3518 3519 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
3519 3520 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p,
3520 3521 scp_assembly_required_p);
3521 3522 }
3522 3523
3523 3524 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) {
3524 3525 char *buffer = ::getenv(name);
3525 3526
3526 3527 // Don't check this variable if user has special privileges
3527 3528 // (e.g. unix su command).
3528 3529 if (buffer == NULL || os::have_special_privileges()) {
3529 3530 return JNI_OK;
3530 3531 }
3531 3532
3532 3533 if ((buffer = os::strdup(buffer)) == NULL) {
3533 3534 return JNI_ENOMEM;
3534 3535 }
3535 3536
3536 3537 GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaVMOption>(2, true); // Construct option array
3537 3538 jio_fprintf(defaultStream::error_stream(),
3538 3539 "Picked up %s: %s\n", name, buffer);
3539 3540 char* rd = buffer; // pointer to the input string (rd)
3540 3541 while (true) { // repeat for all options in the input string
3541 3542 while (isspace(*rd)) rd++; // skip whitespace
3542 3543 if (*rd == 0) break; // we re done when the input string is read completely
3543 3544
3544 3545 // The output, option string, overwrites the input string.
3545 3546 // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
3546 3547 // input string (rd).
3547 3548 char* wrt = rd;
3548 3549
3549 3550 JavaVMOption option;
3550 3551 option.optionString = wrt;
3551 3552 options->append(option); // Fill in option
3552 3553 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL
3553 3554 if (*rd == '\'' || *rd == '"') { // handle a quoted string
3554 3555 int quote = *rd; // matching quote to look for
3555 3556 rd++; // don't copy open quote
3556 3557 while (*rd != quote) { // include everything (even spaces) up until quote
3557 3558 if (*rd == 0) { // string termination means unmatched string
3558 3559 jio_fprintf(defaultStream::error_stream(),
3559 3560 "Unmatched quote in %s\n", name);
3560 3561 delete options;
3561 3562 os::free(buffer);
3562 3563 return JNI_ERR;
3563 3564 }
3564 3565 *wrt++ = *rd++; // copy to option string
3565 3566 }
3566 3567 rd++; // don't copy close quote
3567 3568 } else {
3568 3569 *wrt++ = *rd++; // copy to option string
3569 3570 }
3570 3571 }
3571 3572 // Need to check if we're done before writing a NULL,
3572 3573 // because the write could be to the byte that rd is pointing to.
3573 3574 if (*rd++ == 0) {
3574 3575 *wrt = 0;
3575 3576 break;
3576 3577 }
3577 3578 *wrt = 0; // Zero terminate option
3578 3579 }
3579 3580 JavaVMOption* options_arr =
3580 3581 NEW_C_HEAP_ARRAY_RETURN_NULL(JavaVMOption, options->length(), mtInternal);
3581 3582 if (options_arr == NULL) {
3582 3583 delete options;
3583 3584 os::free(buffer);
3584 3585 return JNI_ENOMEM;
3585 3586 }
3586 3587 for (int i = 0; i < options->length(); i++) {
3587 3588 options_arr[i] = options->at(i);
3588 3589 }
3589 3590
3590 3591 // Construct JavaVMInitArgs structure and parse as if it was part of the command line
3591 3592 JavaVMInitArgs vm_args;
3592 3593 vm_args.version = JNI_VERSION_1_2;
3593 3594 vm_args.options = options_arr;
3594 3595 vm_args.nOptions = options->length();
3595 3596 vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions;
3596 3597
3597 3598 if (PrintVMOptions) {
3598 3599 const char* tail;
3599 3600 for (int i = 0; i < vm_args.nOptions; i++) {
3600 3601 const JavaVMOption *option = vm_args.options + i;
3601 3602 if (match_option(option, "-XX:", &tail)) {
3602 3603 logOption(tail);
3603 3604 }
3604 3605 }
3605 3606 }
3606 3607
3607 3608 jint result = parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p,
3608 3609 Flag::ENVIRON_VAR);
3609 3610 FREE_C_HEAP_ARRAY(JavaVMOption, options_arr);
3610 3611 delete options;
3611 3612 os::free(buffer);
3612 3613 return result;
3613 3614 }
3614 3615
3615 3616 void Arguments::set_shared_spaces_flags() {
3616 3617 if (DumpSharedSpaces) {
3617 3618 if (RequireSharedSpaces) {
3618 3619 warning("cannot dump shared archive while using shared archive");
3619 3620 }
3620 3621 UseSharedSpaces = false;
3621 3622 #ifdef _LP64
3622 3623 if (!UseCompressedOops || !UseCompressedClassPointers) {
3623 3624 vm_exit_during_initialization(
3624 3625 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
3625 3626 }
3626 3627 } else {
3627 3628 if (!UseCompressedOops || !UseCompressedClassPointers) {
3628 3629 no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
3629 3630 }
3630 3631 #endif
3631 3632 }
3632 3633 }
3633 3634
3634 3635 #if !INCLUDE_ALL_GCS
3635 3636 static void force_serial_gc() {
3636 3637 FLAG_SET_DEFAULT(UseSerialGC, true);
3637 3638 UNSUPPORTED_GC_OPTION(UseG1GC);
3638 3639 UNSUPPORTED_GC_OPTION(UseParallelGC);
3639 3640 UNSUPPORTED_GC_OPTION(UseParallelOldGC);
3640 3641 UNSUPPORTED_GC_OPTION(UseConcMarkSweepGC);
3641 3642 UNSUPPORTED_GC_OPTION(UseParNewGC);
3642 3643 }
3643 3644 #endif // INCLUDE_ALL_GCS
3644 3645
3645 3646 // Sharing support
3646 3647 // Construct the path to the archive
3647 3648 static char* get_shared_archive_path() {
3648 3649 char *shared_archive_path;
3649 3650 if (SharedArchiveFile == NULL) {
3650 3651 char jvm_path[JVM_MAXPATHLEN];
3651 3652 os::jvm_path(jvm_path, sizeof(jvm_path));
3652 3653 char *end = strrchr(jvm_path, *os::file_separator());
3653 3654 if (end != NULL) *end = '\0';
3654 3655 size_t jvm_path_len = strlen(jvm_path);
3655 3656 size_t file_sep_len = strlen(os::file_separator());
3656 3657 const size_t len = jvm_path_len + file_sep_len + 20;
3657 3658 shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtInternal);
3658 3659 if (shared_archive_path != NULL) {
3659 3660 jio_snprintf(shared_archive_path, len, "%s%sclasses.jsa",
3660 3661 jvm_path, os::file_separator());
3661 3662 }
3662 3663 } else {
3663 3664 shared_archive_path = os::strdup_check_oom(SharedArchiveFile, mtInternal);
3664 3665 }
3665 3666 return shared_archive_path;
3666 3667 }
3667 3668
3668 3669 #ifndef PRODUCT
3669 3670 // Determine whether LogVMOutput should be implicitly turned on.
3670 3671 static bool use_vm_log() {
3671 3672 if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) ||
3672 3673 PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods ||
3673 3674 PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers ||
3674 3675 PrintAssembly || TraceDeoptimization || TraceDependencies ||
3675 3676 (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) {
3676 3677 return true;
3677 3678 }
3678 3679
3679 3680 #ifdef COMPILER1
3680 3681 if (PrintC1Statistics) {
3681 3682 return true;
3682 3683 }
3683 3684 #endif // COMPILER1
3684 3685
3685 3686 #ifdef COMPILER2
3686 3687 if (PrintOptoAssembly || PrintOptoStatistics) {
3687 3688 return true;
3688 3689 }
3689 3690 #endif // COMPILER2
3690 3691
3691 3692 return false;
3692 3693 }
3693 3694 #endif // PRODUCT
3694 3695
3695 3696 // Parse entry point called from JNI_CreateJavaVM
3696 3697
3697 3698 jint Arguments::parse(const JavaVMInitArgs* args) {
3698 3699
3699 3700 // Remaining part of option string
3700 3701 const char* tail;
3701 3702
3702 3703 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3703 3704 const char* hotspotrc = ".hotspotrc";
3704 3705 bool settings_file_specified = false;
3705 3706 bool needs_hotspotrc_warning = false;
3706 3707
3707 3708 const char* flags_file;
3708 3709 int index;
3709 3710 for (index = 0; index < args->nOptions; index++) {
3710 3711 const JavaVMOption *option = args->options + index;
3711 3712 if (ArgumentsExt::process_options(option)) {
3712 3713 continue;
3713 3714 }
3714 3715 if (match_option(option, "-XX:Flags=", &tail)) {
3715 3716 flags_file = tail;
3716 3717 settings_file_specified = true;
3717 3718 continue;
3718 3719 }
3719 3720 if (match_option(option, "-XX:+PrintVMOptions")) {
3720 3721 PrintVMOptions = true;
3721 3722 continue;
3722 3723 }
3723 3724 if (match_option(option, "-XX:-PrintVMOptions")) {
3724 3725 PrintVMOptions = false;
3725 3726 continue;
3726 3727 }
3727 3728 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) {
3728 3729 IgnoreUnrecognizedVMOptions = true;
3729 3730 continue;
3730 3731 }
3731 3732 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) {
3732 3733 IgnoreUnrecognizedVMOptions = false;
3733 3734 continue;
3734 3735 }
3735 3736 if (match_option(option, "-XX:+PrintFlagsInitial")) {
3736 3737 CommandLineFlags::printFlags(tty, false);
3737 3738 vm_exit(0);
3738 3739 }
3739 3740 if (match_option(option, "-XX:NativeMemoryTracking", &tail)) {
3740 3741 #if INCLUDE_NMT
3741 3742 // The launcher did not setup nmt environment variable properly.
3742 3743 if (!MemTracker::check_launcher_nmt_support(tail)) {
3743 3744 warning("Native Memory Tracking did not setup properly, using wrong launcher?");
3744 3745 }
3745 3746
3746 3747 // Verify if nmt option is valid.
3747 3748 if (MemTracker::verify_nmt_option()) {
3748 3749 // Late initialization, still in single-threaded mode.
3749 3750 if (MemTracker::tracking_level() >= NMT_summary) {
3750 3751 MemTracker::init();
3751 3752 }
3752 3753 } else {
3753 3754 vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL);
3754 3755 }
3755 3756 continue;
3756 3757 #else
3757 3758 jio_fprintf(defaultStream::error_stream(),
3758 3759 "Native Memory Tracking is not supported in this VM\n");
3759 3760 return JNI_ERR;
3760 3761 #endif
3761 3762 }
3762 3763
3763 3764 #ifndef PRODUCT
3764 3765 if (match_option(option, "-XX:+PrintFlagsWithComments")) {
3765 3766 CommandLineFlags::printFlags(tty, true);
3766 3767 vm_exit(0);
3767 3768 }
3768 3769 #endif
3769 3770 }
3770 3771
3771 3772 if (IgnoreUnrecognizedVMOptions) {
3772 3773 // uncast const to modify the flag args->ignoreUnrecognized
3773 3774 *(jboolean*)(&args->ignoreUnrecognized) = true;
3774 3775 }
3775 3776
3776 3777 // Parse specified settings file
3777 3778 if (settings_file_specified) {
3778 3779 if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) {
3779 3780 return JNI_EINVAL;
3780 3781 }
3781 3782 } else {
3782 3783 #ifdef ASSERT
3783 3784 // Parse default .hotspotrc settings file
3784 3785 if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) {
3785 3786 return JNI_EINVAL;
3786 3787 }
3787 3788 #else
3788 3789 struct stat buf;
3789 3790 if (os::stat(hotspotrc, &buf) == 0) {
3790 3791 needs_hotspotrc_warning = true;
3791 3792 }
3792 3793 #endif
3793 3794 }
3794 3795
3795 3796 if (PrintVMOptions) {
3796 3797 for (index = 0; index < args->nOptions; index++) {
3797 3798 const JavaVMOption *option = args->options + index;
3798 3799 if (match_option(option, "-XX:", &tail)) {
3799 3800 logOption(tail);
3800 3801 }
3801 3802 }
3802 3803 }
3803 3804
3804 3805 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
3805 3806 jint result = parse_vm_init_args(args);
3806 3807 if (result != JNI_OK) {
3807 3808 return result;
3808 3809 }
3809 3810
3810 3811 // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed.
3811 3812 SharedArchivePath = get_shared_archive_path();
3812 3813 if (SharedArchivePath == NULL) {
3813 3814 return JNI_ENOMEM;
3814 3815 }
3815 3816
3816 3817 // Set up VerifySharedSpaces
3817 3818 if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) {
3818 3819 VerifySharedSpaces = true;
3819 3820 }
3820 3821
3821 3822 // Delay warning until here so that we've had a chance to process
3822 3823 // the -XX:-PrintWarnings flag
3823 3824 if (needs_hotspotrc_warning) {
3824 3825 warning("%s file is present but has been ignored. "
3825 3826 "Run with -XX:Flags=%s to load the file.",
3826 3827 hotspotrc, hotspotrc);
3827 3828 }
3828 3829
3829 3830 #if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX.
3830 3831 UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages");
3831 3832 #endif
3832 3833
3833 3834 ArgumentsExt::report_unsupported_options();
3834 3835
3835 3836 #ifndef PRODUCT
3836 3837 if (TraceBytecodesAt != 0) {
3837 3838 TraceBytecodes = true;
3838 3839 }
3839 3840 if (CountCompiledCalls) {
3840 3841 if (UseCounterDecay) {
3841 3842 warning("UseCounterDecay disabled because CountCalls is set");
3842 3843 UseCounterDecay = false;
3843 3844 }
3844 3845 }
3845 3846 #endif // PRODUCT
3846 3847
3847 3848 if (ScavengeRootsInCode == 0) {
3848 3849 if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) {
3849 3850 warning("forcing ScavengeRootsInCode non-zero");
3850 3851 }
3851 3852 ScavengeRootsInCode = 1;
3852 3853 }
3853 3854
3854 3855 if (PrintGCDetails) {
3855 3856 // Turn on -verbose:gc options as well
3856 3857 PrintGC = true;
3857 3858 }
3858 3859
3859 3860 // Set object alignment values.
3860 3861 set_object_alignment();
3861 3862
3862 3863 #if !INCLUDE_ALL_GCS
3863 3864 force_serial_gc();
3864 3865 #endif // INCLUDE_ALL_GCS
3865 3866 #if !INCLUDE_CDS
3866 3867 if (DumpSharedSpaces || RequireSharedSpaces) {
3867 3868 jio_fprintf(defaultStream::error_stream(),
3868 3869 "Shared spaces are not supported in this VM\n");
3869 3870 return JNI_ERR;
3870 3871 }
3871 3872 if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) {
3872 3873 warning("Shared spaces are not supported in this VM");
3873 3874 FLAG_SET_DEFAULT(UseSharedSpaces, false);
3874 3875 FLAG_SET_DEFAULT(PrintSharedSpaces, false);
3875 3876 }
3876 3877 no_shared_spaces("CDS Disabled");
3877 3878 #endif // INCLUDE_CDS
3878 3879
3879 3880 return JNI_OK;
3880 3881 }
3881 3882
3882 3883 jint Arguments::apply_ergo() {
3883 3884
3884 3885 // Set flags based on ergonomics.
3885 3886 set_ergonomics_flags();
3886 3887
3887 3888 set_shared_spaces_flags();
3888 3889
3889 3890 // Check the GC selections again.
3890 3891 if (!check_gc_consistency()) {
3891 3892 return JNI_EINVAL;
3892 3893 }
3893 3894
3894 3895 if (TieredCompilation) {
3895 3896 set_tiered_flags();
3896 3897 } else {
3897 3898 // Check if the policy is valid. Policies 0 and 1 are valid for non-tiered setup.
3898 3899 if (CompilationPolicyChoice >= 2) {
3899 3900 vm_exit_during_initialization(
3900 3901 "Incompatible compilation policy selected", NULL);
3901 3902 }
3902 3903 // Scale CompileThreshold
3903 3904 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves CompileThreshold unchanged.
3904 3905 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) {
3905 3906 FLAG_SET_ERGO(intx, CompileThreshold, scaled_compile_threshold(CompileThreshold));
3906 3907 }
3907 3908 }
3908 3909
3909 3910 #ifdef COMPILER2
3910 3911 #ifndef PRODUCT
3911 3912 if (PrintIdealGraphLevel > 0) {
3912 3913 FLAG_SET_ERGO(bool, PrintIdealGraph, true);
3913 3914 }
3914 3915 #endif
3915 3916 #endif
3916 3917
3917 3918 // Set heap size based on available physical memory
3918 3919 set_heap_size();
3919 3920
3920 3921 ArgumentsExt::set_gc_specific_flags();
3921 3922
3922 3923 // Initialize Metaspace flags and alignments
3923 3924 Metaspace::ergo_initialize();
3924 3925
3925 3926 // Set bytecode rewriting flags
3926 3927 set_bytecode_flags();
3927 3928
3928 3929 // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled
3929 3930 set_aggressive_opts_flags();
3930 3931
3931 3932 // Turn off biased locking for locking debug mode flags,
3932 3933 // which are subtly different from each other but neither works with
3933 3934 // biased locking
3934 3935 if (UseHeavyMonitors
3935 3936 #ifdef COMPILER1
3936 3937 || !UseFastLocking
3937 3938 #endif // COMPILER1
3938 3939 ) {
3939 3940 if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) {
3940 3941 // flag set to true on command line; warn the user that they
3941 3942 // can't enable biased locking here
3942 3943 warning("Biased Locking is not supported with locking debug flags"
3943 3944 "; ignoring UseBiasedLocking flag." );
3944 3945 }
3945 3946 UseBiasedLocking = false;
3946 3947 }
3947 3948
3948 3949 #ifdef ZERO
3949 3950 // Clear flags not supported on zero.
3950 3951 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3951 3952 FLAG_SET_DEFAULT(UseBiasedLocking, false);
3952 3953 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false));
3953 3954 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedClassPointers, false));
3954 3955 #endif // CC_INTERP
3955 3956
3956 3957 #ifdef COMPILER2
3957 3958 if (!EliminateLocks) {
3958 3959 EliminateNestedLocks = false;
3959 3960 }
3960 3961 if (!Inline) {
3961 3962 IncrementalInline = false;
3962 3963 }
3963 3964 #ifndef PRODUCT
3964 3965 if (!IncrementalInline) {
3965 3966 AlwaysIncrementalInline = false;
3966 3967 }
3967 3968 #endif
3968 3969 if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) {
3969 3970 // nothing to use the profiling, turn if off
3970 3971 FLAG_SET_DEFAULT(TypeProfileLevel, 0);
3971 3972 }
3972 3973 #endif
3973 3974
3974 3975 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3975 3976 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3976 3977 DebugNonSafepoints = true;
3977 3978 }
3978 3979
3979 3980 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3980 3981 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3981 3982 }
3982 3983
3983 3984 #ifndef PRODUCT
3984 3985 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3985 3986 if (use_vm_log()) {
3986 3987 LogVMOutput = true;
3987 3988 }
3988 3989 }
3989 3990 #endif // PRODUCT
3990 3991
3991 3992 if (PrintCommandLineFlags) {
3992 3993 CommandLineFlags::printSetFlags(tty);
3993 3994 }
3994 3995
3995 3996 // Apply CPU specific policy for the BiasedLocking
3996 3997 if (UseBiasedLocking) {
3997 3998 if (!VM_Version::use_biased_locking() &&
3998 3999 !(FLAG_IS_CMDLINE(UseBiasedLocking))) {
3999 4000 UseBiasedLocking = false;
4000 4001 }
4001 4002 }
4002 4003 #ifdef COMPILER2
4003 4004 if (!UseBiasedLocking || EmitSync != 0) {
4004 4005 UseOptoBiasInlining = false;
4005 4006 }
4006 4007 #endif
4007 4008
4008 4009 return JNI_OK;
4009 4010 }
4010 4011
4011 4012 jint Arguments::adjust_after_os() {
4012 4013 if (UseNUMA) {
4013 4014 if (UseParallelGC || UseParallelOldGC) {
4014 4015 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) {
4015 4016 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M);
4016 4017 }
4017 4018 }
4018 4019 // UseNUMAInterleaving is set to ON for all collectors and
4019 4020 // platforms when UseNUMA is set to ON. NUMA-aware collectors
4020 4021 // such as the parallel collector for Linux and Solaris will
4021 4022 // interleave old gen and survivor spaces on top of NUMA
4022 4023 // allocation policy for the eden space.
4023 4024 // Non NUMA-aware collectors such as CMS, G1 and Serial-GC on
4024 4025 // all platforms and ParallelGC on Windows will interleave all
4025 4026 // of the heap spaces across NUMA nodes.
4026 4027 if (FLAG_IS_DEFAULT(UseNUMAInterleaving)) {
4027 4028 FLAG_SET_ERGO(bool, UseNUMAInterleaving, true);
4028 4029 }
4029 4030 }
4030 4031 return JNI_OK;
4031 4032 }
4032 4033
4033 4034 int Arguments::PropertyList_count(SystemProperty* pl) {
4034 4035 int count = 0;
4035 4036 while(pl != NULL) {
4036 4037 count++;
4037 4038 pl = pl->next();
4038 4039 }
4039 4040 return count;
4040 4041 }
4041 4042
4042 4043 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) {
4043 4044 assert(key != NULL, "just checking");
4044 4045 SystemProperty* prop;
4045 4046 for (prop = pl; prop != NULL; prop = prop->next()) {
4046 4047 if (strcmp(key, prop->key()) == 0) return prop->value();
4047 4048 }
4048 4049 return NULL;
4049 4050 }
4050 4051
4051 4052 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) {
4052 4053 int count = 0;
4053 4054 const char* ret_val = NULL;
4054 4055
4055 4056 while(pl != NULL) {
4056 4057 if(count >= index) {
4057 4058 ret_val = pl->key();
4058 4059 break;
4059 4060 }
4060 4061 count++;
4061 4062 pl = pl->next();
4062 4063 }
4063 4064
4064 4065 return ret_val;
4065 4066 }
4066 4067
4067 4068 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) {
4068 4069 int count = 0;
4069 4070 char* ret_val = NULL;
4070 4071
4071 4072 while(pl != NULL) {
4072 4073 if(count >= index) {
4073 4074 ret_val = pl->value();
4074 4075 break;
4075 4076 }
4076 4077 count++;
4077 4078 pl = pl->next();
4078 4079 }
4079 4080
4080 4081 return ret_val;
4081 4082 }
4082 4083
4083 4084 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) {
4084 4085 SystemProperty* p = *plist;
4085 4086 if (p == NULL) {
4086 4087 *plist = new_p;
4087 4088 } else {
4088 4089 while (p->next() != NULL) {
4089 4090 p = p->next();
4090 4091 }
4091 4092 p->set_next(new_p);
4092 4093 }
4093 4094 }
4094 4095
4095 4096 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) {
4096 4097 if (plist == NULL)
4097 4098 return;
4098 4099
4099 4100 SystemProperty* new_p = new SystemProperty(k, v, true);
4100 4101 PropertyList_add(plist, new_p);
4101 4102 }
4102 4103
4103 4104 void Arguments::PropertyList_add(SystemProperty *element) {
4104 4105 PropertyList_add(&_system_properties, element);
4105 4106 }
4106 4107
4107 4108 // This add maintains unique property key in the list.
4108 4109 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append) {
4109 4110 if (plist == NULL)
4110 4111 return;
4111 4112
4112 4113 // If property key exist then update with new value.
4113 4114 SystemProperty* prop;
4114 4115 for (prop = *plist; prop != NULL; prop = prop->next()) {
4115 4116 if (strcmp(k, prop->key()) == 0) {
4116 4117 if (append) {
4117 4118 prop->append_value(v);
4118 4119 } else {
4119 4120 prop->set_value(v);
4120 4121 }
4121 4122 return;
4122 4123 }
4123 4124 }
4124 4125
4125 4126 PropertyList_add(plist, k, v);
4126 4127 }
4127 4128
4128 4129 // Copies src into buf, replacing "%%" with "%" and "%p" with pid
4129 4130 // Returns true if all of the source pointed by src has been copied over to
4130 4131 // the destination buffer pointed by buf. Otherwise, returns false.
4131 4132 // Notes:
4132 4133 // 1. If the length (buflen) of the destination buffer excluding the
4133 4134 // NULL terminator character is not long enough for holding the expanded
4134 4135 // pid characters, it also returns false instead of returning the partially
4135 4136 // expanded one.
4136 4137 // 2. The passed in "buflen" should be large enough to hold the null terminator.
4137 4138 bool Arguments::copy_expand_pid(const char* src, size_t srclen,
4138 4139 char* buf, size_t buflen) {
4139 4140 const char* p = src;
4140 4141 char* b = buf;
4141 4142 const char* src_end = &src[srclen];
4142 4143 char* buf_end = &buf[buflen - 1];
4143 4144
4144 4145 while (p < src_end && b < buf_end) {
4145 4146 if (*p == '%') {
4146 4147 switch (*(++p)) {
4147 4148 case '%': // "%%" ==> "%"
4148 4149 *b++ = *p++;
4149 4150 break;
4150 4151 case 'p': { // "%p" ==> current process id
4151 4152 // buf_end points to the character before the last character so
4152 4153 // that we could write '\0' to the end of the buffer.
4153 4154 size_t buf_sz = buf_end - b + 1;
4154 4155 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id());
4155 4156
4156 4157 // if jio_snprintf fails or the buffer is not long enough to hold
4157 4158 // the expanded pid, returns false.
4158 4159 if (ret < 0 || ret >= (int)buf_sz) {
4159 4160 return false;
4160 4161 } else {
4161 4162 b += ret;
4162 4163 assert(*b == '\0', "fail in copy_expand_pid");
4163 4164 if (p == src_end && b == buf_end + 1) {
4164 4165 // reach the end of the buffer.
4165 4166 return true;
4166 4167 }
4167 4168 }
4168 4169 p++;
4169 4170 break;
4170 4171 }
4171 4172 default :
4172 4173 *b++ = '%';
4173 4174 }
4174 4175 } else {
4175 4176 *b++ = *p++;
4176 4177 }
4177 4178 }
4178 4179 *b = '\0';
4179 4180 return (p == src_end); // return false if not all of the source was copied
4180 4181 }
↓ open down ↓ |
1417 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX