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