Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/runtime/flags/jvmFlag.cpp
40957 views
1
/*
2
* Copyright (c) 1997, 2021, 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 "jvm_io.h"
27
#include "jfr/jfrEvents.hpp"
28
#include "memory/allocation.inline.hpp"
29
#include "runtime/arguments.hpp"
30
#include "runtime/flags/jvmFlag.hpp"
31
#include "runtime/flags/jvmFlagAccess.hpp"
32
#include "runtime/flags/jvmFlagLookup.hpp"
33
#include "runtime/globals_extension.hpp"
34
#include "utilities/defaultStream.hpp"
35
#include "utilities/stringUtils.hpp"
36
37
static bool is_product_build() {
38
#ifdef PRODUCT
39
return true;
40
#else
41
return false;
42
#endif
43
}
44
45
void JVMFlag::set_origin(JVMFlagOrigin new_origin) {
46
int old_flags = _flags;
47
int origin = static_cast<int>(new_origin);
48
assert((origin & VALUE_ORIGIN_MASK) == origin, "sanity");
49
int was_in_cmdline = (new_origin == JVMFlagOrigin::COMMAND_LINE) ? WAS_SET_ON_COMMAND_LINE : 0;
50
_flags = Flags((_flags & ~VALUE_ORIGIN_MASK) | origin | was_in_cmdline);
51
if ((old_flags & WAS_SET_ON_COMMAND_LINE) != 0) {
52
assert((_flags & WAS_SET_ON_COMMAND_LINE) != 0, "once initialized, should never change");
53
}
54
}
55
56
/**
57
* Returns if this flag is a constant in the binary. Right now this is
58
* true for notproduct and develop flags in product builds.
59
*/
60
bool JVMFlag::is_constant_in_binary() const {
61
#ifdef PRODUCT
62
return is_notproduct() || is_develop();
63
#else
64
return false;
65
#endif
66
}
67
68
bool JVMFlag::is_unlocker() const {
69
return strcmp(_name, "UnlockDiagnosticVMOptions") == 0 ||
70
strcmp(_name, "UnlockExperimentalVMOptions") == 0;
71
}
72
73
bool JVMFlag::is_unlocked() const {
74
if (is_diagnostic()) {
75
return UnlockDiagnosticVMOptions;
76
}
77
if (is_experimental()) {
78
return UnlockExperimentalVMOptions;
79
}
80
return true;
81
}
82
83
void JVMFlag::clear_diagnostic() {
84
assert(is_diagnostic(), "sanity");
85
_flags = Flags(_flags & ~KIND_DIAGNOSTIC);
86
assert(!is_diagnostic(), "sanity");
87
}
88
89
void JVMFlag::clear_experimental() {
90
assert(is_experimental(), "sanity");
91
_flags = Flags(_flags & ~KIND_EXPERIMENTAL);
92
assert(!is_experimental(), "sanity");
93
}
94
95
void JVMFlag::set_product() {
96
assert(!is_product(), "sanity");
97
_flags = Flags(_flags | KIND_PRODUCT);
98
assert(is_product(), "sanity");
99
}
100
101
// Get custom message for this locked flag, or NULL if
102
// none is available. Returns message type produced.
103
JVMFlag::MsgType JVMFlag::get_locked_message(char* buf, int buflen) const {
104
buf[0] = '\0';
105
if (is_diagnostic() && !is_unlocked()) {
106
jio_snprintf(buf, buflen,
107
"Error: VM option '%s' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.\n"
108
"Error: The unlock option must precede '%s'.\n",
109
_name, _name);
110
return JVMFlag::DIAGNOSTIC_FLAG_BUT_LOCKED;
111
}
112
if (is_experimental() && !is_unlocked()) {
113
jio_snprintf(buf, buflen,
114
"Error: VM option '%s' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.\n"
115
"Error: The unlock option must precede '%s'.\n",
116
_name, _name);
117
return JVMFlag::EXPERIMENTAL_FLAG_BUT_LOCKED;
118
}
119
if (is_develop() && is_product_build()) {
120
jio_snprintf(buf, buflen, "Error: VM option '%s' is develop and is available only in debug version of VM.\n",
121
_name);
122
return JVMFlag::DEVELOPER_FLAG_BUT_PRODUCT_BUILD;
123
}
124
if (is_notproduct() && is_product_build()) {
125
jio_snprintf(buf, buflen, "Error: VM option '%s' is notproduct and is available only in debug version of VM.\n",
126
_name);
127
return JVMFlag::NOTPRODUCT_FLAG_BUT_PRODUCT_BUILD;
128
}
129
return JVMFlag::NONE;
130
}
131
132
// Helper function for JVMFlag::print_on().
133
// Fills current line up to requested position.
134
// Should the current position already be past the requested position,
135
// one separator blank is enforced.
136
void fill_to_pos(outputStream* st, unsigned int req_pos) {
137
if ((unsigned int)st->position() < req_pos) {
138
st->fill_to(req_pos); // need to fill with blanks to reach req_pos
139
} else {
140
st->print(" "); // enforce blank separation. Previous field too long.
141
}
142
}
143
144
void JVMFlag::print_on(outputStream* st, bool withComments, bool printRanges) const {
145
// Don't print notproduct and develop flags in a product build.
146
if (is_constant_in_binary()) {
147
return;
148
}
149
150
if (!printRanges) {
151
// The command line options -XX:+PrintFlags* cause this function to be called
152
// for each existing flag to print information pertinent to this flag. The data
153
// is displayed in columnar form, with the following layout:
154
// col1 - data type, right-justified
155
// col2 - name, left-justified
156
// col3 - ' =' double-char, leading space to align with possible '+='
157
// col4 - value left-justified
158
// col5 - kind right-justified
159
// col6 - origin left-justified
160
// col7 - comments left-justified
161
//
162
// The column widths are fixed. They are defined such that, for most cases,
163
// an eye-pleasing tabular output is created.
164
//
165
// Sample output:
166
// bool ThreadPriorityVerbose = false {product} {default}
167
// uintx ThresholdTolerance = 10 {product} {default}
168
// size_t TLABSize = 0 {product} {default}
169
// uintx SurvivorRatio = 8 {product} {default}
170
// double InitialRAMPercentage = 1.562500 {product} {default}
171
// ccstr CompileCommandFile = MyFile.cmd {product} {command line}
172
// ccstrlist CompileOnly = Method1
173
// CompileOnly += Method2 {product} {command line}
174
// | | | | | | |
175
// | | | | | | +-- col7
176
// | | | | | +-- col6
177
// | | | | +-- col5
178
// | | | +-- col4
179
// | | +-- col3
180
// | +-- col2
181
// +-- col1
182
183
const unsigned int col_spacing = 1;
184
const unsigned int col1_pos = 0;
185
const unsigned int col1_width = 9;
186
const unsigned int col2_pos = col1_pos + col1_width + col_spacing;
187
const unsigned int col2_width = 39;
188
const unsigned int col3_pos = col2_pos + col2_width + col_spacing;
189
const unsigned int col3_width = 2;
190
const unsigned int col4_pos = col3_pos + col3_width + col_spacing;
191
const unsigned int col4_width = 30;
192
const unsigned int col5_pos = col4_pos + col4_width + col_spacing;
193
const unsigned int col5_width = 20;
194
const unsigned int col6_pos = col5_pos + col5_width + col_spacing;
195
const unsigned int col6_width = 15;
196
const unsigned int col7_pos = col6_pos + col6_width + col_spacing;
197
const unsigned int col7_width = 1;
198
199
st->fill_to(col1_pos);
200
st->print("%*s", col1_width, type_string()); // right-justified, therefore width is required.
201
202
fill_to_pos(st, col2_pos);
203
st->print("%s", _name);
204
205
fill_to_pos(st, col3_pos);
206
st->print(" ="); // use " =" for proper alignment with multiline ccstr output.
207
208
fill_to_pos(st, col4_pos);
209
if (is_bool()) {
210
st->print("%s", get_bool() ? "true" : "false");
211
} else if (is_int()) {
212
st->print("%d", get_int());
213
} else if (is_uint()) {
214
st->print("%u", get_uint());
215
} else if (is_intx()) {
216
st->print(INTX_FORMAT, get_intx());
217
} else if (is_uintx()) {
218
st->print(UINTX_FORMAT, get_uintx());
219
} else if (is_uint64_t()) {
220
st->print(UINT64_FORMAT, get_uint64_t());
221
} else if (is_size_t()) {
222
st->print(SIZE_FORMAT, get_size_t());
223
} else if (is_double()) {
224
st->print("%f", get_double());
225
} else if (is_ccstr()) {
226
// Honor <newline> characters in ccstr: print multiple lines.
227
const char* cp = get_ccstr();
228
if (cp != NULL) {
229
const char* eol;
230
while ((eol = strchr(cp, '\n')) != NULL) {
231
size_t llen = pointer_delta(eol, cp, sizeof(char));
232
st->print("%.*s", (int)llen, cp);
233
st->cr();
234
cp = eol+1;
235
fill_to_pos(st, col2_pos);
236
st->print("%s", _name);
237
fill_to_pos(st, col3_pos);
238
st->print("+=");
239
fill_to_pos(st, col4_pos);
240
}
241
st->print("%s", cp);
242
}
243
} else {
244
st->print("unhandled type %s", type_string());
245
st->cr();
246
return;
247
}
248
249
fill_to_pos(st, col5_pos);
250
print_kind(st, col5_width);
251
252
fill_to_pos(st, col6_pos);
253
print_origin(st, col6_width);
254
255
#ifndef PRODUCT
256
if (withComments) {
257
fill_to_pos(st, col7_pos);
258
st->print("%s", _doc);
259
}
260
#endif
261
st->cr();
262
} else if (!is_bool() && !is_ccstr()) {
263
// The command line options -XX:+PrintFlags* cause this function to be called
264
// for each existing flag to print information pertinent to this flag. The data
265
// is displayed in columnar form, with the following layout:
266
// col1 - data type, right-justified
267
// col2 - name, left-justified
268
// col4 - range [ min ... max]
269
// col5 - kind right-justified
270
// col6 - origin left-justified
271
// col7 - comments left-justified
272
//
273
// The column widths are fixed. They are defined such that, for most cases,
274
// an eye-pleasing tabular output is created.
275
//
276
// Sample output:
277
// intx MinPassesBeforeFlush [ 0 ... 9223372036854775807 ] {diagnostic} {default}
278
// uintx MinRAMFraction [ 1 ... 18446744073709551615 ] {product} {default}
279
// double MinRAMPercentage [ 0.000 ... 100.000 ] {product} {default}
280
// uintx MinSurvivorRatio [ 3 ... 18446744073709551615 ] {product} {default}
281
// size_t MinTLABSize [ 1 ... 9223372036854775807 ] {product} {default}
282
// intx MaxInlineSize [ 0 ... 2147483647 ] {product} {default}
283
// | | | | | |
284
// | | | | | +-- col7
285
// | | | | +-- col6
286
// | | | +-- col5
287
// | | +-- col4
288
// | +-- col2
289
// +-- col1
290
291
const unsigned int col_spacing = 1;
292
const unsigned int col1_pos = 0;
293
const unsigned int col1_width = 9;
294
const unsigned int col2_pos = col1_pos + col1_width + col_spacing;
295
const unsigned int col2_width = 49;
296
const unsigned int col3_pos = col2_pos + col2_width + col_spacing;
297
const unsigned int col3_width = 0;
298
const unsigned int col4_pos = col3_pos + col3_width + col_spacing;
299
const unsigned int col4_width = 60;
300
const unsigned int col5_pos = col4_pos + col4_width + col_spacing;
301
const unsigned int col5_width = 35;
302
const unsigned int col6_pos = col5_pos + col5_width + col_spacing;
303
const unsigned int col6_width = 15;
304
const unsigned int col7_pos = col6_pos + col6_width + col_spacing;
305
const unsigned int col7_width = 1;
306
307
st->fill_to(col1_pos);
308
st->print("%*s", col1_width, type_string()); // right-justified, therefore width is required.
309
310
fill_to_pos(st, col2_pos);
311
st->print("%s", _name);
312
313
fill_to_pos(st, col4_pos);
314
JVMFlagAccess::print_range(st, this);
315
316
fill_to_pos(st, col5_pos);
317
print_kind(st, col5_width);
318
319
fill_to_pos(st, col6_pos);
320
print_origin(st, col6_width);
321
322
#ifndef PRODUCT
323
if (withComments) {
324
fill_to_pos(st, col7_pos);
325
st->print("%s", _doc);
326
}
327
#endif
328
st->cr();
329
}
330
}
331
332
void JVMFlag::print_kind(outputStream* st, unsigned int width) const {
333
struct Data {
334
int flag;
335
const char* name;
336
};
337
338
Data data[] = {
339
{ KIND_JVMCI, "JVMCI" },
340
{ KIND_C1, "C1" },
341
{ KIND_C2, "C2" },
342
{ KIND_ARCH, "ARCH" },
343
{ KIND_PLATFORM_DEPENDENT, "pd" },
344
{ KIND_PRODUCT, "product" },
345
{ KIND_MANAGEABLE, "manageable" },
346
{ KIND_DIAGNOSTIC, "diagnostic" },
347
{ KIND_EXPERIMENTAL, "experimental" },
348
{ KIND_NOT_PRODUCT, "notproduct" },
349
{ KIND_DEVELOP, "develop" },
350
{ KIND_LP64_PRODUCT, "lp64_product" },
351
{ -1, "" }
352
};
353
354
if ((_flags & KIND_MASK) != 0) {
355
bool is_first = true;
356
const size_t buffer_size = 64;
357
size_t buffer_used = 0;
358
char kind[buffer_size];
359
360
jio_snprintf(kind, buffer_size, "{");
361
buffer_used++;
362
for (int i = 0; data[i].flag != -1; i++) {
363
Data d = data[i];
364
if ((_flags & d.flag) != 0) {
365
if (is_first) {
366
is_first = false;
367
} else {
368
assert(buffer_used + 1 < buffer_size, "Too small buffer");
369
jio_snprintf(kind + buffer_used, buffer_size - buffer_used, " ");
370
buffer_used++;
371
}
372
size_t length = strlen(d.name);
373
assert(buffer_used + length < buffer_size, "Too small buffer");
374
jio_snprintf(kind + buffer_used, buffer_size - buffer_used, "%s", d.name);
375
buffer_used += length;
376
}
377
}
378
assert(buffer_used + 2 <= buffer_size, "Too small buffer");
379
jio_snprintf(kind + buffer_used, buffer_size - buffer_used, "}");
380
st->print("%*s", width, kind);
381
}
382
}
383
384
void JVMFlag::print_origin(outputStream* st, unsigned int width) const {
385
st->print("{");
386
switch(get_origin()) {
387
case JVMFlagOrigin::DEFAULT:
388
st->print("default"); break;
389
case JVMFlagOrigin::COMMAND_LINE:
390
st->print("command line"); break;
391
case JVMFlagOrigin::ENVIRON_VAR:
392
st->print("environment"); break;
393
case JVMFlagOrigin::CONFIG_FILE:
394
st->print("config file"); break;
395
case JVMFlagOrigin::MANAGEMENT:
396
st->print("management"); break;
397
case JVMFlagOrigin::ERGONOMIC:
398
if (_flags & WAS_SET_ON_COMMAND_LINE) {
399
st->print("command line, ");
400
}
401
st->print("ergonomic"); break;
402
case JVMFlagOrigin::ATTACH_ON_DEMAND:
403
st->print("attach"); break;
404
case JVMFlagOrigin::INTERNAL:
405
st->print("internal"); break;
406
case JVMFlagOrigin::JIMAGE_RESOURCE:
407
st->print("jimage"); break;
408
}
409
st->print("}");
410
}
411
412
void JVMFlag::print_as_flag(outputStream* st) const {
413
if (is_bool()) {
414
st->print("-XX:%s%s", get_bool() ? "+" : "-", _name);
415
} else if (is_int()) {
416
st->print("-XX:%s=%d", _name, get_int());
417
} else if (is_uint()) {
418
st->print("-XX:%s=%u", _name, get_uint());
419
} else if (is_intx()) {
420
st->print("-XX:%s=" INTX_FORMAT, _name, get_intx());
421
} else if (is_uintx()) {
422
st->print("-XX:%s=" UINTX_FORMAT, _name, get_uintx());
423
} else if (is_uint64_t()) {
424
st->print("-XX:%s=" UINT64_FORMAT, _name, get_uint64_t());
425
} else if (is_size_t()) {
426
st->print("-XX:%s=" SIZE_FORMAT, _name, get_size_t());
427
} else if (is_double()) {
428
st->print("-XX:%s=%f", _name, get_double());
429
} else if (is_ccstr()) {
430
st->print("-XX:%s=", _name);
431
const char* cp = get_ccstr();
432
if (cp != NULL) {
433
// Need to turn embedded '\n's back into separate arguments
434
// Not so efficient to print one character at a time,
435
// but the choice is to do the transformation to a buffer
436
// and print that. And this need not be efficient.
437
for (; *cp != '\0'; cp += 1) {
438
switch (*cp) {
439
default:
440
st->print("%c", *cp);
441
break;
442
case '\n':
443
st->print(" -XX:%s=", _name);
444
break;
445
}
446
}
447
}
448
} else {
449
ShouldNotReachHere();
450
}
451
}
452
453
const char* JVMFlag::flag_error_str(JVMFlag::Error error) {
454
switch (error) {
455
case JVMFlag::MISSING_NAME: return "MISSING_NAME";
456
case JVMFlag::MISSING_VALUE: return "MISSING_VALUE";
457
case JVMFlag::NON_WRITABLE: return "NON_WRITABLE";
458
case JVMFlag::OUT_OF_BOUNDS: return "OUT_OF_BOUNDS";
459
case JVMFlag::VIOLATES_CONSTRAINT: return "VIOLATES_CONSTRAINT";
460
case JVMFlag::INVALID_FLAG: return "INVALID_FLAG";
461
case JVMFlag::ERR_OTHER: return "ERR_OTHER";
462
case JVMFlag::SUCCESS: return "SUCCESS";
463
default: ShouldNotReachHere(); return "NULL";
464
}
465
}
466
467
//----------------------------------------------------------------------
468
// Build flagTable[]
469
470
// Find out the number of LP64/ARCH/JVMCI/COMPILER1/COMPILER2 flags,
471
// for JVMFlag::flag_group()
472
473
#define ENUM_F(type, name, ...) enum_##name,
474
#define IGNORE_F(...)
475
476
// dev dev-pd pro pro-pd notpro range constraint
477
enum FlagCounter_LP64 { LP64_RUNTIME_FLAGS( ENUM_F, ENUM_F, ENUM_F, ENUM_F, ENUM_F, IGNORE_F, IGNORE_F) num_flags_LP64 };
478
enum FlagCounter_ARCH { ARCH_FLAGS( ENUM_F, ENUM_F, ENUM_F, IGNORE_F, IGNORE_F) num_flags_ARCH };
479
enum FlagCounter_JVMCI { JVMCI_ONLY(JVMCI_FLAGS( ENUM_F, ENUM_F, ENUM_F, ENUM_F, ENUM_F, IGNORE_F, IGNORE_F)) num_flags_JVMCI };
480
enum FlagCounter_C1 { COMPILER1_PRESENT(C1_FLAGS(ENUM_F, ENUM_F, ENUM_F, ENUM_F, ENUM_F, IGNORE_F, IGNORE_F)) num_flags_C1 };
481
enum FlagCounter_C2 { COMPILER2_PRESENT(C2_FLAGS(ENUM_F, ENUM_F, ENUM_F, ENUM_F, ENUM_F, IGNORE_F, IGNORE_F)) num_flags_C2 };
482
483
const int first_flag_enum_LP64 = 0;
484
const int first_flag_enum_ARCH = first_flag_enum_LP64 + num_flags_LP64;
485
const int first_flag_enum_JVMCI = first_flag_enum_ARCH + num_flags_ARCH;
486
const int first_flag_enum_C1 = first_flag_enum_JVMCI + num_flags_JVMCI;
487
const int first_flag_enum_C2 = first_flag_enum_C1 + num_flags_C1;
488
const int first_flag_enum_other = first_flag_enum_C2 + num_flags_C2;
489
490
static constexpr int flag_group(int flag_enum) {
491
if (flag_enum < first_flag_enum_ARCH) return JVMFlag::KIND_LP64_PRODUCT;
492
if (flag_enum < first_flag_enum_JVMCI) return JVMFlag::KIND_ARCH;
493
if (flag_enum < first_flag_enum_C1) return JVMFlag::KIND_JVMCI;
494
if (flag_enum < first_flag_enum_C2) return JVMFlag::KIND_C1;
495
if (flag_enum < first_flag_enum_other) return JVMFlag::KIND_C2;
496
497
return 0;
498
}
499
500
constexpr JVMFlag::JVMFlag(int flag_enum, FlagType type, const char* name,
501
void* addr, int flags, int extra_flags, const char* doc) :
502
_addr(addr), _name(name), _flags(), _type(type) NOT_PRODUCT(COMMA _doc(doc)) {
503
flags = flags | extra_flags | static_cast<int>(JVMFlagOrigin::DEFAULT) | flag_group(flag_enum);
504
if ((flags & JVMFlag::KIND_PRODUCT) != 0) {
505
if (flags & (JVMFlag::KIND_DIAGNOSTIC | JVMFlag::KIND_MANAGEABLE | JVMFlag::KIND_EXPERIMENTAL)) {
506
// Backwards compatibility. This will be relaxed in JDK-7123237.
507
flags &= ~(JVMFlag::KIND_PRODUCT);
508
}
509
}
510
_flags = static_cast<Flags>(flags);
511
}
512
513
constexpr JVMFlag::JVMFlag(int flag_enum, FlagType type, const char* name,
514
void* addr, int flags, const char* doc) :
515
JVMFlag(flag_enum, type, name, addr, flags, /*extra_flags*/0, doc) {}
516
517
const int PRODUCT_KIND = JVMFlag::KIND_PRODUCT;
518
const int PRODUCT_KIND_PD = JVMFlag::KIND_PRODUCT | JVMFlag::KIND_PLATFORM_DEPENDENT;
519
const int DEVELOP_KIND = JVMFlag::KIND_DEVELOP;
520
const int DEVELOP_KIND_PD = JVMFlag::KIND_DEVELOP | JVMFlag::KIND_PLATFORM_DEPENDENT;
521
const int NOTPROD_KIND = JVMFlag::KIND_NOT_PRODUCT;
522
523
#define FLAG_TYPE(type) (JVMFlag::TYPE_ ## type)
524
#define INITIALIZE_DEVELOP_FLAG( type, name, value, ...) JVMFlag(FLAG_MEMBER_ENUM(name), FLAG_TYPE(type), XSTR(name), (void*)&name, DEVELOP_KIND, __VA_ARGS__),
525
#define INITIALIZE_DEVELOP_FLAG_PD(type, name, ...) JVMFlag(FLAG_MEMBER_ENUM(name), FLAG_TYPE(type), XSTR(name), (void*)&name, DEVELOP_KIND_PD, __VA_ARGS__),
526
#define INITIALIZE_PRODUCT_FLAG( type, name, value, ...) JVMFlag(FLAG_MEMBER_ENUM(name), FLAG_TYPE(type), XSTR(name), (void*)&name, PRODUCT_KIND, __VA_ARGS__),
527
#define INITIALIZE_PRODUCT_FLAG_PD(type, name, ...) JVMFlag(FLAG_MEMBER_ENUM(name), FLAG_TYPE(type), XSTR(name), (void*)&name, PRODUCT_KIND_PD, __VA_ARGS__),
528
#define INITIALIZE_NOTPROD_FLAG( type, name, value, ...) JVMFlag(FLAG_MEMBER_ENUM(name), FLAG_TYPE(type), XSTR(name), (void*)&name, NOTPROD_KIND, __VA_ARGS__),
529
530
// Handy aliases to match the symbols used in the flag specification macros.
531
const int DIAGNOSTIC = JVMFlag::KIND_DIAGNOSTIC;
532
const int MANAGEABLE = JVMFlag::KIND_MANAGEABLE;
533
const int EXPERIMENTAL = JVMFlag::KIND_EXPERIMENTAL;
534
535
#define MATERIALIZE_ALL_FLAGS \
536
ALL_FLAGS(INITIALIZE_DEVELOP_FLAG, \
537
INITIALIZE_DEVELOP_FLAG_PD, \
538
INITIALIZE_PRODUCT_FLAG, \
539
INITIALIZE_PRODUCT_FLAG_PD, \
540
INITIALIZE_NOTPROD_FLAG, \
541
IGNORE_RANGE, \
542
IGNORE_CONSTRAINT)
543
544
static JVMFlag flagTable[NUM_JVMFlagsEnum + 1] = {
545
MATERIALIZE_ALL_FLAGS
546
JVMFlag() // The iteration code wants a flag with a NULL name at the end of the table.
547
};
548
549
// We want flagTable[] to be completely initialized at C++ compilation time, which requires
550
// that all arguments passed to JVMFlag() constructors be constexpr. The following line
551
// checks for this -- if any non-constexpr arguments are passed, the C++ compiler will
552
// generate an error.
553
//
554
// constexpr implies internal linkage. This means the flagTable_verify_constexpr[] variable
555
// will not be included in jvmFlag.o, so there's no footprint cost for having this variable.
556
//
557
// Note that we cannot declare flagTable[] as constexpr because JVMFlag::_flags is modified
558
// at runtime.
559
constexpr JVMFlag flagTable_verify_constexpr[] = { MATERIALIZE_ALL_FLAGS };
560
561
JVMFlag* JVMFlag::flags = flagTable;
562
size_t JVMFlag::numFlags = (sizeof(flagTable) / sizeof(JVMFlag));
563
564
#define JVM_FLAG_TYPE_SIGNATURE(t) JVMFlag::type_signature<t>(),
565
566
const int JVMFlag::type_signatures[] = {
567
JVM_FLAG_NON_STRING_TYPES_DO(JVM_FLAG_TYPE_SIGNATURE)
568
JVMFlag::type_signature<ccstr>(),
569
JVMFlag::type_signature<ccstr>()
570
};
571
572
// Search the flag table for a named flag
573
JVMFlag* JVMFlag::find_flag(const char* name, size_t length, bool allow_locked, bool return_flag) {
574
JVMFlag* flag = JVMFlagLookup::find(name, length);
575
if (flag != NULL) {
576
// Found a matching entry.
577
// Don't report notproduct and develop flags in product builds.
578
if (flag->is_constant_in_binary()) {
579
return (return_flag ? flag : NULL);
580
}
581
// Report locked flags only if allowed.
582
if (!(flag->is_unlocked() || flag->is_unlocker())) {
583
if (!allow_locked) {
584
// disable use of locked flags, e.g. diagnostic, experimental,
585
// etc. until they are explicitly unlocked
586
return NULL;
587
}
588
}
589
return flag;
590
}
591
// JVMFlag name is not in the flag table
592
return NULL;
593
}
594
595
JVMFlag* JVMFlag::fuzzy_match(const char* name, size_t length, bool allow_locked) {
596
float VMOptionsFuzzyMatchSimilarity = 0.7f;
597
JVMFlag* match = NULL;
598
float score;
599
float max_score = -1;
600
601
for (JVMFlag* current = &flagTable[0]; current->_name != NULL; current++) {
602
score = StringUtils::similarity(current->_name, strlen(current->_name), name, length);
603
if (score > max_score) {
604
max_score = score;
605
match = current;
606
}
607
}
608
609
if (match == NULL) {
610
return NULL;
611
}
612
613
if (!(match->is_unlocked() || match->is_unlocker())) {
614
if (!allow_locked) {
615
return NULL;
616
}
617
}
618
619
if (max_score < VMOptionsFuzzyMatchSimilarity) {
620
return NULL;
621
}
622
623
return match;
624
}
625
626
bool JVMFlag::is_default(JVMFlagsEnum flag) {
627
return flag_from_enum(flag)->is_default();
628
}
629
630
bool JVMFlag::is_ergo(JVMFlagsEnum flag) {
631
return flag_from_enum(flag)->is_ergonomic();
632
}
633
634
bool JVMFlag::is_cmdline(JVMFlagsEnum flag) {
635
return flag_from_enum(flag)->is_command_line();
636
}
637
638
bool JVMFlag::is_jimage_resource(JVMFlagsEnum flag) {
639
return flag_from_enum(flag)->is_jimage_resource();
640
}
641
642
void JVMFlag::setOnCmdLine(JVMFlagsEnum flag) {
643
flag_from_enum(flag)->set_command_line();
644
}
645
646
extern "C" {
647
static int compare_flags(const void* void_a, const void* void_b) {
648
return strcmp((*((JVMFlag**) void_a))->name(), (*((JVMFlag**) void_b))->name());
649
}
650
}
651
652
void JVMFlag::printSetFlags(outputStream* out) {
653
// Print which flags were set on the command line
654
// note: this method is called before the thread structure is in place
655
// which means resource allocation cannot be used.
656
657
// The last entry is the null entry.
658
const size_t length = JVMFlag::numFlags - 1;
659
660
// Sort
661
JVMFlag** array = NEW_C_HEAP_ARRAY(JVMFlag*, length, mtArguments);
662
for (size_t i = 0; i < length; i++) {
663
array[i] = &flagTable[i];
664
}
665
qsort(array, length, sizeof(JVMFlag*), compare_flags);
666
667
// Print
668
for (size_t i = 0; i < length; i++) {
669
if (array[i]->get_origin() != JVMFlagOrigin::DEFAULT) {
670
array[i]->print_as_flag(out);
671
out->print(" ");
672
}
673
}
674
out->cr();
675
FREE_C_HEAP_ARRAY(JVMFlag*, array);
676
}
677
678
#ifndef PRODUCT
679
680
void JVMFlag::verify() {
681
assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict");
682
}
683
684
#endif // PRODUCT
685
686
#ifdef ASSERT
687
688
void JVMFlag::assert_valid_flag_enum(JVMFlagsEnum i) {
689
assert(0 <= int(i) && int(i) < NUM_JVMFlagsEnum, "must be");
690
}
691
692
void JVMFlag::check_all_flag_declarations() {
693
for (JVMFlag* current = &flagTable[0]; current->_name != NULL; current++) {
694
int flags = static_cast<int>(current->_flags);
695
// Backwards compatibility. This will be relaxed/removed in JDK-7123237.
696
int mask = JVMFlag::KIND_DIAGNOSTIC | JVMFlag::KIND_MANAGEABLE | JVMFlag::KIND_EXPERIMENTAL;
697
if ((flags & mask) != 0) {
698
assert((flags & mask) == JVMFlag::KIND_DIAGNOSTIC ||
699
(flags & mask) == JVMFlag::KIND_MANAGEABLE ||
700
(flags & mask) == JVMFlag::KIND_EXPERIMENTAL,
701
"%s can be declared with at most one of "
702
"DIAGNOSTIC, MANAGEABLE or EXPERIMENTAL", current->_name);
703
assert((flags & KIND_NOT_PRODUCT) == 0 &&
704
(flags & KIND_DEVELOP) == 0,
705
"%s has an optional DIAGNOSTIC, MANAGEABLE or EXPERIMENTAL "
706
"attribute; it must be declared as a product flag", current->_name);
707
}
708
}
709
}
710
711
#endif // ASSERT
712
713
void JVMFlag::printFlags(outputStream* out, bool withComments, bool printRanges, bool skipDefaults) {
714
// Print the flags sorted by name
715
// Note: This method may be called before the thread structure is in place
716
// which means resource allocation cannot be used. Also, it may be
717
// called as part of error reporting, so handle native OOMs gracefully.
718
719
// The last entry is the null entry.
720
const size_t length = JVMFlag::numFlags - 1;
721
722
// Print
723
if (!printRanges) {
724
out->print_cr("[Global flags]");
725
} else {
726
out->print_cr("[Global flags ranges]");
727
}
728
729
// Sort
730
JVMFlag** array = NEW_C_HEAP_ARRAY_RETURN_NULL(JVMFlag*, length, mtArguments);
731
if (array != NULL) {
732
for (size_t i = 0; i < length; i++) {
733
array[i] = &flagTable[i];
734
}
735
qsort(array, length, sizeof(JVMFlag*), compare_flags);
736
737
for (size_t i = 0; i < length; i++) {
738
if (array[i]->is_unlocked() && !(skipDefaults && array[i]->is_default())) {
739
array[i]->print_on(out, withComments, printRanges);
740
}
741
}
742
FREE_C_HEAP_ARRAY(JVMFlag*, array);
743
} else {
744
// OOM? Print unsorted.
745
for (size_t i = 0; i < length; i++) {
746
if (flagTable[i].is_unlocked() && !(skipDefaults && flagTable[i].is_default())) {
747
flagTable[i].print_on(out, withComments, printRanges);
748
}
749
}
750
}
751
}
752
753
void JVMFlag::printError(bool verbose, const char* msg, ...) {
754
if (verbose) {
755
va_list listPointer;
756
va_start(listPointer, msg);
757
jio_vfprintf(defaultStream::error_stream(), msg, listPointer);
758
va_end(listPointer);
759
}
760
}
761
762