753 E e; 754 e.set_name(name); 755 e.set_old_value(old_value); 756 e.set_new_value(new_value); 757 e.set_origin(origin); 758 e.commit(); 759 } 760 761 static Flag::Error get_status_error(Flag::Error status_range, Flag::Error status_constraint) { 762 if (status_range != Flag::SUCCESS) { 763 return status_range; 764 } else if (status_constraint != Flag::SUCCESS) { 765 return status_constraint; 766 } else { 767 return Flag::SUCCESS; 768 } 769 } 770 771 static Flag::Error apply_constraint_and_check_range_bool(const char* name, bool* new_value, bool verbose = true) { 772 Flag::Error status = Flag::SUCCESS; 773 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); 774 if (constraint != NULL) { 775 status = constraint->apply_bool(new_value, verbose); 776 } 777 return status; 778 } 779 780 Flag::Error CommandLineFlags::boolAt(const char* name, size_t len, bool* value, bool allow_locked, bool return_flag) { 781 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 782 if (result == NULL) return Flag::INVALID_FLAG; 783 if (!result->is_bool()) return Flag::WRONG_FORMAT; 784 *value = result->get_bool(); 785 return Flag::SUCCESS; 786 } 787 788 Flag::Error CommandLineFlags::boolAtPut(const char* name, size_t len, bool* value, Flag::Flags origin) { 789 Flag* result = Flag::find_flag(name, len); 790 if (result == NULL) return Flag::INVALID_FLAG; 791 if (!result->is_bool()) return Flag::WRONG_FORMAT; 792 Flag::Error check = apply_constraint_and_check_range_bool(name, value, !CommandLineFlags::finishedInitializing()); 793 if (check != Flag::SUCCESS) return check; 794 bool old_value = result->get_bool(); 795 trace_flag_changed<EventBooleanFlagChanged, bool>(name, old_value, *value, origin); 796 result->set_bool(*value); 797 *value = old_value; 798 result->set_origin(origin); 799 return Flag::SUCCESS; 800 } 801 802 Flag::Error CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, Flag::Flags origin) { 803 Flag* faddr = address_of_flag(flag); 804 guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type"); 805 Flag::Error check = apply_constraint_and_check_range_bool(faddr->_name, &value); 806 if (check != Flag::SUCCESS) return check; 807 trace_flag_changed<EventBooleanFlagChanged, bool>(faddr->_name, faddr->get_bool(), value, origin); 808 faddr->set_bool(value); 809 faddr->set_origin(origin); 810 return Flag::SUCCESS; 811 } 812 813 static Flag::Error apply_constraint_and_check_range_int(const char* name, int* new_value, bool verbose = true) { 814 Flag::Error range_status = Flag::SUCCESS; 815 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 816 if (range != NULL) { 817 range_status = range->check_int(*new_value, verbose); 818 } 819 Flag::Error constraint_status = Flag::SUCCESS; 820 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); 821 if (constraint != NULL) { 822 constraint_status = constraint->apply_int(new_value, verbose); 823 } 824 return get_status_error(range_status, constraint_status); 825 } 826 827 Flag::Error CommandLineFlags::intAt(const char* name, size_t len, int* value, bool allow_locked, bool return_flag) { 828 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 829 if (result == NULL) return Flag::INVALID_FLAG; 830 if (!result->is_int()) return Flag::WRONG_FORMAT; 831 *value = result->get_int(); 832 return Flag::SUCCESS; 833 } 834 835 Flag::Error CommandLineFlags::intAtPut(const char* name, size_t len, int* value, Flag::Flags origin) { 836 Flag* result = Flag::find_flag(name, len); 837 if (result == NULL) return Flag::INVALID_FLAG; 838 if (!result->is_int()) return Flag::WRONG_FORMAT; 839 Flag::Error check = apply_constraint_and_check_range_int(name, value, !CommandLineFlags::finishedInitializing()); 840 if (check != Flag::SUCCESS) return check; 841 int old_value = result->get_int(); 842 trace_flag_changed<EventIntFlagChanged, s4>(name, old_value, *value, origin); 843 result->set_int(*value); 844 *value = old_value; 845 result->set_origin(origin); 846 return Flag::SUCCESS; 847 } 848 849 Flag::Error CommandLineFlagsEx::intAtPut(CommandLineFlagWithType flag, int value, Flag::Flags origin) { 850 Flag* faddr = address_of_flag(flag); 851 guarantee(faddr != NULL && faddr->is_int(), "wrong flag type"); 852 trace_flag_changed<EventIntFlagChanged, s4>(faddr->_name, faddr->get_int(), value, origin); 853 faddr->set_int(value); 854 faddr->set_origin(origin); 855 return Flag::SUCCESS; 856 } 857 858 static Flag::Error apply_constraint_and_check_range_uint(const char* name, uint* new_value, bool verbose = true) { 859 Flag::Error range_status = Flag::SUCCESS; 860 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 861 if (range != NULL) { 862 range_status = range->check_uint(*new_value, verbose); 863 } 864 Flag::Error constraint_status = Flag::SUCCESS; 865 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); 866 if (constraint != NULL) { 867 constraint_status = constraint->apply_uint(new_value, verbose); 868 } 869 return get_status_error(range_status, constraint_status); 870 } 871 872 Flag::Error CommandLineFlags::uintAt(const char* name, size_t len, uint* value, bool allow_locked, bool return_flag) { 873 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 874 if (result == NULL) return Flag::INVALID_FLAG; 875 if (!result->is_uint()) return Flag::WRONG_FORMAT; 876 *value = result->get_uint(); 877 return Flag::SUCCESS; 878 } 879 880 Flag::Error CommandLineFlags::uintAtPut(const char* name, size_t len, uint* value, Flag::Flags origin) { 881 Flag* result = Flag::find_flag(name, len); 882 if (result == NULL) return Flag::INVALID_FLAG; 883 if (!result->is_uint()) return Flag::WRONG_FORMAT; 884 Flag::Error check = apply_constraint_and_check_range_uint(name, value, !CommandLineFlags::finishedInitializing()); 885 if (check != Flag::SUCCESS) return check; 886 uint old_value = result->get_uint(); 887 trace_flag_changed<EventUnsignedIntFlagChanged, u4>(name, old_value, *value, origin); 888 result->set_uint(*value); 889 *value = old_value; 890 result->set_origin(origin); 891 return Flag::SUCCESS; 892 } 893 894 Flag::Error CommandLineFlagsEx::uintAtPut(CommandLineFlagWithType flag, uint value, Flag::Flags origin) { 895 Flag* faddr = address_of_flag(flag); 896 guarantee(faddr != NULL && faddr->is_uint(), "wrong flag type"); 897 trace_flag_changed<EventUnsignedIntFlagChanged, u4>(faddr->_name, faddr->get_uint(), value, origin); 898 faddr->set_uint(value); 899 faddr->set_origin(origin); 900 return Flag::SUCCESS; 901 } 902 903 Flag::Error CommandLineFlags::intxAt(const char* name, size_t len, intx* value, bool allow_locked, bool return_flag) { 904 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 905 if (result == NULL) return Flag::INVALID_FLAG; 906 if (!result->is_intx()) return Flag::WRONG_FORMAT; 907 *value = result->get_intx(); 908 return Flag::SUCCESS; 909 } 910 911 static Flag::Error apply_constraint_and_check_range_intx(const char* name, intx* new_value, bool verbose = true) { 912 Flag::Error range_status = Flag::SUCCESS; 913 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 914 if (range != NULL) { 915 range_status = range->check_intx(*new_value, verbose); 916 } 917 Flag::Error constraint_status = Flag::SUCCESS; 918 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); 919 if (constraint != NULL) { 920 constraint_status = constraint->apply_intx(new_value, verbose); 921 } 922 return get_status_error(range_status, constraint_status); 923 } 924 925 Flag::Error CommandLineFlags::intxAtPut(const char* name, size_t len, intx* value, Flag::Flags origin) { 926 Flag* result = Flag::find_flag(name, len); 927 if (result == NULL) return Flag::INVALID_FLAG; 928 if (!result->is_intx()) return Flag::WRONG_FORMAT; 929 Flag::Error check = apply_constraint_and_check_range_intx(name, value, !CommandLineFlags::finishedInitializing()); 930 if (check != Flag::SUCCESS) return check; 931 intx old_value = result->get_intx(); 932 trace_flag_changed<EventLongFlagChanged, intx>(name, old_value, *value, origin); 933 result->set_intx(*value); 934 *value = old_value; 935 result->set_origin(origin); 936 return Flag::SUCCESS; 937 } 938 939 Flag::Error CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, Flag::Flags origin) { 940 Flag* faddr = address_of_flag(flag); 941 guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type"); 942 Flag::Error check = apply_constraint_and_check_range_intx(faddr->_name, &value); 943 if (check != Flag::SUCCESS) return check; 944 trace_flag_changed<EventLongFlagChanged, intx>(faddr->_name, faddr->get_intx(), value, origin); 945 faddr->set_intx(value); 946 faddr->set_origin(origin); 947 return Flag::SUCCESS; 948 } 949 950 Flag::Error CommandLineFlags::uintxAt(const char* name, size_t len, uintx* value, bool allow_locked, bool return_flag) { 951 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 952 if (result == NULL) return Flag::INVALID_FLAG; 953 if (!result->is_uintx()) return Flag::WRONG_FORMAT; 954 *value = result->get_uintx(); 955 return Flag::SUCCESS; 956 } 957 958 static Flag::Error apply_constraint_and_check_range_uintx(const char* name, uintx* new_value, bool verbose = true) { 959 Flag::Error range_status = Flag::SUCCESS; 960 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 961 if (range != NULL) { 962 range_status = range->check_uintx(*new_value, verbose); 963 } 964 Flag::Error constraint_status = Flag::SUCCESS; 965 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); 966 if (constraint != NULL) { 967 constraint_status = constraint->apply_uintx(new_value, verbose); 968 } 969 return get_status_error(range_status, constraint_status); 970 } 971 972 Flag::Error CommandLineFlags::uintxAtPut(const char* name, size_t len, uintx* value, Flag::Flags origin) { 973 Flag* result = Flag::find_flag(name, len); 974 if (result == NULL) return Flag::INVALID_FLAG; 975 if (!result->is_uintx()) return Flag::WRONG_FORMAT; 976 Flag::Error check = apply_constraint_and_check_range_uintx(name, value, !CommandLineFlags::finishedInitializing()); 977 if (check != Flag::SUCCESS) return check; 978 uintx old_value = result->get_uintx(); 979 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin); 980 result->set_uintx(*value); 981 *value = old_value; 982 result->set_origin(origin); 983 return Flag::SUCCESS; 984 } 985 986 Flag::Error CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin) { 987 Flag* faddr = address_of_flag(flag); 988 guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type"); 989 Flag::Error check = apply_constraint_and_check_range_uintx(faddr->_name, &value); 990 if (check != Flag::SUCCESS) return check; 991 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_uintx(), value, origin); 992 faddr->set_uintx(value); 993 faddr->set_origin(origin); 994 return Flag::SUCCESS; 995 } 996 997 Flag::Error CommandLineFlags::uint64_tAt(const char* name, size_t len, uint64_t* value, bool allow_locked, bool return_flag) { 998 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 999 if (result == NULL) return Flag::INVALID_FLAG; 1000 if (!result->is_uint64_t()) return Flag::WRONG_FORMAT; 1001 *value = result->get_uint64_t(); 1002 return Flag::SUCCESS; 1003 } 1004 1005 static Flag::Error apply_constraint_and_check_range_uint64_t(const char* name, uint64_t* new_value, bool verbose = true) { 1006 Flag::Error range_status = Flag::SUCCESS; 1007 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 1008 if (range != NULL) { 1009 range_status = range->check_uint64_t(*new_value, verbose); 1010 } 1011 Flag::Error constraint_status = Flag::SUCCESS; 1012 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); 1013 if (constraint != NULL) { 1014 constraint_status = constraint->apply_uint64_t(new_value, verbose); 1015 } 1016 return get_status_error(range_status, constraint_status); 1017 } 1018 1019 Flag::Error CommandLineFlags::uint64_tAtPut(const char* name, size_t len, uint64_t* value, Flag::Flags origin) { 1020 Flag* result = Flag::find_flag(name, len); 1021 if (result == NULL) return Flag::INVALID_FLAG; 1022 if (!result->is_uint64_t()) return Flag::WRONG_FORMAT; 1023 Flag::Error check = apply_constraint_and_check_range_uint64_t(name, value, !CommandLineFlags::finishedInitializing()); 1024 if (check != Flag::SUCCESS) return check; 1025 uint64_t old_value = result->get_uint64_t(); 1026 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin); 1027 result->set_uint64_t(*value); 1028 *value = old_value; 1029 result->set_origin(origin); 1030 return Flag::SUCCESS; 1031 } 1032 1033 Flag::Error CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, Flag::Flags origin) { 1034 Flag* faddr = address_of_flag(flag); 1035 guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type"); 1036 Flag::Error check = apply_constraint_and_check_range_uint64_t(faddr->_name, &value); 1037 if (check != Flag::SUCCESS) return check; 1038 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_uint64_t(), value, origin); 1039 faddr->set_uint64_t(value); 1040 faddr->set_origin(origin); 1041 return Flag::SUCCESS; 1042 } 1043 1044 Flag::Error CommandLineFlags::size_tAt(const char* name, size_t len, size_t* value, bool allow_locked, bool return_flag) { 1045 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 1046 if (result == NULL) return Flag::INVALID_FLAG; 1047 if (!result->is_size_t()) return Flag::WRONG_FORMAT; 1048 *value = result->get_size_t(); 1049 return Flag::SUCCESS; 1050 } 1051 1052 static Flag::Error apply_constraint_and_check_range_size_t(const char* name, size_t* new_value, bool verbose = true) { 1053 Flag::Error range_status = Flag::SUCCESS; 1054 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 1055 if (range != NULL) { 1056 range_status = range->check_size_t(*new_value, verbose); 1057 } 1058 Flag::Error constraint_status = Flag::SUCCESS; 1059 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); 1060 if (constraint != NULL) { 1061 constraint_status = constraint->apply_size_t(new_value, verbose); 1062 } 1063 return get_status_error(range_status, constraint_status); 1064 } 1065 1066 Flag::Error CommandLineFlags::size_tAtPut(const char* name, size_t len, size_t* value, Flag::Flags origin) { 1067 Flag* result = Flag::find_flag(name, len); 1068 if (result == NULL) return Flag::INVALID_FLAG; 1069 if (!result->is_size_t()) return Flag::WRONG_FORMAT; 1070 Flag::Error check = apply_constraint_and_check_range_size_t(name, value, !CommandLineFlags::finishedInitializing()); 1071 if (check != Flag::SUCCESS) return check; 1072 size_t old_value = result->get_size_t(); 1073 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin); 1074 result->set_size_t(*value); 1075 *value = old_value; 1076 result->set_origin(origin); 1077 return Flag::SUCCESS; 1078 } 1079 1080 Flag::Error CommandLineFlagsEx::size_tAtPut(CommandLineFlagWithType flag, size_t value, Flag::Flags origin) { 1081 Flag* faddr = address_of_flag(flag); 1082 guarantee(faddr != NULL && faddr->is_size_t(), "wrong flag type"); 1083 Flag::Error check = apply_constraint_and_check_range_size_t(faddr->_name, &value); 1084 if (check != Flag::SUCCESS) return check; 1085 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_size_t(), value, origin); 1086 faddr->set_size_t(value); 1087 faddr->set_origin(origin); 1088 return Flag::SUCCESS; 1089 } 1090 1091 Flag::Error CommandLineFlags::doubleAt(const char* name, size_t len, double* value, bool allow_locked, bool return_flag) { 1092 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 1093 if (result == NULL) return Flag::INVALID_FLAG; 1094 if (!result->is_double()) return Flag::WRONG_FORMAT; 1095 *value = result->get_double(); 1096 return Flag::SUCCESS; 1097 } 1098 1099 static Flag::Error apply_constraint_and_check_range_double(const char* name, double* new_value, bool verbose = true) { 1100 Flag::Error range_status = Flag::SUCCESS; 1101 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 1102 if (range != NULL) { 1103 range_status = range->check_double(*new_value, verbose); 1104 } 1105 Flag::Error constraint_status = Flag::SUCCESS; 1106 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name); 1107 if (constraint != NULL) { 1108 constraint_status = constraint->apply_double(new_value, verbose); 1109 } 1110 return get_status_error(range_status, constraint_status); 1111 } 1112 1113 Flag::Error CommandLineFlags::doubleAtPut(const char* name, size_t len, double* value, Flag::Flags origin) { 1114 Flag* result = Flag::find_flag(name, len); 1115 if (result == NULL) return Flag::INVALID_FLAG; 1116 if (!result->is_double()) return Flag::WRONG_FORMAT; 1117 Flag::Error check = apply_constraint_and_check_range_double(name, value, !CommandLineFlags::finishedInitializing()); 1118 if (check != Flag::SUCCESS) return check; 1119 double old_value = result->get_double(); 1120 trace_flag_changed<EventDoubleFlagChanged, double>(name, old_value, *value, origin); 1121 result->set_double(*value); 1122 *value = old_value; 1123 result->set_origin(origin); 1124 return Flag::SUCCESS; 1125 } 1126 1127 Flag::Error CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, Flag::Flags origin) { 1128 Flag* faddr = address_of_flag(flag); 1129 guarantee(faddr != NULL && faddr->is_double(), "wrong flag type"); 1130 Flag::Error check = apply_constraint_and_check_range_double(faddr->_name, &value, !CommandLineFlags::finishedInitializing()); 1131 if (check != Flag::SUCCESS) return check; 1132 trace_flag_changed<EventDoubleFlagChanged, double>(faddr->_name, faddr->get_double(), value, origin); 1133 faddr->set_double(value); 1134 faddr->set_origin(origin); 1135 return Flag::SUCCESS; 1136 } 1137 1138 Flag::Error CommandLineFlags::ccstrAt(const char* name, size_t len, ccstr* value, bool allow_locked, bool return_flag) { 1139 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 1140 if (result == NULL) return Flag::INVALID_FLAG; 1141 if (!result->is_ccstr()) return Flag::WRONG_FORMAT; 1142 *value = result->get_ccstr(); 1143 return Flag::SUCCESS; 1144 } 1145 1146 Flag::Error CommandLineFlags::ccstrAtPut(const char* name, size_t len, ccstr* value, Flag::Flags origin) { 1147 Flag* result = Flag::find_flag(name, len); 1148 if (result == NULL) return Flag::INVALID_FLAG; 1149 if (!result->is_ccstr()) return Flag::WRONG_FORMAT; 1150 ccstr old_value = result->get_ccstr(); 1193 const size_t length = Flag::numFlags - 1; 1194 1195 // Sort 1196 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length, mtInternal); 1197 for (size_t i = 0; i < length; i++) { 1198 array[i] = &flagTable[i]; 1199 } 1200 qsort(array, length, sizeof(Flag*), compare_flags); 1201 1202 // Print 1203 for (size_t i = 0; i < length; i++) { 1204 if (array[i]->get_origin() /* naked field! */) { 1205 array[i]->print_as_flag(out); 1206 out->print(" "); 1207 } 1208 } 1209 out->cr(); 1210 FREE_C_HEAP_ARRAY(Flag*, array); 1211 } 1212 1213 bool CommandLineFlags::_finished_initializing = false; 1214 1215 bool CommandLineFlags::check_all_ranges_and_constraints() { 1216 1217 //#define PRINT_RANGES_AND_CONSTRAINTS_SIZES 1218 #ifdef PRINT_RANGES_AND_CONSTRAINTS_SIZES 1219 { 1220 size_t size_ranges = sizeof(CommandLineFlagRangeList); 1221 for (int i=0; i<CommandLineFlagRangeList::length(); i++) { 1222 size_ranges += sizeof(CommandLineFlagRange); 1223 CommandLineFlagRange* range = CommandLineFlagRangeList::at(i); 1224 const char* name = range->name(); 1225 Flag* flag = Flag::find_flag(name, strlen(name), true, true); 1226 if (flag->is_intx()) { 1227 size_ranges += 2*sizeof(intx); 1228 size_ranges += sizeof(CommandLineFlagRange*); 1229 } else if (flag->is_uintx()) { 1230 size_ranges += 2*sizeof(uintx); 1231 size_ranges += sizeof(CommandLineFlagRange*); 1232 } else if (flag->is_uint64_t()) { 1233 size_ranges += 2*sizeof(uint64_t); 1234 size_ranges += sizeof(CommandLineFlagRange*); 1235 } else if (flag->is_size_t()) { 1236 size_ranges += 2*sizeof(size_t); 1237 size_ranges += sizeof(CommandLineFlagRange*); 1238 } else if (flag->is_double()) { 1239 size_ranges += 2*sizeof(double); 1240 size_ranges += sizeof(CommandLineFlagRange*); 1241 } 1242 } 1243 fprintf(stderr, "Size of %d ranges: " SIZE_FORMAT " bytes\n", 1244 CommandLineFlagRangeList::length(), size_ranges); 1245 } 1246 { 1247 size_t size_constraints = sizeof(CommandLineFlagConstraintList); 1248 for (int i=0; i<CommandLineFlagConstraintList::length(); i++) { 1249 size_constraints += sizeof(CommandLineFlagConstraint); 1250 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::at(i); 1251 const char* name = constraint->name(); 1252 Flag* flag = Flag::find_flag(name, strlen(name), true, true); 1253 if (flag->is_bool()) { 1254 size_constraints += sizeof(CommandLineFlagConstraintFunc_bool); 1255 size_constraints += sizeof(CommandLineFlagConstraint*); 1256 } else if (flag->is_intx()) { 1257 size_constraints += sizeof(CommandLineFlagConstraintFunc_intx); 1258 size_constraints += sizeof(CommandLineFlagConstraint*); 1259 } else if (flag->is_uintx()) { 1260 size_constraints += sizeof(CommandLineFlagConstraintFunc_uintx); 1261 size_constraints += sizeof(CommandLineFlagConstraint*); 1262 } else if (flag->is_uint64_t()) { 1263 size_constraints += sizeof(CommandLineFlagConstraintFunc_uint64_t); 1264 size_constraints += sizeof(CommandLineFlagConstraint*); 1265 } else if (flag->is_size_t()) { 1266 size_constraints += sizeof(CommandLineFlagConstraintFunc_size_t); 1267 size_constraints += sizeof(CommandLineFlagConstraint*); 1268 } else if (flag->is_double()) { 1269 size_constraints += sizeof(CommandLineFlagConstraintFunc_double); 1270 size_constraints += sizeof(CommandLineFlagConstraint*); 1271 } 1272 } 1273 fprintf(stderr, "Size of %d constraints: " SIZE_FORMAT " bytes\n", 1274 CommandLineFlagConstraintList::length(), size_constraints); 1275 } 1276 #endif // PRINT_RANGES_AND_CONSTRAINTS_SIZES 1277 1278 _finished_initializing = true; 1279 1280 bool status = true; 1281 for (int i=0; i<CommandLineFlagRangeList::length(); i++) { 1282 CommandLineFlagRange* range = CommandLineFlagRangeList::at(i); 1283 const char* name = range->name(); 1284 Flag* flag = Flag::find_flag(name, strlen(name), true, true); 1285 if (flag != NULL) { 1286 if (flag->is_intx()) { 1287 intx value = flag->get_intx(); 1288 if (range->check_intx(value, true) != Flag::SUCCESS) status = false; 1289 } else if (flag->is_uintx()) { 1290 uintx value = flag->get_uintx(); 1291 if (range->check_uintx(value, true) != Flag::SUCCESS) status = false; 1292 } else if (flag->is_uint64_t()) { 1293 uint64_t value = flag->get_uint64_t(); 1294 if (range->check_uint64_t(value, true) != Flag::SUCCESS) status = false; 1295 } else if (flag->is_size_t()) { 1296 size_t value = flag->get_size_t(); 1297 if (range->check_size_t(value, true) != Flag::SUCCESS) status = false; 1298 } else if (flag->is_double()) { 1299 double value = flag->get_double(); 1300 if (range->check_double(value, true) != Flag::SUCCESS) status = false; 1301 } 1302 } 1303 } 1304 for (int i=0; i<CommandLineFlagConstraintList::length(); i++) { 1305 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::at(i); 1306 const char*name = constraint->name(); 1307 Flag* flag = Flag::find_flag(name, strlen(name), true, true); 1308 if (flag != NULL) { 1309 if (flag->is_bool()) { 1310 bool value = flag->get_bool(); 1311 if (constraint->apply_bool(&value, true) != Flag::SUCCESS) status = false; 1312 } else if (flag->is_intx()) { 1313 intx value = flag->get_intx(); 1314 if (constraint->apply_intx(&value, true) != Flag::SUCCESS) status = false; 1315 } else if (flag->is_uintx()) { 1316 uintx value = flag->get_uintx(); 1317 if (constraint->apply_uintx(&value, true) != Flag::SUCCESS) status = false; 1318 } else if (flag->is_uint64_t()) { 1319 uint64_t value = flag->get_uint64_t(); 1320 if (constraint->apply_uint64_t(&value, true) != Flag::SUCCESS) status = false; 1321 } else if (flag->is_size_t()) { 1322 size_t value = flag->get_size_t(); 1323 if (constraint->apply_size_t(&value, true) != Flag::SUCCESS) status = false; 1324 } else if (flag->is_double()) { 1325 double value = flag->get_double(); 1326 if (constraint->apply_double(&value, true) != Flag::SUCCESS) status = false; 1327 } 1328 } 1329 } 1330 1331 Arguments::post_final_range_and_constraint_check(status); 1332 1333 return status; 1334 } 1335 1336 #ifndef PRODUCT 1337 1338 void CommandLineFlags::verify() { 1339 assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict"); 1340 } 1341 1342 #endif // PRODUCT 1343 1344 #define ONLY_PRINT_PRODUCT_FLAGS 1345 1346 void CommandLineFlags::printFlags(outputStream* out, bool withComments, bool printRanges) { 1347 // Print the flags sorted by name 1348 // note: this method is called before the thread structure is in place 1349 // which means resource allocation cannot be used. 1350 1351 // The last entry is the null entry. 1352 const size_t length = Flag::numFlags - 1; 1353 | 753 E e; 754 e.set_name(name); 755 e.set_old_value(old_value); 756 e.set_new_value(new_value); 757 e.set_origin(origin); 758 e.commit(); 759 } 760 761 static Flag::Error get_status_error(Flag::Error status_range, Flag::Error status_constraint) { 762 if (status_range != Flag::SUCCESS) { 763 return status_range; 764 } else if (status_constraint != Flag::SUCCESS) { 765 return status_constraint; 766 } else { 767 return Flag::SUCCESS; 768 } 769 } 770 771 static Flag::Error apply_constraint_and_check_range_bool(const char* name, bool* new_value, bool verbose = true) { 772 Flag::Error status = Flag::SUCCESS; 773 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_needs_check(name); 774 if (constraint != NULL) { 775 status = constraint->apply_bool(new_value, verbose); 776 } 777 return status; 778 } 779 780 Flag::Error CommandLineFlags::boolAt(const char* name, size_t len, bool* value, bool allow_locked, bool return_flag) { 781 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 782 if (result == NULL) return Flag::INVALID_FLAG; 783 if (!result->is_bool()) return Flag::WRONG_FORMAT; 784 *value = result->get_bool(); 785 return Flag::SUCCESS; 786 } 787 788 Flag::Error CommandLineFlags::boolAtPut(const char* name, size_t len, bool* value, Flag::Flags origin) { 789 Flag* result = Flag::find_flag(name, len); 790 if (result == NULL) return Flag::INVALID_FLAG; 791 if (!result->is_bool()) return Flag::WRONG_FORMAT; 792 Flag::Error check = apply_constraint_and_check_range_bool(name, value, !CommandLineFlagConstraintList::validated_after_ergo()); 793 if (check != Flag::SUCCESS) return check; 794 bool old_value = result->get_bool(); 795 trace_flag_changed<EventBooleanFlagChanged, bool>(name, old_value, *value, origin); 796 result->set_bool(*value); 797 *value = old_value; 798 result->set_origin(origin); 799 return Flag::SUCCESS; 800 } 801 802 Flag::Error CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, Flag::Flags origin) { 803 Flag* faddr = address_of_flag(flag); 804 guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type"); 805 Flag::Error check = apply_constraint_and_check_range_bool(faddr->_name, &value); 806 if (check != Flag::SUCCESS) return check; 807 trace_flag_changed<EventBooleanFlagChanged, bool>(faddr->_name, faddr->get_bool(), value, origin); 808 faddr->set_bool(value); 809 faddr->set_origin(origin); 810 return Flag::SUCCESS; 811 } 812 813 static Flag::Error apply_constraint_and_check_range_int(const char* name, int* new_value, bool verbose = true) { 814 Flag::Error range_status = Flag::SUCCESS; 815 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 816 if (range != NULL) { 817 range_status = range->check_int(*new_value, verbose); 818 } 819 Flag::Error constraint_status = Flag::SUCCESS; 820 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_needs_check(name); 821 if (constraint != NULL) { 822 constraint_status = constraint->apply_int(new_value, verbose); 823 } 824 return get_status_error(range_status, constraint_status); 825 } 826 827 Flag::Error CommandLineFlags::intAt(const char* name, size_t len, int* value, bool allow_locked, bool return_flag) { 828 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 829 if (result == NULL) return Flag::INVALID_FLAG; 830 if (!result->is_int()) return Flag::WRONG_FORMAT; 831 *value = result->get_int(); 832 return Flag::SUCCESS; 833 } 834 835 Flag::Error CommandLineFlags::intAtPut(const char* name, size_t len, int* value, Flag::Flags origin) { 836 Flag* result = Flag::find_flag(name, len); 837 if (result == NULL) return Flag::INVALID_FLAG; 838 if (!result->is_int()) return Flag::WRONG_FORMAT; 839 Flag::Error check = apply_constraint_and_check_range_int(name, value, !CommandLineFlagConstraintList::validated_after_ergo()); 840 if (check != Flag::SUCCESS) return check; 841 int old_value = result->get_int(); 842 trace_flag_changed<EventIntFlagChanged, s4>(name, old_value, *value, origin); 843 result->set_int(*value); 844 *value = old_value; 845 result->set_origin(origin); 846 return Flag::SUCCESS; 847 } 848 849 Flag::Error CommandLineFlagsEx::intAtPut(CommandLineFlagWithType flag, int value, Flag::Flags origin) { 850 Flag* faddr = address_of_flag(flag); 851 guarantee(faddr != NULL && faddr->is_int(), "wrong flag type"); 852 trace_flag_changed<EventIntFlagChanged, s4>(faddr->_name, faddr->get_int(), value, origin); 853 faddr->set_int(value); 854 faddr->set_origin(origin); 855 return Flag::SUCCESS; 856 } 857 858 static Flag::Error apply_constraint_and_check_range_uint(const char* name, uint* new_value, bool verbose = true) { 859 Flag::Error range_status = Flag::SUCCESS; 860 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 861 if (range != NULL) { 862 range_status = range->check_uint(*new_value, verbose); 863 } 864 Flag::Error constraint_status = Flag::SUCCESS; 865 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_needs_check(name); 866 if (constraint != NULL) { 867 constraint_status = constraint->apply_uint(new_value, verbose); 868 } 869 return get_status_error(range_status, constraint_status); 870 } 871 872 Flag::Error CommandLineFlags::uintAt(const char* name, size_t len, uint* value, bool allow_locked, bool return_flag) { 873 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 874 if (result == NULL) return Flag::INVALID_FLAG; 875 if (!result->is_uint()) return Flag::WRONG_FORMAT; 876 *value = result->get_uint(); 877 return Flag::SUCCESS; 878 } 879 880 Flag::Error CommandLineFlags::uintAtPut(const char* name, size_t len, uint* value, Flag::Flags origin) { 881 Flag* result = Flag::find_flag(name, len); 882 if (result == NULL) return Flag::INVALID_FLAG; 883 if (!result->is_uint()) return Flag::WRONG_FORMAT; 884 Flag::Error check = apply_constraint_and_check_range_uint(name, value, !CommandLineFlagConstraintList::validated_after_ergo()); 885 if (check != Flag::SUCCESS) return check; 886 uint old_value = result->get_uint(); 887 trace_flag_changed<EventUnsignedIntFlagChanged, u4>(name, old_value, *value, origin); 888 result->set_uint(*value); 889 *value = old_value; 890 result->set_origin(origin); 891 return Flag::SUCCESS; 892 } 893 894 Flag::Error CommandLineFlagsEx::uintAtPut(CommandLineFlagWithType flag, uint value, Flag::Flags origin) { 895 Flag* faddr = address_of_flag(flag); 896 guarantee(faddr != NULL && faddr->is_uint(), "wrong flag type"); 897 trace_flag_changed<EventUnsignedIntFlagChanged, u4>(faddr->_name, faddr->get_uint(), value, origin); 898 faddr->set_uint(value); 899 faddr->set_origin(origin); 900 return Flag::SUCCESS; 901 } 902 903 Flag::Error CommandLineFlags::intxAt(const char* name, size_t len, intx* value, bool allow_locked, bool return_flag) { 904 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 905 if (result == NULL) return Flag::INVALID_FLAG; 906 if (!result->is_intx()) return Flag::WRONG_FORMAT; 907 *value = result->get_intx(); 908 return Flag::SUCCESS; 909 } 910 911 static Flag::Error apply_constraint_and_check_range_intx(const char* name, intx* new_value, bool verbose = true) { 912 Flag::Error range_status = Flag::SUCCESS; 913 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 914 if (range != NULL) { 915 range_status = range->check_intx(*new_value, verbose); 916 } 917 Flag::Error constraint_status = Flag::SUCCESS; 918 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_needs_check(name); 919 if (constraint != NULL) { 920 constraint_status = constraint->apply_intx(new_value, verbose); 921 } 922 return get_status_error(range_status, constraint_status); 923 } 924 925 Flag::Error CommandLineFlags::intxAtPut(const char* name, size_t len, intx* value, Flag::Flags origin) { 926 Flag* result = Flag::find_flag(name, len); 927 if (result == NULL) return Flag::INVALID_FLAG; 928 if (!result->is_intx()) return Flag::WRONG_FORMAT; 929 Flag::Error check = apply_constraint_and_check_range_intx(name, value, !CommandLineFlagConstraintList::validated_after_ergo()); 930 if (check != Flag::SUCCESS) return check; 931 intx old_value = result->get_intx(); 932 trace_flag_changed<EventLongFlagChanged, intx>(name, old_value, *value, origin); 933 result->set_intx(*value); 934 *value = old_value; 935 result->set_origin(origin); 936 return Flag::SUCCESS; 937 } 938 939 Flag::Error CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, Flag::Flags origin) { 940 Flag* faddr = address_of_flag(flag); 941 guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type"); 942 Flag::Error check = apply_constraint_and_check_range_intx(faddr->_name, &value); 943 if (check != Flag::SUCCESS) return check; 944 trace_flag_changed<EventLongFlagChanged, intx>(faddr->_name, faddr->get_intx(), value, origin); 945 faddr->set_intx(value); 946 faddr->set_origin(origin); 947 return Flag::SUCCESS; 948 } 949 950 Flag::Error CommandLineFlags::uintxAt(const char* name, size_t len, uintx* value, bool allow_locked, bool return_flag) { 951 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 952 if (result == NULL) return Flag::INVALID_FLAG; 953 if (!result->is_uintx()) return Flag::WRONG_FORMAT; 954 *value = result->get_uintx(); 955 return Flag::SUCCESS; 956 } 957 958 static Flag::Error apply_constraint_and_check_range_uintx(const char* name, uintx* new_value, bool verbose = true) { 959 Flag::Error range_status = Flag::SUCCESS; 960 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 961 if (range != NULL) { 962 range_status = range->check_uintx(*new_value, verbose); 963 } 964 Flag::Error constraint_status = Flag::SUCCESS; 965 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_needs_check(name); 966 if (constraint != NULL) { 967 constraint_status = constraint->apply_uintx(new_value, verbose); 968 } 969 return get_status_error(range_status, constraint_status); 970 } 971 972 Flag::Error CommandLineFlags::uintxAtPut(const char* name, size_t len, uintx* value, Flag::Flags origin) { 973 Flag* result = Flag::find_flag(name, len); 974 if (result == NULL) return Flag::INVALID_FLAG; 975 if (!result->is_uintx()) return Flag::WRONG_FORMAT; 976 Flag::Error check = apply_constraint_and_check_range_uintx(name, value, !CommandLineFlagConstraintList::validated_after_ergo()); 977 if (check != Flag::SUCCESS) return check; 978 uintx old_value = result->get_uintx(); 979 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin); 980 result->set_uintx(*value); 981 *value = old_value; 982 result->set_origin(origin); 983 return Flag::SUCCESS; 984 } 985 986 Flag::Error CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin) { 987 Flag* faddr = address_of_flag(flag); 988 guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type"); 989 Flag::Error check = apply_constraint_and_check_range_uintx(faddr->_name, &value); 990 if (check != Flag::SUCCESS) return check; 991 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_uintx(), value, origin); 992 faddr->set_uintx(value); 993 faddr->set_origin(origin); 994 return Flag::SUCCESS; 995 } 996 997 Flag::Error CommandLineFlags::uint64_tAt(const char* name, size_t len, uint64_t* value, bool allow_locked, bool return_flag) { 998 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 999 if (result == NULL) return Flag::INVALID_FLAG; 1000 if (!result->is_uint64_t()) return Flag::WRONG_FORMAT; 1001 *value = result->get_uint64_t(); 1002 return Flag::SUCCESS; 1003 } 1004 1005 static Flag::Error apply_constraint_and_check_range_uint64_t(const char* name, uint64_t* new_value, bool verbose = true) { 1006 Flag::Error range_status = Flag::SUCCESS; 1007 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 1008 if (range != NULL) { 1009 range_status = range->check_uint64_t(*new_value, verbose); 1010 } 1011 Flag::Error constraint_status = Flag::SUCCESS; 1012 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_needs_check(name); 1013 if (constraint != NULL) { 1014 constraint_status = constraint->apply_uint64_t(new_value, verbose); 1015 } 1016 return get_status_error(range_status, constraint_status); 1017 } 1018 1019 Flag::Error CommandLineFlags::uint64_tAtPut(const char* name, size_t len, uint64_t* value, Flag::Flags origin) { 1020 Flag* result = Flag::find_flag(name, len); 1021 if (result == NULL) return Flag::INVALID_FLAG; 1022 if (!result->is_uint64_t()) return Flag::WRONG_FORMAT; 1023 Flag::Error check = apply_constraint_and_check_range_uint64_t(name, value, !CommandLineFlagConstraintList::validated_after_ergo()); 1024 if (check != Flag::SUCCESS) return check; 1025 uint64_t old_value = result->get_uint64_t(); 1026 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin); 1027 result->set_uint64_t(*value); 1028 *value = old_value; 1029 result->set_origin(origin); 1030 return Flag::SUCCESS; 1031 } 1032 1033 Flag::Error CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, Flag::Flags origin) { 1034 Flag* faddr = address_of_flag(flag); 1035 guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type"); 1036 Flag::Error check = apply_constraint_and_check_range_uint64_t(faddr->_name, &value); 1037 if (check != Flag::SUCCESS) return check; 1038 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_uint64_t(), value, origin); 1039 faddr->set_uint64_t(value); 1040 faddr->set_origin(origin); 1041 return Flag::SUCCESS; 1042 } 1043 1044 Flag::Error CommandLineFlags::size_tAt(const char* name, size_t len, size_t* value, bool allow_locked, bool return_flag) { 1045 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 1046 if (result == NULL) return Flag::INVALID_FLAG; 1047 if (!result->is_size_t()) return Flag::WRONG_FORMAT; 1048 *value = result->get_size_t(); 1049 return Flag::SUCCESS; 1050 } 1051 1052 static Flag::Error apply_constraint_and_check_range_size_t(const char* name, size_t* new_value, bool verbose = true) { 1053 Flag::Error range_status = Flag::SUCCESS; 1054 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 1055 if (range != NULL) { 1056 range_status = range->check_size_t(*new_value, verbose); 1057 } 1058 Flag::Error constraint_status = Flag::SUCCESS; 1059 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_needs_check(name); 1060 if (constraint != NULL) { 1061 constraint_status = constraint->apply_size_t(new_value, verbose); 1062 } 1063 return get_status_error(range_status, constraint_status); 1064 } 1065 1066 Flag::Error CommandLineFlags::size_tAtPut(const char* name, size_t len, size_t* value, Flag::Flags origin) { 1067 Flag* result = Flag::find_flag(name, len); 1068 if (result == NULL) return Flag::INVALID_FLAG; 1069 if (!result->is_size_t()) return Flag::WRONG_FORMAT; 1070 Flag::Error check = apply_constraint_and_check_range_size_t(name, value, !CommandLineFlagConstraintList::validated_after_ergo()); 1071 if (check != Flag::SUCCESS) return check; 1072 size_t old_value = result->get_size_t(); 1073 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin); 1074 result->set_size_t(*value); 1075 *value = old_value; 1076 result->set_origin(origin); 1077 return Flag::SUCCESS; 1078 } 1079 1080 Flag::Error CommandLineFlagsEx::size_tAtPut(CommandLineFlagWithType flag, size_t value, Flag::Flags origin) { 1081 Flag* faddr = address_of_flag(flag); 1082 guarantee(faddr != NULL && faddr->is_size_t(), "wrong flag type"); 1083 Flag::Error check = apply_constraint_and_check_range_size_t(faddr->_name, &value); 1084 if (check != Flag::SUCCESS) return check; 1085 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_size_t(), value, origin); 1086 faddr->set_size_t(value); 1087 faddr->set_origin(origin); 1088 return Flag::SUCCESS; 1089 } 1090 1091 Flag::Error CommandLineFlags::doubleAt(const char* name, size_t len, double* value, bool allow_locked, bool return_flag) { 1092 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 1093 if (result == NULL) return Flag::INVALID_FLAG; 1094 if (!result->is_double()) return Flag::WRONG_FORMAT; 1095 *value = result->get_double(); 1096 return Flag::SUCCESS; 1097 } 1098 1099 static Flag::Error apply_constraint_and_check_range_double(const char* name, double* new_value, bool verbose = true) { 1100 Flag::Error range_status = Flag::SUCCESS; 1101 CommandLineFlagRange* range = CommandLineFlagRangeList::find(name); 1102 if (range != NULL) { 1103 range_status = range->check_double(*new_value, verbose); 1104 } 1105 Flag::Error constraint_status = Flag::SUCCESS; 1106 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find_if_needs_check(name); 1107 if (constraint != NULL) { 1108 constraint_status = constraint->apply_double(new_value, verbose); 1109 } 1110 return get_status_error(range_status, constraint_status); 1111 } 1112 1113 Flag::Error CommandLineFlags::doubleAtPut(const char* name, size_t len, double* value, Flag::Flags origin) { 1114 Flag* result = Flag::find_flag(name, len); 1115 if (result == NULL) return Flag::INVALID_FLAG; 1116 if (!result->is_double()) return Flag::WRONG_FORMAT; 1117 Flag::Error check = apply_constraint_and_check_range_double(name, value, !CommandLineFlagConstraintList::validated_after_ergo()); 1118 if (check != Flag::SUCCESS) return check; 1119 double old_value = result->get_double(); 1120 trace_flag_changed<EventDoubleFlagChanged, double>(name, old_value, *value, origin); 1121 result->set_double(*value); 1122 *value = old_value; 1123 result->set_origin(origin); 1124 return Flag::SUCCESS; 1125 } 1126 1127 Flag::Error CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, Flag::Flags origin) { 1128 Flag* faddr = address_of_flag(flag); 1129 guarantee(faddr != NULL && faddr->is_double(), "wrong flag type"); 1130 Flag::Error check = apply_constraint_and_check_range_double(faddr->_name, &value); 1131 if (check != Flag::SUCCESS) return check; 1132 trace_flag_changed<EventDoubleFlagChanged, double>(faddr->_name, faddr->get_double(), value, origin); 1133 faddr->set_double(value); 1134 faddr->set_origin(origin); 1135 return Flag::SUCCESS; 1136 } 1137 1138 Flag::Error CommandLineFlags::ccstrAt(const char* name, size_t len, ccstr* value, bool allow_locked, bool return_flag) { 1139 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag); 1140 if (result == NULL) return Flag::INVALID_FLAG; 1141 if (!result->is_ccstr()) return Flag::WRONG_FORMAT; 1142 *value = result->get_ccstr(); 1143 return Flag::SUCCESS; 1144 } 1145 1146 Flag::Error CommandLineFlags::ccstrAtPut(const char* name, size_t len, ccstr* value, Flag::Flags origin) { 1147 Flag* result = Flag::find_flag(name, len); 1148 if (result == NULL) return Flag::INVALID_FLAG; 1149 if (!result->is_ccstr()) return Flag::WRONG_FORMAT; 1150 ccstr old_value = result->get_ccstr(); 1193 const size_t length = Flag::numFlags - 1; 1194 1195 // Sort 1196 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length, mtInternal); 1197 for (size_t i = 0; i < length; i++) { 1198 array[i] = &flagTable[i]; 1199 } 1200 qsort(array, length, sizeof(Flag*), compare_flags); 1201 1202 // Print 1203 for (size_t i = 0; i < length; i++) { 1204 if (array[i]->get_origin() /* naked field! */) { 1205 array[i]->print_as_flag(out); 1206 out->print(" "); 1207 } 1208 } 1209 out->cr(); 1210 FREE_C_HEAP_ARRAY(Flag*, array); 1211 } 1212 1213 bool CommandLineFlags::check_ranges() { 1214 //#define PRINT_RANGES_SIZES 1215 #ifdef PRINT_RANGES_SIZES 1216 { 1217 size_t size_ranges = sizeof(CommandLineFlagRangeList); 1218 for (int i=0; i<CommandLineFlagRangeList::length(); i++) { 1219 size_ranges += sizeof(CommandLineFlagRange); 1220 CommandLineFlagRange* range = CommandLineFlagRangeList::at(i); 1221 const char* name = range->name(); 1222 Flag* flag = Flag::find_flag(name, strlen(name), true, true); 1223 if (flag->is_intx()) { 1224 size_ranges += 2*sizeof(intx); 1225 size_ranges += sizeof(CommandLineFlagRange*); 1226 } else if (flag->is_uintx()) { 1227 size_ranges += 2*sizeof(uintx); 1228 size_ranges += sizeof(CommandLineFlagRange*); 1229 } else if (flag->is_uint64_t()) { 1230 size_ranges += 2*sizeof(uint64_t); 1231 size_ranges += sizeof(CommandLineFlagRange*); 1232 } else if (flag->is_size_t()) { 1233 size_ranges += 2*sizeof(size_t); 1234 size_ranges += sizeof(CommandLineFlagRange*); 1235 } else if (flag->is_double()) { 1236 size_ranges += 2*sizeof(double); 1237 size_ranges += sizeof(CommandLineFlagRange*); 1238 } 1239 } 1240 fprintf(stderr, "Size of %d ranges: " SIZE_FORMAT " bytes\n", 1241 CommandLineFlagRangeList::length(), size_ranges); 1242 } 1243 #endif // PRINT_RANGES_SIZES 1244 1245 // Check ranges. 1246 bool status = true; 1247 for (int i=0; i<CommandLineFlagRangeList::length(); i++) { 1248 CommandLineFlagRange* range = CommandLineFlagRangeList::at(i); 1249 const char* name = range->name(); 1250 Flag* flag = Flag::find_flag(name, strlen(name), true, true); 1251 if (flag != NULL) { 1252 if (flag->is_intx()) { 1253 intx value = flag->get_intx(); 1254 if (range->check_intx(value, true) != Flag::SUCCESS) status = false; 1255 } else if (flag->is_uintx()) { 1256 uintx value = flag->get_uintx(); 1257 if (range->check_uintx(value, true) != Flag::SUCCESS) status = false; 1258 } else if (flag->is_uint64_t()) { 1259 uint64_t value = flag->get_uint64_t(); 1260 if (range->check_uint64_t(value, true) != Flag::SUCCESS) status = false; 1261 } else if (flag->is_size_t()) { 1262 size_t value = flag->get_size_t(); 1263 if (range->check_size_t(value, true) != Flag::SUCCESS) status = false; 1264 } else if (flag->is_double()) { 1265 double value = flag->get_double(); 1266 if (range->check_double(value, true) != Flag::SUCCESS) status = false; 1267 } 1268 } 1269 } 1270 return status; 1271 } 1272 1273 // Check constraints for specific constraint type. 1274 static bool check_constraints(CommandLineFlagConstraint::ConstraintType constraint_type) { 1275 //#define PRINT_CONSTRAINTS_SIZES 1276 #ifdef PRINT_CONSTRAINTS_SIZES 1277 { 1278 size_t size_constraints = sizeof(CommandLineFlagConstraintList); 1279 for (int i=0; i<CommandLineFlagConstraintList::length(); i++) { 1280 size_constraints += sizeof(CommandLineFlagConstraint); 1281 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::at(i); 1282 const char* name = constraint->name(); 1283 Flag* flag = Flag::find_flag(name, strlen(name), true, true); 1284 if (flag->is_bool()) { 1285 size_constraints += sizeof(CommandLineFlagConstraintFunc_bool); 1286 size_constraints += sizeof(CommandLineFlagConstraint*); 1287 } else if (flag->is_intx()) { 1288 size_constraints += sizeof(CommandLineFlagConstraintFunc_intx); 1289 size_constraints += sizeof(CommandLineFlagConstraint*); 1290 } else if (flag->is_uintx()) { 1291 size_constraints += sizeof(CommandLineFlagConstraintFunc_uintx); 1292 size_constraints += sizeof(CommandLineFlagConstraint*); 1293 } else if (flag->is_uint64_t()) { 1294 size_constraints += sizeof(CommandLineFlagConstraintFunc_uint64_t); 1295 size_constraints += sizeof(CommandLineFlagConstraint*); 1296 } else if (flag->is_size_t()) { 1297 size_constraints += sizeof(CommandLineFlagConstraintFunc_size_t); 1298 size_constraints += sizeof(CommandLineFlagConstraint*); 1299 } else if (flag->is_double()) { 1300 size_constraints += sizeof(CommandLineFlagConstraintFunc_double); 1301 size_constraints += sizeof(CommandLineFlagConstraint*); 1302 } 1303 } 1304 fprintf(stderr, "Size of %d constraints: " SIZE_FORMAT " bytes\n", 1305 CommandLineFlagConstraintList::length(), size_constraints); 1306 } 1307 #endif // PRINT_CONSTRAINTS_SIZES 1308 1309 bool status = true; 1310 for (int i=0; i<CommandLineFlagConstraintList::length(); i++) { 1311 CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::at(i); 1312 if (constraint_type != constraint->type()) continue; 1313 const char*name = constraint->name(); 1314 Flag* flag = Flag::find_flag(name, strlen(name), true, true); 1315 if (flag != NULL) { 1316 if (flag->is_bool()) { 1317 bool value = flag->get_bool(); 1318 if (constraint->apply_bool(&value, true) != Flag::SUCCESS) status = false; 1319 } else if (flag->is_intx()) { 1320 intx value = flag->get_intx(); 1321 if (constraint->apply_intx(&value, true) != Flag::SUCCESS) status = false; 1322 } else if (flag->is_uintx()) { 1323 uintx value = flag->get_uintx(); 1324 if (constraint->apply_uintx(&value, true) != Flag::SUCCESS) status = false; 1325 } else if (flag->is_uint64_t()) { 1326 uint64_t value = flag->get_uint64_t(); 1327 if (constraint->apply_uint64_t(&value, true) != Flag::SUCCESS) status = false; 1328 } else if (flag->is_size_t()) { 1329 size_t value = flag->get_size_t(); 1330 if (constraint->apply_size_t(&value, true) != Flag::SUCCESS) status = false; 1331 } else if (flag->is_double()) { 1332 double value = flag->get_double(); 1333 if (constraint->apply_double(&value, true) != Flag::SUCCESS) status = false; 1334 } 1335 } 1336 } 1337 return status; 1338 } 1339 1340 // Check constraints and do post work of 'AfterErgo'. 1341 bool CommandLineFlags::check_constraints_of_after_ergo() { 1342 CommandLineFlagConstraintList::set_validating_type(CommandLineFlagConstraint::AfterErgo); 1343 1344 bool status = check_constraints(CommandLineFlagConstraint::AfterErgo); 1345 1346 Arguments::post_after_ergo_constraint_check(status); 1347 1348 return status; 1349 } 1350 1351 // Check constraints of 'AfterMemoryInit'. 1352 bool CommandLineFlags::check_constraints_of_after_memory_init() { 1353 CommandLineFlagConstraintList::set_validating_type(CommandLineFlagConstraint::AfterMemoryInit); 1354 1355 return check_constraints(CommandLineFlagConstraint::AfterMemoryInit); 1356 } 1357 1358 #ifndef PRODUCT 1359 1360 void CommandLineFlags::verify() { 1361 assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict"); 1362 } 1363 1364 #endif // PRODUCT 1365 1366 #define ONLY_PRINT_PRODUCT_FLAGS 1367 1368 void CommandLineFlags::printFlags(outputStream* out, bool withComments, bool printRanges) { 1369 // Print the flags sorted by name 1370 // note: this method is called before the thread structure is in place 1371 // which means resource allocation cannot be used. 1372 1373 // The last entry is the null entry. 1374 const size_t length = Flag::numFlags - 1; 1375 |