src/share/vm/runtime/globals.cpp

Wed, 02 Feb 2011 11:35:26 -0500

author
bobv
date
Wed, 02 Feb 2011 11:35:26 -0500
changeset 2508
b92c45f2bc75
parent 2314
f95d63e2154a
child 2742
ed69575596ac
permissions
-rw-r--r--

7016023: Enable building ARM and PPC from src/closed repository
Reviewed-by: dholmes, bdelsart

     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     return UnlockDiagnosticVMOptions;
    67   } else if (strcmp(kind, "{experimental}") == 0 ||
    68              strcmp(kind, "{C2 experimental}") == 0) {
    69     return UnlockExperimentalVMOptions;
    70   } else {
    71     return true;
    72   }
    73 }
    75 bool Flag::is_writeable() const {
    76   return (strcmp(kind, "{manageable}") == 0 || strcmp(kind, "{product rw}") == 0);
    77 }
    79 // All flags except "manageable" are assumed internal flags.
    80 // Long term, we need to define a mechanism to specify which flags
    81 // are external/stable and change this function accordingly.
    82 bool Flag::is_external() const {
    83   return (strcmp(kind, "{manageable}") == 0);
    84 }
    86 // Length of format string (e.g. "%.1234s") for printing ccstr below
    87 #define FORMAT_BUFFER_LEN 16
    89 void Flag::print_on(outputStream* st, bool withComments) {
    90   st->print("%9s %-40s %c= ", type, name, (origin != DEFAULT ? ':' : ' '));
    91   if (is_bool())     st->print("%-16s", get_bool() ? "true" : "false");
    92   if (is_intx())     st->print("%-16ld", get_intx());
    93   if (is_uintx())    st->print("%-16lu", get_uintx());
    94   if (is_uint64_t()) st->print("%-16lu", get_uint64_t());
    95   if (is_double())   st->print("%-16f", get_double());
    97   if (is_ccstr()) {
    98      const char* cp = get_ccstr();
    99      if (cp != NULL) {
   100        const char* eol;
   101        while ((eol = strchr(cp, '\n')) != NULL) {
   102          char format_buffer[FORMAT_BUFFER_LEN];
   103          size_t llen = pointer_delta(eol, cp, sizeof(char));
   104          jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
   105                      "%%." SIZE_FORMAT "s", llen);
   106          st->print(format_buffer, cp);
   107          st->cr();
   108          cp = eol+1;
   109          st->print("%5s %-35s += ", "", name);
   110        }
   111        st->print("%-16s", cp);
   112      }
   113      else st->print("%-16s", "");
   114   }
   115   st->print("%-20s", kind);
   116   if (withComments) {
   117 #ifndef PRODUCT
   118     st->print("%s", doc );
   119 #endif
   120   }
   121   st->cr();
   122 }
   124 void Flag::print_as_flag(outputStream* st) {
   125   if (is_bool()) {
   126     st->print("-XX:%s%s", get_bool() ? "+" : "-", name);
   127   } else if (is_intx()) {
   128     st->print("-XX:%s=" INTX_FORMAT, name, get_intx());
   129   } else if (is_uintx()) {
   130     st->print("-XX:%s=" UINTX_FORMAT, name, get_uintx());
   131   } else if (is_uint64_t()) {
   132     st->print("-XX:%s=" UINT64_FORMAT, name, get_uint64_t());
   133   } else if (is_ccstr()) {
   134     st->print("-XX:%s=", name);
   135     const char* cp = get_ccstr();
   136     if (cp != NULL) {
   137       // Need to turn embedded '\n's back into separate arguments
   138       // Not so efficient to print one character at a time,
   139       // but the choice is to do the transformation to a buffer
   140       // and print that.  And this need not be efficient.
   141       for (; *cp != '\0'; cp += 1) {
   142         switch (*cp) {
   143           default:
   144             st->print("%c", *cp);
   145             break;
   146           case '\n':
   147             st->print(" -XX:%s=", name);
   148             break;
   149         }
   150       }
   151     }
   152   } else {
   153     ShouldNotReachHere();
   154   }
   155 }
   157 // 4991491 do not "optimize out" the was_set false values: omitting them
   158 // tickles a Microsoft compiler bug causing flagTable to be malformed
   160 #define RUNTIME_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product}", DEFAULT },
   161 #define RUNTIME_PD_PRODUCT_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{pd product}", DEFAULT },
   162 #define RUNTIME_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{diagnostic}", DEFAULT },
   163 #define RUNTIME_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{experimental}", DEFAULT },
   164 #define RUNTIME_MANAGEABLE_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{manageable}", DEFAULT },
   165 #define RUNTIME_PRODUCT_RW_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product rw}", DEFAULT },
   167 #ifdef PRODUCT
   168   #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
   169   #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     /* flag is constant */
   170   #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
   171 #else
   172   #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "", DEFAULT },
   173   #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, doc, "{pd}", DEFAULT },
   174   #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{notproduct}", DEFAULT },
   175 #endif
   177 #ifdef _LP64
   178   #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{lp64_product}", DEFAULT },
   179 #else
   180   #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
   181 #endif // _LP64
   183 #define C1_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 product}", DEFAULT },
   184 #define C1_PD_PRODUCT_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 pd product}", DEFAULT },
   185 #ifdef PRODUCT
   186   #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
   187   #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     /* flag is constant */
   188   #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
   189 #else
   190   #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1}", DEFAULT },
   191   #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, doc, "{C1 pd}", DEFAULT },
   192   #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1 notproduct}", DEFAULT },
   193 #endif
   196 #define C2_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 product}", DEFAULT },
   197 #define C2_PD_PRODUCT_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 pd product}", DEFAULT },
   198 #define C2_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 diagnostic}", DEFAULT },
   199 #define C2_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 experimental}", DEFAULT },
   200 #ifdef PRODUCT
   201   #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
   202   #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     /* flag is constant */
   203   #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
   204 #else
   205   #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2}", DEFAULT },
   206   #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, doc, "{C2 pd}", DEFAULT },
   207   #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2 notproduct}", DEFAULT },
   208 #endif
   210 #define SHARK_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark product}", DEFAULT },
   211 #define SHARK_PD_PRODUCT_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark pd product}", DEFAULT },
   212 #define SHARK_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark diagnostic}", DEFAULT },
   213 #ifdef PRODUCT
   214   #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
   215   #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     /* flag is constant */
   216   #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
   217 #else
   218   #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark}", DEFAULT },
   219   #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, doc, "{Shark pd}", DEFAULT },
   220   #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark notproduct}", DEFAULT },
   221 #endif
   223 static Flag flagTable[] = {
   224  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)
   225  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)
   226 #ifndef SERIALGC
   227  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)
   228 #endif // SERIALGC
   229 #ifdef COMPILER1
   230  C1_FLAGS(C1_DEVELOP_FLAG_STRUCT, C1_PD_DEVELOP_FLAG_STRUCT, C1_PRODUCT_FLAG_STRUCT, C1_PD_PRODUCT_FLAG_STRUCT, C1_NOTPRODUCT_FLAG_STRUCT)
   231 #endif
   232 #ifdef COMPILER2
   233  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)
   234 #endif
   235 #ifdef SHARK
   236  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)
   237 #endif
   238  {0, NULL, NULL}
   239 };
   241 Flag* Flag::flags = flagTable;
   242 size_t Flag::numFlags = (sizeof(flagTable) / sizeof(Flag));
   244 inline bool str_equal(const char* s, char* q, size_t len) {
   245   // s is null terminated, q is not!
   246   if (strlen(s) != (unsigned int) len) return false;
   247   return strncmp(s, q, len) == 0;
   248 }
   250 Flag* Flag::find_flag(char* name, size_t length) {
   251   for (Flag* current = &flagTable[0]; current->name; current++) {
   252     if (str_equal(current->name, name, length)) {
   253       if (!(current->is_unlocked() || current->is_unlocker())) {
   254         // disable use of diagnostic or experimental flags until they
   255         // are explicitly unlocked
   256         return NULL;
   257       }
   258       return current;
   259     }
   260   }
   261   return NULL;
   262 }
   264 // Returns the address of the index'th element
   265 static Flag* address_of_flag(CommandLineFlagWithType flag) {
   266   assert((size_t)flag < Flag::numFlags, "bad command line flag index");
   267   return &Flag::flags[flag];
   268 }
   270 bool CommandLineFlagsEx::is_default(CommandLineFlag flag) {
   271   assert((size_t)flag < Flag::numFlags, "bad command line flag index");
   272   Flag* f = &Flag::flags[flag];
   273   return (f->origin == DEFAULT);
   274 }
   276 bool CommandLineFlagsEx::is_ergo(CommandLineFlag flag) {
   277   assert((size_t)flag < Flag::numFlags, "bad command line flag index");
   278   Flag* f = &Flag::flags[flag];
   279   return (f->origin == ERGONOMIC);
   280 }
   282 bool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
   283   assert((size_t)flag < Flag::numFlags, "bad command line flag index");
   284   Flag* f = &Flag::flags[flag];
   285   return (f->origin == COMMAND_LINE);
   286 }
   288 bool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
   289   Flag* result = Flag::find_flag((char*)name, strlen(name));
   290   if (result == NULL) return false;
   291   *value = (result->origin == COMMAND_LINE);
   292   return true;
   293 }
   295 bool CommandLineFlags::boolAt(char* name, size_t len, bool* value) {
   296   Flag* result = Flag::find_flag(name, len);
   297   if (result == NULL) return false;
   298   if (!result->is_bool()) return false;
   299   *value = result->get_bool();
   300   return true;
   301 }
   303 bool CommandLineFlags::boolAtPut(char* name, size_t len, bool* value, FlagValueOrigin origin) {
   304   Flag* result = Flag::find_flag(name, len);
   305   if (result == NULL) return false;
   306   if (!result->is_bool()) return false;
   307   bool old_value = result->get_bool();
   308   result->set_bool(*value);
   309   *value = old_value;
   310   result->origin = origin;
   311   return true;
   312 }
   314 void CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, FlagValueOrigin origin) {
   315   Flag* faddr = address_of_flag(flag);
   316   guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type");
   317   faddr->set_bool(value);
   318   faddr->origin = origin;
   319 }
   321 bool CommandLineFlags::intxAt(char* name, size_t len, intx* value) {
   322   Flag* result = Flag::find_flag(name, len);
   323   if (result == NULL) return false;
   324   if (!result->is_intx()) return false;
   325   *value = result->get_intx();
   326   return true;
   327 }
   329 bool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, FlagValueOrigin origin) {
   330   Flag* result = Flag::find_flag(name, len);
   331   if (result == NULL) return false;
   332   if (!result->is_intx()) return false;
   333   intx old_value = result->get_intx();
   334   result->set_intx(*value);
   335   *value = old_value;
   336   result->origin = origin;
   337   return true;
   338 }
   340 void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, FlagValueOrigin origin) {
   341   Flag* faddr = address_of_flag(flag);
   342   guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
   343   faddr->set_intx(value);
   344   faddr->origin = origin;
   345 }
   347 bool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) {
   348   Flag* result = Flag::find_flag(name, len);
   349   if (result == NULL) return false;
   350   if (!result->is_uintx()) return false;
   351   *value = result->get_uintx();
   352   return true;
   353 }
   355 bool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, FlagValueOrigin origin) {
   356   Flag* result = Flag::find_flag(name, len);
   357   if (result == NULL) return false;
   358   if (!result->is_uintx()) return false;
   359   uintx old_value = result->get_uintx();
   360   result->set_uintx(*value);
   361   *value = old_value;
   362   result->origin = origin;
   363   return true;
   364 }
   366 void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, FlagValueOrigin origin) {
   367   Flag* faddr = address_of_flag(flag);
   368   guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type");
   369   faddr->set_uintx(value);
   370   faddr->origin = origin;
   371 }
   373 bool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) {
   374   Flag* result = Flag::find_flag(name, len);
   375   if (result == NULL) return false;
   376   if (!result->is_uint64_t()) return false;
   377   *value = result->get_uint64_t();
   378   return true;
   379 }
   381 bool CommandLineFlags::uint64_tAtPut(char* name, size_t len, uint64_t* value, FlagValueOrigin origin) {
   382   Flag* result = Flag::find_flag(name, len);
   383   if (result == NULL) return false;
   384   if (!result->is_uint64_t()) return false;
   385   uint64_t old_value = result->get_uint64_t();
   386   result->set_uint64_t(*value);
   387   *value = old_value;
   388   result->origin = origin;
   389   return true;
   390 }
   392 void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, FlagValueOrigin origin) {
   393   Flag* faddr = address_of_flag(flag);
   394   guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type");
   395   faddr->set_uint64_t(value);
   396   faddr->origin = origin;
   397 }
   399 bool CommandLineFlags::doubleAt(char* name, size_t len, double* value) {
   400   Flag* result = Flag::find_flag(name, len);
   401   if (result == NULL) return false;
   402   if (!result->is_double()) return false;
   403   *value = result->get_double();
   404   return true;
   405 }
   407 bool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, FlagValueOrigin origin) {
   408   Flag* result = Flag::find_flag(name, len);
   409   if (result == NULL) return false;
   410   if (!result->is_double()) return false;
   411   double old_value = result->get_double();
   412   result->set_double(*value);
   413   *value = old_value;
   414   result->origin = origin;
   415   return true;
   416 }
   418 void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, FlagValueOrigin origin) {
   419   Flag* faddr = address_of_flag(flag);
   420   guarantee(faddr != NULL && faddr->is_double(), "wrong flag type");
   421   faddr->set_double(value);
   422   faddr->origin = origin;
   423 }
   425 bool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) {
   426   Flag* result = Flag::find_flag(name, len);
   427   if (result == NULL) return false;
   428   if (!result->is_ccstr()) return false;
   429   *value = result->get_ccstr();
   430   return true;
   431 }
   433 // Contract:  Flag will make private copy of the incoming value.
   434 // Outgoing value is always malloc-ed, and caller MUST call free.
   435 bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, FlagValueOrigin origin) {
   436   Flag* result = Flag::find_flag(name, len);
   437   if (result == NULL) return false;
   438   if (!result->is_ccstr()) return false;
   439   ccstr old_value = result->get_ccstr();
   440   char* new_value = NULL;
   441   if (*value != NULL) {
   442     new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1);
   443     strcpy(new_value, *value);
   444   }
   445   result->set_ccstr(new_value);
   446   if (result->origin == DEFAULT && old_value != NULL) {
   447     // Prior value is NOT heap allocated, but was a literal constant.
   448     char* old_value_to_free = NEW_C_HEAP_ARRAY(char, strlen(old_value)+1);
   449     strcpy(old_value_to_free, old_value);
   450     old_value = old_value_to_free;
   451   }
   452   *value = old_value;
   453   result->origin = origin;
   454   return true;
   455 }
   457 // Contract:  Flag will make private copy of the incoming value.
   458 void CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, FlagValueOrigin origin) {
   459   Flag* faddr = address_of_flag(flag);
   460   guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
   461   ccstr old_value = faddr->get_ccstr();
   462   char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1);
   463   strcpy(new_value, value);
   464   faddr->set_ccstr(new_value);
   465   if (faddr->origin != DEFAULT && old_value != NULL) {
   466     // Prior value is heap allocated so free it.
   467     FREE_C_HEAP_ARRAY(char, old_value);
   468   }
   469   faddr->origin = origin;
   470 }
   472 extern "C" {
   473   static int compare_flags(const void* void_a, const void* void_b) {
   474     return strcmp((*((Flag**) void_a))->name, (*((Flag**) void_b))->name);
   475   }
   476 }
   478 void CommandLineFlags::printSetFlags() {
   479   // Print which flags were set on the command line
   480   // note: this method is called before the thread structure is in place
   481   //       which means resource allocation cannot be used.
   483   // Compute size
   484   int length= 0;
   485   while (flagTable[length].name != NULL) length++;
   487   // Sort
   488   Flag** array = NEW_C_HEAP_ARRAY(Flag*, length);
   489   for (int index = 0; index < length; index++) {
   490     array[index] = &flagTable[index];
   491   }
   492   qsort(array, length, sizeof(Flag*), compare_flags);
   494   // Print
   495   for (int i = 0; i < length; i++) {
   496     if (array[i]->origin /* naked field! */) {
   497       array[i]->print_as_flag(tty);
   498       tty->print(" ");
   499     }
   500   }
   501   tty->cr();
   502   FREE_C_HEAP_ARRAY(Flag*, array);
   503 }
   505 #ifndef PRODUCT
   508 void CommandLineFlags::verify() {
   509   assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict");
   510 }
   512 #endif // PRODUCT
   514 void CommandLineFlags::printFlags(bool withComments) {
   515   // Print the flags sorted by name
   516   // note: this method is called before the thread structure is in place
   517   //       which means resource allocation cannot be used.
   519   // Compute size
   520   int length= 0;
   521   while (flagTable[length].name != NULL) length++;
   523   // Sort
   524   Flag** array = NEW_C_HEAP_ARRAY(Flag*, length);
   525   for (int index = 0; index < length; index++) {
   526     array[index] = &flagTable[index];
   527   }
   528   qsort(array, length, sizeof(Flag*), compare_flags);
   530   // Print
   531   tty->print_cr("[Global flags]");
   532   for (int i = 0; i < length; i++) {
   533     if (array[i]->is_unlocked()) {
   534       array[i]->print_on(tty, withComments);
   535     }
   536   }
   537   FREE_C_HEAP_ARRAY(Flag*, array);
   538 }

mercurial