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