set_numeric_flag function(hotspot/src/share/vm/runtime/arguments.cpp) not determine flag type and delegate this to the CommandLineFlags::<type>AtPut method by consequentially calling methods for all types.
CommandLineFlags::<type>AtPut find the flag with passed name and process it if type is match.This seems as not optimal, because each CommandLineFlags::<type>AtPut method calls Flag::find_flag to find the flag with passed name. Instead, set_numeric_flag function can found the flag by Flag::find_flag method and call appropriate CommandLineFlags::<type>AtPut method to update the value. In this case we will have 2 calls to Flag::find_flag method instead of 6 in the worst case. CommandLineFlags::<type>AtPut methods also can be optimized by providing version which accepts Flag and in this case we can have 1 call to Flag::find_flag method to find flag.
The worst case is for size_t flag type. Here an example:
static bool set_numeric_flag(char* name, char* value, Flag::Flags origin) {
...
if (CommandLineFlags::intAtPut(name, &int_v, origin) == Flag::SUCCESS) {
return true;
}
uint uint_v = (uint) v;
if (!is_neg && CommandLineFlags::uintAtPut(name, &uint_v, origin) == Flag::SUCCESS) {
return true;
}
intx_v = (intx) v;
if (is_neg) {
intx_v = -intx_v;
}
if (CommandLineFlags::intxAtPut(name, &intx_v, origin) == Flag::SUCCESS) {
return true;
}
uintx uintx_v = (uintx) v;
if (!is_neg && (CommandLineFlags::uintxAtPut(name, &uintx_v, origin) == Flag::SUCCESS)) {
return true;
}
uint64_t uint64_t_v = (uint64_t) v;
if (!is_neg && (CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin) == Flag::SUCCESS)) {
return true;
}
size_t size_t_v = (size_t) v;
if (!is_neg && (CommandLineFlags::size_tAtPut(name, &size_t_v, origin) == Flag::SUCCESS)) {
return true;
}
return false;
}
If the type is size_t, then all CommandLineFlags::<type>atPut, expect CommandLineFlags::size_tAtPut, will not process this flag. And therefore Flag::find_flag will be called at least 6 times for size_t flag type.
Proposed change:
find flag in set_numeric_flag function and use flag->is_int(), flag->is_intx() and etc. to call appropriate CommandLineFlags::<type>atPut method.
CommandLineFlags::<type>AtPut find the flag with passed name and process it if type is match.This seems as not optimal, because each CommandLineFlags::<type>AtPut method calls Flag::find_flag to find the flag with passed name. Instead, set_numeric_flag function can found the flag by Flag::find_flag method and call appropriate CommandLineFlags::<type>AtPut method to update the value. In this case we will have 2 calls to Flag::find_flag method instead of 6 in the worst case. CommandLineFlags::<type>AtPut methods also can be optimized by providing version which accepts Flag and in this case we can have 1 call to Flag::find_flag method to find flag.
The worst case is for size_t flag type. Here an example:
static bool set_numeric_flag(char* name, char* value, Flag::Flags origin) {
...
if (CommandLineFlags::intAtPut(name, &int_v, origin) == Flag::SUCCESS) {
return true;
}
uint uint_v = (uint) v;
if (!is_neg && CommandLineFlags::uintAtPut(name, &uint_v, origin) == Flag::SUCCESS) {
return true;
}
intx_v = (intx) v;
if (is_neg) {
intx_v = -intx_v;
}
if (CommandLineFlags::intxAtPut(name, &intx_v, origin) == Flag::SUCCESS) {
return true;
}
uintx uintx_v = (uintx) v;
if (!is_neg && (CommandLineFlags::uintxAtPut(name, &uintx_v, origin) == Flag::SUCCESS)) {
return true;
}
uint64_t uint64_t_v = (uint64_t) v;
if (!is_neg && (CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin) == Flag::SUCCESS)) {
return true;
}
size_t size_t_v = (size_t) v;
if (!is_neg && (CommandLineFlags::size_tAtPut(name, &size_t_v, origin) == Flag::SUCCESS)) {
return true;
}
return false;
}
If the type is size_t, then all CommandLineFlags::<type>atPut, expect CommandLineFlags::size_tAtPut, will not process this flag. And therefore Flag::find_flag will be called at least 6 times for size_t flag type.
Proposed change:
find flag in set_numeric_flag function and use flag->is_int(), flag->is_intx() and etc. to call appropriate CommandLineFlags::<type>atPut method.