Wed, 17 Aug 2011 10:32:53 -0700
6791672: enable 1G and larger pages on solaris
Reviewed-by: ysr, iveresov, johnc
1 /*
2 * Copyright (c) 1997, 2010, 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 */
25 #include "precompiled.hpp"
26 #include "memory/allocation.inline.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "runtime/arguments.hpp"
29 #include "runtime/globals.hpp"
30 #include "runtime/globals_extension.hpp"
31 #include "utilities/ostream.hpp"
32 #include "utilities/top.hpp"
33 #ifndef SERIALGC
34 #include "gc_implementation/g1/g1_globals.hpp"
35 #endif
36 #ifdef COMPILER1
37 #include "c1/c1_globals.hpp"
38 #endif
39 #ifdef COMPILER2
40 #include "opto/c2_globals.hpp"
41 #endif
42 #ifdef SHARK
43 #include "shark/shark_globals.hpp"
44 #endif
47 RUNTIME_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
48 MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
49 MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_EXPERIMENTAL_FLAG, \
50 MATERIALIZE_NOTPRODUCT_FLAG, \
51 MATERIALIZE_MANAGEABLE_FLAG, MATERIALIZE_PRODUCT_RW_FLAG, \
52 MATERIALIZE_LP64_PRODUCT_FLAG)
54 RUNTIME_OS_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
55 MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
56 MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_NOTPRODUCT_FLAG)
58 bool Flag::is_unlocker() const {
59 return strcmp(name, "UnlockDiagnosticVMOptions") == 0 ||
60 strcmp(name, "UnlockExperimentalVMOptions") == 0;
62 }
64 bool Flag::is_unlocked() const {
65 if (strcmp(kind, "{diagnostic}") == 0) {
66 if (strcmp(name, "EnableInvokeDynamic") == 0 && UnlockExperimentalVMOptions && !UnlockDiagnosticVMOptions) {
67 // transitional logic to allow tests to run until they are changed
68 static int warned;
69 if (++warned == 1) warning("Use -XX:+UnlockDiagnosticVMOptions before EnableInvokeDynamic flag");
70 return true;
71 }
72 return UnlockDiagnosticVMOptions;
73 } else if (strcmp(kind, "{experimental}") == 0 ||
74 strcmp(kind, "{C2 experimental}") == 0) {
75 return UnlockExperimentalVMOptions;
76 } else {
77 return true;
78 }
79 }
81 bool Flag::is_writeable() const {
82 return (strcmp(kind, "{manageable}") == 0 || strcmp(kind, "{product rw}") == 0);
83 }
85 // All flags except "manageable" are assumed internal flags.
86 // Long term, we need to define a mechanism to specify which flags
87 // are external/stable and change this function accordingly.
88 bool Flag::is_external() const {
89 return (strcmp(kind, "{manageable}") == 0);
90 }
92 // Length of format string (e.g. "%.1234s") for printing ccstr below
93 #define FORMAT_BUFFER_LEN 16
95 void Flag::print_on(outputStream* st, bool withComments) {
96 st->print("%9s %-40s %c= ", type, name, (origin != DEFAULT ? ':' : ' '));
97 if (is_bool()) st->print("%-16s", get_bool() ? "true" : "false");
98 if (is_intx()) st->print("%-16ld", get_intx());
99 if (is_uintx()) st->print("%-16lu", get_uintx());
100 if (is_uint64_t()) st->print("%-16lu", get_uint64_t());
101 if (is_double()) st->print("%-16f", get_double());
103 if (is_ccstr()) {
104 const char* cp = get_ccstr();
105 if (cp != NULL) {
106 const char* eol;
107 while ((eol = strchr(cp, '\n')) != NULL) {
108 char format_buffer[FORMAT_BUFFER_LEN];
109 size_t llen = pointer_delta(eol, cp, sizeof(char));
110 jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
111 "%%." SIZE_FORMAT "s", llen);
112 st->print(format_buffer, cp);
113 st->cr();
114 cp = eol+1;
115 st->print("%5s %-35s += ", "", name);
116 }
117 st->print("%-16s", cp);
118 }
119 else st->print("%-16s", "");
120 }
121 st->print("%-20s", kind);
122 if (withComments) {
123 #ifndef PRODUCT
124 st->print("%s", doc );
125 #endif
126 }
127 st->cr();
128 }
130 void Flag::print_as_flag(outputStream* st) {
131 if (is_bool()) {
132 st->print("-XX:%s%s", get_bool() ? "+" : "-", name);
133 } else if (is_intx()) {
134 st->print("-XX:%s=" INTX_FORMAT, name, get_intx());
135 } else if (is_uintx()) {
136 st->print("-XX:%s=" UINTX_FORMAT, name, get_uintx());
137 } else if (is_uint64_t()) {
138 st->print("-XX:%s=" UINT64_FORMAT, name, get_uint64_t());
139 } else if (is_ccstr()) {
140 st->print("-XX:%s=", name);
141 const char* cp = get_ccstr();
142 if (cp != NULL) {
143 // Need to turn embedded '\n's back into separate arguments
144 // Not so efficient to print one character at a time,
145 // but the choice is to do the transformation to a buffer
146 // and print that. And this need not be efficient.
147 for (; *cp != '\0'; cp += 1) {
148 switch (*cp) {
149 default:
150 st->print("%c", *cp);
151 break;
152 case '\n':
153 st->print(" -XX:%s=", name);
154 break;
155 }
156 }
157 }
158 } else {
159 ShouldNotReachHere();
160 }
161 }
163 // 4991491 do not "optimize out" the was_set false values: omitting them
164 // tickles a Microsoft compiler bug causing flagTable to be malformed
166 #define RUNTIME_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product}", DEFAULT },
167 #define RUNTIME_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{pd product}", DEFAULT },
168 #define RUNTIME_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{diagnostic}", DEFAULT },
169 #define RUNTIME_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{experimental}", DEFAULT },
170 #define RUNTIME_MANAGEABLE_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{manageable}", DEFAULT },
171 #define RUNTIME_PRODUCT_RW_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product rw}", DEFAULT },
173 #ifdef PRODUCT
174 #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
175 #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
176 #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
177 #else
178 #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "", DEFAULT },
179 #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{pd}", DEFAULT },
180 #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{notproduct}", DEFAULT },
181 #endif
183 #ifdef _LP64
184 #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{lp64_product}", DEFAULT },
185 #else
186 #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
187 #endif // _LP64
189 #define C1_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 product}", DEFAULT },
190 #define C1_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 pd product}", DEFAULT },
191 #ifdef PRODUCT
192 #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
193 #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
194 #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
195 #else
196 #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1}", DEFAULT },
197 #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{C1 pd}", DEFAULT },
198 #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1 notproduct}", DEFAULT },
199 #endif
202 #define C2_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 product}", DEFAULT },
203 #define C2_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 pd product}", DEFAULT },
204 #define C2_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 diagnostic}", DEFAULT },
205 #define C2_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 experimental}", DEFAULT },
206 #ifdef PRODUCT
207 #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
208 #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
209 #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
210 #else
211 #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2}", DEFAULT },
212 #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{C2 pd}", DEFAULT },
213 #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2 notproduct}", DEFAULT },
214 #endif
216 #define SHARK_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark product}", DEFAULT },
217 #define SHARK_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark pd product}", DEFAULT },
218 #define SHARK_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark diagnostic}", DEFAULT },
219 #ifdef PRODUCT
220 #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
221 #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
222 #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
223 #else
224 #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark}", DEFAULT },
225 #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{Shark pd}", DEFAULT },
226 #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark notproduct}", DEFAULT },
227 #endif
229 static Flag flagTable[] = {
230 RUNTIME_FLAGS(RUNTIME_DEVELOP_FLAG_STRUCT, RUNTIME_PD_DEVELOP_FLAG_STRUCT, RUNTIME_PRODUCT_FLAG_STRUCT, RUNTIME_PD_PRODUCT_FLAG_STRUCT, RUNTIME_DIAGNOSTIC_FLAG_STRUCT, RUNTIME_EXPERIMENTAL_FLAG_STRUCT, RUNTIME_NOTPRODUCT_FLAG_STRUCT, RUNTIME_MANAGEABLE_FLAG_STRUCT, RUNTIME_PRODUCT_RW_FLAG_STRUCT, RUNTIME_LP64_PRODUCT_FLAG_STRUCT)
231 RUNTIME_OS_FLAGS(RUNTIME_DEVELOP_FLAG_STRUCT, RUNTIME_PD_DEVELOP_FLAG_STRUCT, RUNTIME_PRODUCT_FLAG_STRUCT, RUNTIME_PD_PRODUCT_FLAG_STRUCT, RUNTIME_DIAGNOSTIC_FLAG_STRUCT, RUNTIME_NOTPRODUCT_FLAG_STRUCT)
232 #ifndef SERIALGC
233 G1_FLAGS(RUNTIME_DEVELOP_FLAG_STRUCT, RUNTIME_PD_DEVELOP_FLAG_STRUCT, RUNTIME_PRODUCT_FLAG_STRUCT, RUNTIME_PD_PRODUCT_FLAG_STRUCT, RUNTIME_DIAGNOSTIC_FLAG_STRUCT, RUNTIME_EXPERIMENTAL_FLAG_STRUCT, RUNTIME_NOTPRODUCT_FLAG_STRUCT, RUNTIME_MANAGEABLE_FLAG_STRUCT, RUNTIME_PRODUCT_RW_FLAG_STRUCT)
234 #endif // SERIALGC
235 #ifdef COMPILER1
236 C1_FLAGS(C1_DEVELOP_FLAG_STRUCT, C1_PD_DEVELOP_FLAG_STRUCT, C1_PRODUCT_FLAG_STRUCT, C1_PD_PRODUCT_FLAG_STRUCT, C1_NOTPRODUCT_FLAG_STRUCT)
237 #endif
238 #ifdef COMPILER2
239 C2_FLAGS(C2_DEVELOP_FLAG_STRUCT, C2_PD_DEVELOP_FLAG_STRUCT, C2_PRODUCT_FLAG_STRUCT, C2_PD_PRODUCT_FLAG_STRUCT, C2_DIAGNOSTIC_FLAG_STRUCT, C2_EXPERIMENTAL_FLAG_STRUCT, C2_NOTPRODUCT_FLAG_STRUCT)
240 #endif
241 #ifdef SHARK
242 SHARK_FLAGS(SHARK_DEVELOP_FLAG_STRUCT, SHARK_PD_DEVELOP_FLAG_STRUCT, SHARK_PRODUCT_FLAG_STRUCT, SHARK_PD_PRODUCT_FLAG_STRUCT, SHARK_DIAGNOSTIC_FLAG_STRUCT, SHARK_NOTPRODUCT_FLAG_STRUCT)
243 #endif
244 {0, NULL, NULL}
245 };
247 Flag* Flag::flags = flagTable;
248 size_t Flag::numFlags = (sizeof(flagTable) / sizeof(Flag));
250 inline bool str_equal(const char* s, char* q, size_t len) {
251 // s is null terminated, q is not!
252 if (strlen(s) != (unsigned int) len) return false;
253 return strncmp(s, q, len) == 0;
254 }
256 Flag* Flag::find_flag(char* name, size_t length) {
257 for (Flag* current = &flagTable[0]; current->name; current++) {
258 if (str_equal(current->name, name, length)) {
259 if (!(current->is_unlocked() || current->is_unlocker())) {
260 // disable use of diagnostic or experimental flags until they
261 // are explicitly unlocked
262 return NULL;
263 }
264 return current;
265 }
266 }
267 return NULL;
268 }
270 // Returns the address of the index'th element
271 static Flag* address_of_flag(CommandLineFlagWithType flag) {
272 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
273 return &Flag::flags[flag];
274 }
276 bool CommandLineFlagsEx::is_default(CommandLineFlag flag) {
277 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
278 Flag* f = &Flag::flags[flag];
279 return (f->origin == DEFAULT);
280 }
282 bool CommandLineFlagsEx::is_ergo(CommandLineFlag flag) {
283 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
284 Flag* f = &Flag::flags[flag];
285 return (f->origin == ERGONOMIC);
286 }
288 bool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
289 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
290 Flag* f = &Flag::flags[flag];
291 return (f->origin == COMMAND_LINE);
292 }
294 bool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
295 Flag* result = Flag::find_flag((char*)name, strlen(name));
296 if (result == NULL) return false;
297 *value = (result->origin == COMMAND_LINE);
298 return true;
299 }
301 bool CommandLineFlags::boolAt(char* name, size_t len, bool* value) {
302 Flag* result = Flag::find_flag(name, len);
303 if (result == NULL) return false;
304 if (!result->is_bool()) return false;
305 *value = result->get_bool();
306 return true;
307 }
309 bool CommandLineFlags::boolAtPut(char* name, size_t len, bool* value, FlagValueOrigin origin) {
310 Flag* result = Flag::find_flag(name, len);
311 if (result == NULL) return false;
312 if (!result->is_bool()) return false;
313 bool old_value = result->get_bool();
314 result->set_bool(*value);
315 *value = old_value;
316 result->origin = origin;
317 return true;
318 }
320 void CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, FlagValueOrigin origin) {
321 Flag* faddr = address_of_flag(flag);
322 guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type");
323 faddr->set_bool(value);
324 faddr->origin = origin;
325 }
327 bool CommandLineFlags::intxAt(char* name, size_t len, intx* value) {
328 Flag* result = Flag::find_flag(name, len);
329 if (result == NULL) return false;
330 if (!result->is_intx()) return false;
331 *value = result->get_intx();
332 return true;
333 }
335 bool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, FlagValueOrigin origin) {
336 Flag* result = Flag::find_flag(name, len);
337 if (result == NULL) return false;
338 if (!result->is_intx()) return false;
339 intx old_value = result->get_intx();
340 result->set_intx(*value);
341 *value = old_value;
342 result->origin = origin;
343 return true;
344 }
346 void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, FlagValueOrigin origin) {
347 Flag* faddr = address_of_flag(flag);
348 guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
349 faddr->set_intx(value);
350 faddr->origin = origin;
351 }
353 bool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) {
354 Flag* result = Flag::find_flag(name, len);
355 if (result == NULL) return false;
356 if (!result->is_uintx()) return false;
357 *value = result->get_uintx();
358 return true;
359 }
361 bool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, FlagValueOrigin origin) {
362 Flag* result = Flag::find_flag(name, len);
363 if (result == NULL) return false;
364 if (!result->is_uintx()) return false;
365 uintx old_value = result->get_uintx();
366 result->set_uintx(*value);
367 *value = old_value;
368 result->origin = origin;
369 return true;
370 }
372 void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, FlagValueOrigin origin) {
373 Flag* faddr = address_of_flag(flag);
374 guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type");
375 faddr->set_uintx(value);
376 faddr->origin = origin;
377 }
379 bool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) {
380 Flag* result = Flag::find_flag(name, len);
381 if (result == NULL) return false;
382 if (!result->is_uint64_t()) return false;
383 *value = result->get_uint64_t();
384 return true;
385 }
387 bool CommandLineFlags::uint64_tAtPut(char* name, size_t len, uint64_t* value, FlagValueOrigin origin) {
388 Flag* result = Flag::find_flag(name, len);
389 if (result == NULL) return false;
390 if (!result->is_uint64_t()) return false;
391 uint64_t old_value = result->get_uint64_t();
392 result->set_uint64_t(*value);
393 *value = old_value;
394 result->origin = origin;
395 return true;
396 }
398 void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, FlagValueOrigin origin) {
399 Flag* faddr = address_of_flag(flag);
400 guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type");
401 faddr->set_uint64_t(value);
402 faddr->origin = origin;
403 }
405 bool CommandLineFlags::doubleAt(char* name, size_t len, double* value) {
406 Flag* result = Flag::find_flag(name, len);
407 if (result == NULL) return false;
408 if (!result->is_double()) return false;
409 *value = result->get_double();
410 return true;
411 }
413 bool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, FlagValueOrigin origin) {
414 Flag* result = Flag::find_flag(name, len);
415 if (result == NULL) return false;
416 if (!result->is_double()) return false;
417 double old_value = result->get_double();
418 result->set_double(*value);
419 *value = old_value;
420 result->origin = origin;
421 return true;
422 }
424 void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, FlagValueOrigin origin) {
425 Flag* faddr = address_of_flag(flag);
426 guarantee(faddr != NULL && faddr->is_double(), "wrong flag type");
427 faddr->set_double(value);
428 faddr->origin = origin;
429 }
431 bool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) {
432 Flag* result = Flag::find_flag(name, len);
433 if (result == NULL) return false;
434 if (!result->is_ccstr()) return false;
435 *value = result->get_ccstr();
436 return true;
437 }
439 // Contract: Flag will make private copy of the incoming value.
440 // Outgoing value is always malloc-ed, and caller MUST call free.
441 bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, FlagValueOrigin origin) {
442 Flag* result = Flag::find_flag(name, len);
443 if (result == NULL) return false;
444 if (!result->is_ccstr()) return false;
445 ccstr old_value = result->get_ccstr();
446 char* new_value = NULL;
447 if (*value != NULL) {
448 new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1);
449 strcpy(new_value, *value);
450 }
451 result->set_ccstr(new_value);
452 if (result->origin == DEFAULT && old_value != NULL) {
453 // Prior value is NOT heap allocated, but was a literal constant.
454 char* old_value_to_free = NEW_C_HEAP_ARRAY(char, strlen(old_value)+1);
455 strcpy(old_value_to_free, old_value);
456 old_value = old_value_to_free;
457 }
458 *value = old_value;
459 result->origin = origin;
460 return true;
461 }
463 // Contract: Flag will make private copy of the incoming value.
464 void CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, FlagValueOrigin origin) {
465 Flag* faddr = address_of_flag(flag);
466 guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
467 ccstr old_value = faddr->get_ccstr();
468 char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1);
469 strcpy(new_value, value);
470 faddr->set_ccstr(new_value);
471 if (faddr->origin != DEFAULT && old_value != NULL) {
472 // Prior value is heap allocated so free it.
473 FREE_C_HEAP_ARRAY(char, old_value);
474 }
475 faddr->origin = origin;
476 }
478 extern "C" {
479 static int compare_flags(const void* void_a, const void* void_b) {
480 return strcmp((*((Flag**) void_a))->name, (*((Flag**) void_b))->name);
481 }
482 }
484 void CommandLineFlags::printSetFlags() {
485 // Print which flags were set on the command line
486 // note: this method is called before the thread structure is in place
487 // which means resource allocation cannot be used.
489 // Compute size
490 int length= 0;
491 while (flagTable[length].name != NULL) length++;
493 // Sort
494 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length);
495 for (int index = 0; index < length; index++) {
496 array[index] = &flagTable[index];
497 }
498 qsort(array, length, sizeof(Flag*), compare_flags);
500 // Print
501 for (int i = 0; i < length; i++) {
502 if (array[i]->origin /* naked field! */) {
503 array[i]->print_as_flag(tty);
504 tty->print(" ");
505 }
506 }
507 tty->cr();
508 FREE_C_HEAP_ARRAY(Flag*, array);
509 }
511 #ifndef PRODUCT
514 void CommandLineFlags::verify() {
515 assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict");
516 }
518 #endif // PRODUCT
520 void CommandLineFlags::printFlags(bool withComments) {
521 // Print the flags sorted by name
522 // note: this method is called before the thread structure is in place
523 // which means resource allocation cannot be used.
525 // Compute size
526 int length= 0;
527 while (flagTable[length].name != NULL) length++;
529 // Sort
530 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length);
531 for (int index = 0; index < length; index++) {
532 array[index] = &flagTable[index];
533 }
534 qsort(array, length, sizeof(Flag*), compare_flags);
536 // Print
537 tty->print_cr("[Global flags]");
538 for (int i = 0; i < length; i++) {
539 if (array[i]->is_unlocked()) {
540 array[i]->print_on(tty, withComments);
541 }
542 }
543 FREE_C_HEAP_ARRAY(Flag*, array);
544 }