--- old/src/share/vm/runtime/globals.cpp 2015-07-15 00:07:00.476868181 -0700 +++ new/src/share/vm/runtime/globals.cpp 2015-07-15 00:07:00.368868177 -0700 @@ -770,7 +770,7 @@ static Flag::Error apply_constraint_and_check_range_bool(const char* name, bool* new_value, bool verbose = true) { Flag::Error status = Flag::SUCCESS; - CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); + CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_validated(name); if (constraint != NULL) { status = constraint->apply_bool(new_value, verbose); } @@ -789,7 +789,7 @@ Flag* result = Flag::find_flag(name, len); if (result == NULL) return Flag::INVALID_FLAG; if (!result->is_bool()) return Flag::WRONG_FORMAT; - Flag::Error check = apply_constraint_and_check_range_bool(name, value, !CommandLineFlags::finishedInitializing()); + Flag::Error check = apply_constraint_and_check_range_bool(name, value, !CommandLineFlagConstraintList::validatedAfterParse()); if (check != Flag::SUCCESS) return check; bool old_value = result->get_bool(); trace_flag_changed(name, old_value, *value, origin); @@ -817,7 +817,7 @@ range_status = range->check_int(*new_value, verbose); } Flag::Error constraint_status = Flag::SUCCESS; - CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); + CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_validated(name); if (constraint != NULL) { constraint_status = constraint->apply_int(new_value, verbose); } @@ -836,7 +836,7 @@ Flag* result = Flag::find_flag(name, len); if (result == NULL) return Flag::INVALID_FLAG; if (!result->is_int()) return Flag::WRONG_FORMAT; - Flag::Error check = apply_constraint_and_check_range_int(name, value, !CommandLineFlags::finishedInitializing()); + Flag::Error check = apply_constraint_and_check_range_int(name, value, !CommandLineFlagConstraintList::validatedAfterParse()); if (check != Flag::SUCCESS) return check; int old_value = result->get_int(); trace_flag_changed(name, old_value, *value, origin); @@ -862,7 +862,7 @@ range_status = range->check_uint(*new_value, verbose); } Flag::Error constraint_status = Flag::SUCCESS; - CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); + CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_validated(name); if (constraint != NULL) { constraint_status = constraint->apply_uint(new_value, verbose); } @@ -881,7 +881,7 @@ Flag* result = Flag::find_flag(name, len); if (result == NULL) return Flag::INVALID_FLAG; if (!result->is_uint()) return Flag::WRONG_FORMAT; - Flag::Error check = apply_constraint_and_check_range_uint(name, value, !CommandLineFlags::finishedInitializing()); + Flag::Error check = apply_constraint_and_check_range_uint(name, value, !CommandLineFlagConstraintList::validatedAfterParse()); if (check != Flag::SUCCESS) return check; uint old_value = result->get_uint(); trace_flag_changed(name, old_value, *value, origin); @@ -915,7 +915,7 @@ range_status = range->check_intx(*new_value, verbose); } Flag::Error constraint_status = Flag::SUCCESS; - CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); + CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_validated(name); if (constraint != NULL) { constraint_status = constraint->apply_intx(new_value, verbose); } @@ -926,7 +926,7 @@ Flag* result = Flag::find_flag(name, len); if (result == NULL) return Flag::INVALID_FLAG; if (!result->is_intx()) return Flag::WRONG_FORMAT; - Flag::Error check = apply_constraint_and_check_range_intx(name, value, !CommandLineFlags::finishedInitializing()); + Flag::Error check = apply_constraint_and_check_range_intx(name, value, !CommandLineFlagConstraintList::validatedAfterParse()); if (check != Flag::SUCCESS) return check; intx old_value = result->get_intx(); trace_flag_changed(name, old_value, *value, origin); @@ -962,7 +962,7 @@ range_status = range->check_uintx(*new_value, verbose); } Flag::Error constraint_status = Flag::SUCCESS; - CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); + CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_validated(name); if (constraint != NULL) { constraint_status = constraint->apply_uintx(new_value, verbose); } @@ -973,7 +973,7 @@ Flag* result = Flag::find_flag(name, len); if (result == NULL) return Flag::INVALID_FLAG; if (!result->is_uintx()) return Flag::WRONG_FORMAT; - Flag::Error check = apply_constraint_and_check_range_uintx(name, value, !CommandLineFlags::finishedInitializing()); + Flag::Error check = apply_constraint_and_check_range_uintx(name, value, !CommandLineFlagConstraintList::validatedAfterParse()); if (check != Flag::SUCCESS) return check; uintx old_value = result->get_uintx(); trace_flag_changed(name, old_value, *value, origin); @@ -1009,7 +1009,7 @@ range_status = range->check_uint64_t(*new_value, verbose); } Flag::Error constraint_status = Flag::SUCCESS; - CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); + CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_validated(name); if (constraint != NULL) { constraint_status = constraint->apply_uint64_t(new_value, verbose); } @@ -1020,7 +1020,7 @@ Flag* result = Flag::find_flag(name, len); if (result == NULL) return Flag::INVALID_FLAG; if (!result->is_uint64_t()) return Flag::WRONG_FORMAT; - Flag::Error check = apply_constraint_and_check_range_uint64_t(name, value, !CommandLineFlags::finishedInitializing()); + Flag::Error check = apply_constraint_and_check_range_uint64_t(name, value, !CommandLineFlagConstraintList::validatedAfterParse()); if (check != Flag::SUCCESS) return check; uint64_t old_value = result->get_uint64_t(); trace_flag_changed(name, old_value, *value, origin); @@ -1056,7 +1056,7 @@ range_status = range->check_size_t(*new_value, verbose); } Flag::Error constraint_status = Flag::SUCCESS; - CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); + CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_validated(name); if (constraint != NULL) { constraint_status = constraint->apply_size_t(new_value, verbose); } @@ -1067,7 +1067,7 @@ Flag* result = Flag::find_flag(name, len); if (result == NULL) return Flag::INVALID_FLAG; if (!result->is_size_t()) return Flag::WRONG_FORMAT; - Flag::Error check = apply_constraint_and_check_range_size_t(name, value, !CommandLineFlags::finishedInitializing()); + Flag::Error check = apply_constraint_and_check_range_size_t(name, value, !CommandLineFlagConstraintList::validatedAfterParse()); if (check != Flag::SUCCESS) return check; size_t old_value = result->get_size_t(); trace_flag_changed(name, old_value, *value, origin); @@ -1103,7 +1103,7 @@ range_status = range->check_double(*new_value, verbose); } Flag::Error constraint_status = Flag::SUCCESS; - CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); + CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_validated(name); if (constraint != NULL) { constraint_status = constraint->apply_double(new_value, verbose); } @@ -1114,7 +1114,7 @@ Flag* result = Flag::find_flag(name, len); if (result == NULL) return Flag::INVALID_FLAG; if (!result->is_double()) return Flag::WRONG_FORMAT; - Flag::Error check = apply_constraint_and_check_range_double(name, value, !CommandLineFlags::finishedInitializing()); + Flag::Error check = apply_constraint_and_check_range_double(name, value, !CommandLineFlagConstraintList::validatedAfterParse()); if (check != Flag::SUCCESS) return check; double old_value = result->get_double(); trace_flag_changed(name, old_value, *value, origin); @@ -1127,7 +1127,7 @@ Flag::Error CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, Flag::Flags origin) { Flag* faddr = address_of_flag(flag); guarantee(faddr != NULL && faddr->is_double(), "wrong flag type"); - Flag::Error check = apply_constraint_and_check_range_double(faddr->_name, &value, !CommandLineFlags::finishedInitializing()); + Flag::Error check = apply_constraint_and_check_range_double(faddr->_name, &value); if (check != Flag::SUCCESS) return check; trace_flag_changed(faddr->_name, faddr->get_double(), value, origin); faddr->set_double(value); @@ -1210,9 +1210,42 @@ FREE_C_HEAP_ARRAY(Flag*, array); } -bool CommandLineFlags::_finished_initializing = false; +// Check constraints for specific constraint type. +static bool check_constraints(CommandLineFlagConstraint::ConstraintType constraint_type) { + bool status = true; + + for (int i=0; itype()) continue; + const char*name = constraint->name(); + Flag* flag = Flag::find_flag(name, strlen(name), true, true); + if (flag != NULL) { + if (flag->is_bool()) { + bool value = flag->get_bool(); + if (constraint->apply_bool(&value, true) != Flag::SUCCESS) status = false; + } else if (flag->is_intx()) { + intx value = flag->get_intx(); + if (constraint->apply_intx(&value, true) != Flag::SUCCESS) status = false; + } else if (flag->is_uintx()) { + uintx value = flag->get_uintx(); + if (constraint->apply_uintx(&value, true) != Flag::SUCCESS) status = false; + } else if (flag->is_uint64_t()) { + uint64_t value = flag->get_uint64_t(); + if (constraint->apply_uint64_t(&value, true) != Flag::SUCCESS) status = false; + } else if (flag->is_size_t()) { + size_t value = flag->get_size_t(); + if (constraint->apply_size_t(&value, true) != Flag::SUCCESS) status = false; + } else if (flag->is_double()) { + double value = flag->get_double(); + if (constraint->apply_double(&value, true) != Flag::SUCCESS) status = false; + } + } + } + + return status; +} -bool CommandLineFlags::check_all_ranges_and_constraints() { +bool CommandLineFlags::check_ranges_and_constraints_of_after_parse() { //#define PRINT_RANGES_AND_CONSTRAINTS_SIZES #ifdef PRINT_RANGES_AND_CONSTRAINTS_SIZES @@ -1275,8 +1308,9 @@ } #endif // PRINT_RANGES_AND_CONSTRAINTS_SIZES - _finished_initializing = true; + CommandLineFlagConstraintList::setValidatingType(CommandLineFlagConstraint::AfterParse); + // Check ranges. bool status = true; for (int i=0; iname(); - Flag* flag = Flag::find_flag(name, strlen(name), true, true); - if (flag != NULL) { - if (flag->is_bool()) { - bool value = flag->get_bool(); - if (constraint->apply_bool(&value, true) != Flag::SUCCESS) status = false; - } else if (flag->is_intx()) { - intx value = flag->get_intx(); - if (constraint->apply_intx(&value, true) != Flag::SUCCESS) status = false; - } else if (flag->is_uintx()) { - uintx value = flag->get_uintx(); - if (constraint->apply_uintx(&value, true) != Flag::SUCCESS) status = false; - } else if (flag->is_uint64_t()) { - uint64_t value = flag->get_uint64_t(); - if (constraint->apply_uint64_t(&value, true) != Flag::SUCCESS) status = false; - } else if (flag->is_size_t()) { - size_t value = flag->get_size_t(); - if (constraint->apply_size_t(&value, true) != Flag::SUCCESS) status = false; - } else if (flag->is_double()) { - double value = flag->get_double(); - if (constraint->apply_double(&value, true) != Flag::SUCCESS) status = false; - } - } - } + + // Check constraints of 'AfterParse'. + status = check_constraints(CommandLineFlagConstraint::AfterParse); Arguments::post_final_range_and_constraint_check(status); return status; } + +bool CommandLineFlags::check_constraints_of_after_memory_init() { + CommandLineFlagConstraintList::setValidatingType(CommandLineFlagConstraint::AfterMemoryInit); + + return check_constraints(CommandLineFlagConstraint::AfterMemoryInit); +} + #ifndef PRODUCT void CommandLineFlags::verify() {