hotspot/src/share/vm/runtime/commandLineFlagConstraintList.cpp
changeset 31995 aa4049b4184a
parent 31371 311143309e73
child 32351 1da9b960b3d4
equal deleted inserted replaced
31994:3721b7aa3a0d 31995:aa4049b4184a
    37 class CommandLineFlagConstraint_bool : public CommandLineFlagConstraint {
    37 class CommandLineFlagConstraint_bool : public CommandLineFlagConstraint {
    38   CommandLineFlagConstraintFunc_bool _constraint;
    38   CommandLineFlagConstraintFunc_bool _constraint;
    39 
    39 
    40 public:
    40 public:
    41   // the "name" argument must be a string literal
    41   // the "name" argument must be a string literal
    42   CommandLineFlagConstraint_bool(const char* name, CommandLineFlagConstraintFunc_bool func) : CommandLineFlagConstraint(name) {
    42   CommandLineFlagConstraint_bool(const char* name,
       
    43                                  CommandLineFlagConstraintFunc_bool func,
       
    44                                  ConstraintType type) : CommandLineFlagConstraint(name, type) {
    43     _constraint=func;
    45     _constraint=func;
    44   }
    46   }
    45 
    47 
    46   Flag::Error apply_bool(bool* value, bool verbose) {
    48   Flag::Error apply_bool(bool* value, bool verbose) {
    47     return _constraint(verbose, value);
    49     return _constraint(verbose, value);
    51 class CommandLineFlagConstraint_int : public CommandLineFlagConstraint {
    53 class CommandLineFlagConstraint_int : public CommandLineFlagConstraint {
    52   CommandLineFlagConstraintFunc_int _constraint;
    54   CommandLineFlagConstraintFunc_int _constraint;
    53 
    55 
    54 public:
    56 public:
    55   // the "name" argument must be a string literal
    57   // the "name" argument must be a string literal
    56   CommandLineFlagConstraint_int(const char* name, CommandLineFlagConstraintFunc_int func) : CommandLineFlagConstraint(name) {
    58   CommandLineFlagConstraint_int(const char* name,
       
    59                                 CommandLineFlagConstraintFunc_int func,
       
    60                                 ConstraintType type) : CommandLineFlagConstraint(name, type) {
    57     _constraint=func;
    61     _constraint=func;
    58   }
    62   }
    59 
    63 
    60   Flag::Error apply_int(int* value, bool verbose) {
    64   Flag::Error apply_int(int* value, bool verbose) {
    61     return _constraint(verbose, value);
    65     return _constraint(verbose, value);
    65 class CommandLineFlagConstraint_intx : public CommandLineFlagConstraint {
    69 class CommandLineFlagConstraint_intx : public CommandLineFlagConstraint {
    66   CommandLineFlagConstraintFunc_intx _constraint;
    70   CommandLineFlagConstraintFunc_intx _constraint;
    67 
    71 
    68 public:
    72 public:
    69   // the "name" argument must be a string literal
    73   // the "name" argument must be a string literal
    70   CommandLineFlagConstraint_intx(const char* name, CommandLineFlagConstraintFunc_intx func) : CommandLineFlagConstraint(name) {
    74   CommandLineFlagConstraint_intx(const char* name,
       
    75                                  CommandLineFlagConstraintFunc_intx func,
       
    76                                  ConstraintType type) : CommandLineFlagConstraint(name, type) {
    71     _constraint=func;
    77     _constraint=func;
    72   }
    78   }
    73 
    79 
    74   Flag::Error apply_intx(intx* value, bool verbose) {
    80   Flag::Error apply_intx(intx* value, bool verbose) {
    75     return _constraint(verbose, value);
    81     return _constraint(verbose, value);
    79 class CommandLineFlagConstraint_uint : public CommandLineFlagConstraint {
    85 class CommandLineFlagConstraint_uint : public CommandLineFlagConstraint {
    80   CommandLineFlagConstraintFunc_uint _constraint;
    86   CommandLineFlagConstraintFunc_uint _constraint;
    81 
    87 
    82 public:
    88 public:
    83   // the "name" argument must be a string literal
    89   // the "name" argument must be a string literal
    84   CommandLineFlagConstraint_uint(const char* name, CommandLineFlagConstraintFunc_uint func) : CommandLineFlagConstraint(name) {
    90   CommandLineFlagConstraint_uint(const char* name,
       
    91                                  CommandLineFlagConstraintFunc_uint func,
       
    92                                  ConstraintType type) : CommandLineFlagConstraint(name, type) {
    85     _constraint=func;
    93     _constraint=func;
    86   }
    94   }
    87 
    95 
    88   Flag::Error apply_uint(uint* value, bool verbose) {
    96   Flag::Error apply_uint(uint* value, bool verbose) {
    89     return _constraint(verbose, value);
    97     return _constraint(verbose, value);
    93 class CommandLineFlagConstraint_uintx : public CommandLineFlagConstraint {
   101 class CommandLineFlagConstraint_uintx : public CommandLineFlagConstraint {
    94   CommandLineFlagConstraintFunc_uintx _constraint;
   102   CommandLineFlagConstraintFunc_uintx _constraint;
    95 
   103 
    96 public:
   104 public:
    97   // the "name" argument must be a string literal
   105   // the "name" argument must be a string literal
    98   CommandLineFlagConstraint_uintx(const char* name, CommandLineFlagConstraintFunc_uintx func) : CommandLineFlagConstraint(name) {
   106   CommandLineFlagConstraint_uintx(const char* name,
       
   107                                   CommandLineFlagConstraintFunc_uintx func,
       
   108                                   ConstraintType type) : CommandLineFlagConstraint(name, type) {
    99     _constraint=func;
   109     _constraint=func;
   100   }
   110   }
   101 
   111 
   102   Flag::Error apply_uintx(uintx* value, bool verbose) {
   112   Flag::Error apply_uintx(uintx* value, bool verbose) {
   103     return _constraint(verbose, value);
   113     return _constraint(verbose, value);
   107 class CommandLineFlagConstraint_uint64_t : public CommandLineFlagConstraint {
   117 class CommandLineFlagConstraint_uint64_t : public CommandLineFlagConstraint {
   108   CommandLineFlagConstraintFunc_uint64_t _constraint;
   118   CommandLineFlagConstraintFunc_uint64_t _constraint;
   109 
   119 
   110 public:
   120 public:
   111   // the "name" argument must be a string literal
   121   // the "name" argument must be a string literal
   112   CommandLineFlagConstraint_uint64_t(const char* name, CommandLineFlagConstraintFunc_uint64_t func) : CommandLineFlagConstraint(name) {
   122   CommandLineFlagConstraint_uint64_t(const char* name,
       
   123                                      CommandLineFlagConstraintFunc_uint64_t func,
       
   124                                      ConstraintType type) : CommandLineFlagConstraint(name, type) {
   113     _constraint=func;
   125     _constraint=func;
   114   }
   126   }
   115 
   127 
   116   Flag::Error apply_uint64_t(uint64_t* value, bool verbose) {
   128   Flag::Error apply_uint64_t(uint64_t* value, bool verbose) {
   117     return _constraint(verbose, value);
   129     return _constraint(verbose, value);
   121 class CommandLineFlagConstraint_size_t : public CommandLineFlagConstraint {
   133 class CommandLineFlagConstraint_size_t : public CommandLineFlagConstraint {
   122   CommandLineFlagConstraintFunc_size_t _constraint;
   134   CommandLineFlagConstraintFunc_size_t _constraint;
   123 
   135 
   124 public:
   136 public:
   125   // the "name" argument must be a string literal
   137   // the "name" argument must be a string literal
   126   CommandLineFlagConstraint_size_t(const char* name, CommandLineFlagConstraintFunc_size_t func) : CommandLineFlagConstraint(name) {
   138   CommandLineFlagConstraint_size_t(const char* name,
       
   139                                    CommandLineFlagConstraintFunc_size_t func,
       
   140                                    ConstraintType type) : CommandLineFlagConstraint(name, type) {
   127     _constraint=func;
   141     _constraint=func;
   128   }
   142   }
   129 
   143 
   130   Flag::Error apply_size_t(size_t* value, bool verbose) {
   144   Flag::Error apply_size_t(size_t* value, bool verbose) {
   131     return _constraint(verbose, value);
   145     return _constraint(verbose, value);
   135 class CommandLineFlagConstraint_double : public CommandLineFlagConstraint {
   149 class CommandLineFlagConstraint_double : public CommandLineFlagConstraint {
   136   CommandLineFlagConstraintFunc_double _constraint;
   150   CommandLineFlagConstraintFunc_double _constraint;
   137 
   151 
   138 public:
   152 public:
   139   // the "name" argument must be a string literal
   153   // the "name" argument must be a string literal
   140   CommandLineFlagConstraint_double(const char* name, CommandLineFlagConstraintFunc_double func) : CommandLineFlagConstraint(name) {
   154   CommandLineFlagConstraint_double(const char* name,
       
   155                                    CommandLineFlagConstraintFunc_double func,
       
   156                                    ConstraintType type) : CommandLineFlagConstraint(name, type) {
   141     _constraint=func;
   157     _constraint=func;
   142   }
   158   }
   143 
   159 
   144   Flag::Error apply_double(double* value, bool verbose) {
   160   Flag::Error apply_double(double* value, bool verbose) {
   145     return _constraint(verbose, value);
   161     return _constraint(verbose, value);
   160 void emit_constraint_uint64_t(const char* /*name*/)   { /* NOP */ }
   176 void emit_constraint_uint64_t(const char* /*name*/)   { /* NOP */ }
   161 void emit_constraint_size_t(const char* /*name*/)     { /* NOP */ }
   177 void emit_constraint_size_t(const char* /*name*/)     { /* NOP */ }
   162 void emit_constraint_double(const char* /*name*/)     { /* NOP */ }
   178 void emit_constraint_double(const char* /*name*/)     { /* NOP */ }
   163 
   179 
   164 // CommandLineFlagConstraint emitting code functions if function argument is provided
   180 // CommandLineFlagConstraint emitting code functions if function argument is provided
   165 void emit_constraint_bool(const char* name, CommandLineFlagConstraintFunc_bool func) {
   181 void emit_constraint_bool(const char* name, CommandLineFlagConstraintFunc_bool func, CommandLineFlagConstraint::ConstraintType type) {
   166   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_bool(name, func));
   182   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_bool(name, func, type));
   167 }
   183 }
   168 void emit_constraint_int(const char* name, CommandLineFlagConstraintFunc_int func) {
   184 void emit_constraint_int(const char* name, CommandLineFlagConstraintFunc_int func, CommandLineFlagConstraint::ConstraintType type) {
   169   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_int(name, func));
   185   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_int(name, func, type));
   170 }
   186 }
   171 void emit_constraint_intx(const char* name, CommandLineFlagConstraintFunc_intx func) {
   187 void emit_constraint_intx(const char* name, CommandLineFlagConstraintFunc_intx func, CommandLineFlagConstraint::ConstraintType type) {
   172   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_intx(name, func));
   188   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_intx(name, func, type));
   173 }
   189 }
   174 void emit_constraint_uint(const char* name, CommandLineFlagConstraintFunc_uint func) {
   190 void emit_constraint_uint(const char* name, CommandLineFlagConstraintFunc_uint func, CommandLineFlagConstraint::ConstraintType type) {
   175   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_uint(name, func));
   191   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_uint(name, func, type));
   176 }
   192 }
   177 void emit_constraint_uintx(const char* name, CommandLineFlagConstraintFunc_uintx func) {
   193 void emit_constraint_uintx(const char* name, CommandLineFlagConstraintFunc_uintx func, CommandLineFlagConstraint::ConstraintType type) {
   178   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_uintx(name, func));
   194   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_uintx(name, func, type));
   179 }
   195 }
   180 void emit_constraint_uint64_t(const char* name, CommandLineFlagConstraintFunc_uint64_t func) {
   196 void emit_constraint_uint64_t(const char* name, CommandLineFlagConstraintFunc_uint64_t func, CommandLineFlagConstraint::ConstraintType type) {
   181   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_uint64_t(name, func));
   197   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_uint64_t(name, func, type));
   182 }
   198 }
   183 void emit_constraint_size_t(const char* name, CommandLineFlagConstraintFunc_size_t func) {
   199 void emit_constraint_size_t(const char* name, CommandLineFlagConstraintFunc_size_t func, CommandLineFlagConstraint::ConstraintType type) {
   184   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_size_t(name, func));
   200   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_size_t(name, func, type));
   185 }
   201 }
   186 void emit_constraint_double(const char* name, CommandLineFlagConstraintFunc_double func) {
   202 void emit_constraint_double(const char* name, CommandLineFlagConstraintFunc_double func, CommandLineFlagConstraint::ConstraintType type) {
   187   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_double(name, func));
   203   CommandLineFlagConstraintList::add(new CommandLineFlagConstraint_double(name, func, type));
   188 }
   204 }
   189 
   205 
   190 // Generate code to call emit_constraint_xxx function
   206 // Generate code to call emit_constraint_xxx function
   191 #define EMIT_CONSTRAINT_PRODUCT_FLAG(type, name, value, doc)      ); emit_constraint_##type(#name
   207 #define EMIT_CONSTRAINT_PRODUCT_FLAG(type, name, value, doc)      ); emit_constraint_##type(#name
   192 #define EMIT_CONSTRAINT_COMMERCIAL_FLAG(type, name, value, doc)   ); emit_constraint_##type(#name
   208 #define EMIT_CONSTRAINT_COMMERCIAL_FLAG(type, name, value, doc)   ); emit_constraint_##type(#name
   199 #define EMIT_CONSTRAINT_PD_DEVELOPER_FLAG(type, name, doc)        ); emit_constraint_##type(#name
   215 #define EMIT_CONSTRAINT_PD_DEVELOPER_FLAG(type, name, doc)        ); emit_constraint_##type(#name
   200 #define EMIT_CONSTRAINT_NOTPRODUCT_FLAG(type, name, value, doc)   ); emit_constraint_##type(#name
   216 #define EMIT_CONSTRAINT_NOTPRODUCT_FLAG(type, name, value, doc)   ); emit_constraint_##type(#name
   201 #define EMIT_CONSTRAINT_LP64_PRODUCT_FLAG(type, name, value, doc) ); emit_constraint_##type(#name
   217 #define EMIT_CONSTRAINT_LP64_PRODUCT_FLAG(type, name, value, doc) ); emit_constraint_##type(#name
   202 
   218 
   203 // Generate func argument to pass into emit_constraint_xxx functions
   219 // Generate func argument to pass into emit_constraint_xxx functions
   204 #define EMIT_CONSTRAINT_CHECK(func)                               , func
   220 #define EMIT_CONSTRAINT_CHECK(func, type)                               , func, CommandLineFlagConstraint::type
   205 
   221 
   206 // the "name" argument must be a string literal
   222 // the "name" argument must be a string literal
   207 #define INITIAL_CONTRAINTS_SIZE 16
   223 #define INITIAL_CONSTRAINTS_SIZE 16
   208 GrowableArray<CommandLineFlagConstraint*>* CommandLineFlagConstraintList::_constraints = NULL;
   224 GrowableArray<CommandLineFlagConstraint*>* CommandLineFlagConstraintList::_constraints = NULL;
       
   225 CommandLineFlagConstraint::ConstraintType CommandLineFlagConstraintList::_validating_type = CommandLineFlagConstraint::AtParse;
   209 
   226 
   210 // Check the ranges of all flags that have them or print them out and exit if requested
   227 // Check the ranges of all flags that have them or print them out and exit if requested
   211 void CommandLineFlagConstraintList::init(void) {
   228 void CommandLineFlagConstraintList::init(void) {
   212 
   229 
   213   _constraints = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<CommandLineFlagConstraint*>(INITIAL_CONTRAINTS_SIZE, true);
   230   _constraints = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<CommandLineFlagConstraint*>(INITIAL_CONSTRAINTS_SIZE, true);
   214 
   231 
   215   emit_constraint_no(NULL RUNTIME_FLAGS(EMIT_CONSTRAINT_DEVELOPER_FLAG,
   232   emit_constraint_no(NULL RUNTIME_FLAGS(EMIT_CONSTRAINT_DEVELOPER_FLAG,
   216                                         EMIT_CONSTRAINT_PD_DEVELOPER_FLAG,
   233                                         EMIT_CONSTRAINT_PD_DEVELOPER_FLAG,
   217                                         EMIT_CONSTRAINT_PRODUCT_FLAG,
   234                                         EMIT_CONSTRAINT_PRODUCT_FLAG,
   218                                         EMIT_CONSTRAINT_PD_PRODUCT_FLAG,
   235                                         EMIT_CONSTRAINT_PD_PRODUCT_FLAG,
   271                                    IGNORE_RANGE,
   288                                    IGNORE_RANGE,
   272                                    EMIT_CONSTRAINT_CHECK));
   289                                    EMIT_CONSTRAINT_CHECK));
   273 #endif // INCLUDE_ALL_GCS
   290 #endif // INCLUDE_ALL_GCS
   274 }
   291 }
   275 
   292 
   276 CommandLineFlagConstraint* CommandLineFlagConstraintList::find(const char* name) {
   293 // Find constraints by name and return only if found constraint's type is equal or lower than current validating type.
       
   294 CommandLineFlagConstraint* CommandLineFlagConstraintList::find_if_needs_check(const char* name) {
   277   CommandLineFlagConstraint* found = NULL;
   295   CommandLineFlagConstraint* found = NULL;
   278   for (int i=0; i<length(); i++) {
   296   for (int i=0; i<length(); i++) {
   279     CommandLineFlagConstraint* constraint = at(i);
   297     CommandLineFlagConstraint* constraint = at(i);
   280     if (strcmp(constraint->name(), name) == 0) {
   298     if ((strcmp(constraint->name(), name) == 0) &&
       
   299         (constraint->type() <= _validating_type)) {
   281       found = constraint;
   300       found = constraint;
   282       break;
   301       break;
   283     }
   302     }
   284   }
   303   }
   285   return found;
   304   return found;
   286 }
   305 }
       
   306 
       
   307 // Check constraints for specific constraint type.
       
   308 bool CommandLineFlagConstraintList::check_constraints(CommandLineFlagConstraint::ConstraintType type) {
       
   309 //#define PRINT_CONSTRAINTS_SIZES
       
   310 #ifdef PRINT_CONSTRAINTS_SIZES
       
   311   {
       
   312     size_t size_constraints = sizeof(CommandLineFlagConstraintList);
       
   313     for (int i=0; i<length(); i++) {
       
   314       size_constraints += sizeof(CommandLineFlagConstraint);
       
   315       CommandLineFlagConstraint* constraint = at(i);
       
   316       const char* name = constraint->name();
       
   317       Flag* flag = Flag::find_flag(name, strlen(name), true, true);
       
   318       if (flag->is_bool()) {
       
   319         size_constraints += sizeof(CommandLineFlagConstraintFunc_bool);
       
   320         size_constraints += sizeof(CommandLineFlagConstraint*);
       
   321       } else if (flag->is_intx()) {
       
   322         size_constraints += sizeof(CommandLineFlagConstraintFunc_intx);
       
   323         size_constraints += sizeof(CommandLineFlagConstraint*);
       
   324       } else if (flag->is_uintx()) {
       
   325         size_constraints += sizeof(CommandLineFlagConstraintFunc_uintx);
       
   326         size_constraints += sizeof(CommandLineFlagConstraint*);
       
   327       } else if (flag->is_uint64_t()) {
       
   328         size_constraints += sizeof(CommandLineFlagConstraintFunc_uint64_t);
       
   329         size_constraints += sizeof(CommandLineFlagConstraint*);
       
   330       } else if (flag->is_size_t()) {
       
   331         size_constraints += sizeof(CommandLineFlagConstraintFunc_size_t);
       
   332         size_constraints += sizeof(CommandLineFlagConstraint*);
       
   333       } else if (flag->is_double()) {
       
   334         size_constraints += sizeof(CommandLineFlagConstraintFunc_double);
       
   335         size_constraints += sizeof(CommandLineFlagConstraint*);
       
   336       }
       
   337     }
       
   338     fprintf(stderr, "Size of %d constraints: " SIZE_FORMAT " bytes\n",
       
   339             length(), size_constraints);
       
   340   }
       
   341 #endif // PRINT_CONSTRAINTS_SIZES
       
   342 
       
   343   // Skip if we already checked.
       
   344   if (type < _validating_type) {
       
   345     return true;
       
   346   }
       
   347   _validating_type = type;
       
   348 
       
   349   bool status = true;
       
   350   for (int i=0; i<length(); i++) {
       
   351     CommandLineFlagConstraint* constraint = at(i);
       
   352     if (type != constraint->type()) continue;
       
   353     const char*name = constraint->name();
       
   354     Flag* flag = Flag::find_flag(name, strlen(name), true, true);
       
   355     if (flag != NULL) {
       
   356       if (flag->is_bool()) {
       
   357         bool value = flag->get_bool();
       
   358         if (constraint->apply_bool(&value, true) != Flag::SUCCESS) status = false;
       
   359       } else if (flag->is_intx()) {
       
   360         intx value = flag->get_intx();
       
   361         if (constraint->apply_intx(&value, true) != Flag::SUCCESS) status = false;
       
   362       } else if (flag->is_uintx()) {
       
   363         uintx value = flag->get_uintx();
       
   364         if (constraint->apply_uintx(&value, true) != Flag::SUCCESS) status = false;
       
   365       } else if (flag->is_uint64_t()) {
       
   366         uint64_t value = flag->get_uint64_t();
       
   367         if (constraint->apply_uint64_t(&value, true) != Flag::SUCCESS) status = false;
       
   368       } else if (flag->is_size_t()) {
       
   369         size_t value = flag->get_size_t();
       
   370         if (constraint->apply_size_t(&value, true) != Flag::SUCCESS) status = false;
       
   371       } else if (flag->is_double()) {
       
   372         double value = flag->get_double();
       
   373         if (constraint->apply_double(&value, true) != Flag::SUCCESS) status = false;
       
   374       }
       
   375     }
       
   376   }
       
   377   return status;
       
   378 }