comparison src/share/vm/graal/graalRuntime.cpp @ 21516:fe4a77bec5b7

Use GraalRuntime::parse_lines in GraalRuntime::parse_graal_options_file
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Thu, 07 May 2015 16:59:34 +0200
parents 1ab7802d35c9
children cecb4e39521c
comparison
equal deleted inserted replaced
21515:1ab7802d35c9 21516:fe4a77bec5b7
864 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); 864 THROW_MSG(vmSymbols::java_lang_InternalError(), buf);
865 } 865 }
866 } 866 }
867 } 867 }
868 868
869 class GraalOptionParseClosure : public ParseClosure {
870 TRAPS;
871 KlassHandle _hotSpotOptionsClass;
872 public:
873 GraalOptionParseClosure(KlassHandle hotSpotOptionsClass, TRAPS) : THREAD(THREAD), _hotSpotOptionsClass(hotSpotOptionsClass) {}
874 void do_line(char* line) {
875 GraalRuntime::parse_argument(_hotSpotOptionsClass, line, THREAD);
876 if (HAS_PENDING_EXCEPTION) {
877 warn_and_abort("Exception thrown while parsing argument");
878 }
879 }
880 };
881
869 void GraalRuntime::parse_graal_options_file(KlassHandle hotSpotOptionsClass, TRAPS) { 882 void GraalRuntime::parse_graal_options_file(KlassHandle hotSpotOptionsClass, TRAPS) {
870 const char* home = Arguments::get_java_home(); 883 const char* home = Arguments::get_java_home();
871 size_t path_len = strlen(home) + strlen("/lib/graal.options") + 1; 884 size_t path_len = strlen(home) + strlen("/lib/graal.options") + 1;
872 char* path = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, path_len); 885 char* path = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, path_len);
873 char sep = os::file_separator()[0]; 886 char sep = os::file_separator()[0];
874 sprintf(path, "%s%clib%cgraal.options", home, sep, sep); 887 sprintf(path, "%s%clib%cgraal.options", home, sep, sep);
875 888 GraalOptionParseClosure closure(hotSpotOptionsClass, THREAD);
876 struct stat st; 889 parse_lines(path, &closure, false, THREAD);
877 if (os::stat(path, &st) == 0) {
878 int file_handle = os::open(path, 0, 0);
879 if (file_handle != -1) {
880 char* buffer = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, st.st_size);
881 int num_read = (int) os::read(file_handle, (char*) buffer, st.st_size);
882 if (num_read == -1) {
883 warning("Error reading file %s due to %s", path, strerror(errno));
884 } else if (num_read != st.st_size) {
885 warning("Only read %d of " SIZE_FORMAT " bytes from %s", num_read, (size_t) st.st_size, path);
886 }
887 os::close(file_handle);
888 if (num_read == st.st_size) {
889 char* line = buffer;
890 int lineNo = 1;
891 while (line - buffer < num_read) {
892 char* nl = strchr(line, '\n');
893 if (nl != NULL) {
894 *nl = '\0';
895 }
896 parse_argument(hotSpotOptionsClass, line, THREAD);
897 if (HAS_PENDING_EXCEPTION) {
898 warning("Error in %s:%d", path, lineNo);
899 return;
900 }
901 if (nl != NULL) {
902 line = nl + 1;
903 lineNo++;
904 } else {
905 // File without newline at the end
906 break;
907 }
908 }
909 }
910 } else {
911 warning("Error opening file %s due to %s", path, strerror(errno));
912 }
913 }
914 } 890 }
915 891
916 jlong GraalRuntime::parse_primitive_option_value(char spec, const char* name, size_t name_len, const char* value, TRAPS) { 892 jlong GraalRuntime::parse_primitive_option_value(char spec, const char* name, size_t name_len, const char* value, TRAPS) {
917 check_required_value(name, name_len, value, CHECK_(0L)); 893 check_required_value(name, name_len, value, CHECK_(0L));
918 union { 894 union {
1074 vm_abort(false); 1050 vm_abort(false);
1075 } 1051 }
1076 return klass; 1052 return klass;
1077 } 1053 }
1078 1054
1079 void GraalRuntime::parse_lines(char* path, ParseClosure* closure, TRAPS) { 1055 void GraalRuntime::parse_lines(char* path, ParseClosure* closure, bool warnStatFailure, TRAPS) {
1080 struct stat st; 1056 struct stat st;
1081 if (os::stat(path, &st) == 0) { 1057 if (os::stat(path, &st) == 0) {
1082 int file_handle = os::open(path, 0, 0); 1058 int file_handle = os::open(path, 0, 0);
1083 if (file_handle != -1) { 1059 if (file_handle != -1) {
1084 char* buffer = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, st.st_size + 1); 1060 char* buffer = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, st.st_size + 1);
1087 warning("Error reading file %s due to %s", path, strerror(errno)); 1063 warning("Error reading file %s due to %s", path, strerror(errno));
1088 } else if (num_read != st.st_size) { 1064 } else if (num_read != st.st_size) {
1089 warning("Only read %d of " SIZE_FORMAT " bytes from %s", num_read, (size_t) st.st_size, path); 1065 warning("Only read %d of " SIZE_FORMAT " bytes from %s", num_read, (size_t) st.st_size, path);
1090 } 1066 }
1091 os::close(file_handle); 1067 os::close(file_handle);
1068 closure->set_filename(path);
1092 if (num_read == st.st_size) { 1069 if (num_read == st.st_size) {
1093 buffer[num_read] = '\0'; 1070 buffer[num_read] = '\0';
1094 1071
1095 char* line = buffer; 1072 char* line = buffer;
1096 while (line - buffer < num_read) { 1073 while (line - buffer < num_read && !closure->is_aborted()) {
1097 // find line end (\r, \n or \r\n) 1074 // find line end (\r, \n or \r\n)
1098 char* nextline = NULL; 1075 char* nextline = NULL;
1099 char* cr = strchr(line, '\r'); 1076 char* cr = strchr(line, '\r');
1100 char* lf = strchr(line, '\n'); 1077 char* lf = strchr(line, '\n');
1101 if (cr != NULL && lf != NULL) { 1078 if (cr != NULL && lf != NULL) {
1119 // trim right 1096 // trim right
1120 while (end > line && (*(end -1) == ' ' || *(end -1) == '\t')) end--; 1097 while (end > line && (*(end -1) == ' ' || *(end -1) == '\t')) end--;
1121 *end = '\0'; 1098 *end = '\0';
1122 // skip comments and empty lines 1099 // skip comments and empty lines
1123 if (*line != '#' && strlen(line) > 0) { 1100 if (*line != '#' && strlen(line) > 0) {
1124 closure->do_line(line); 1101 closure->parse_line(line);
1125 } 1102 }
1126 if (nextline != NULL) { 1103 if (nextline != NULL) {
1127 line = nextline; 1104 line = nextline;
1128 } else { 1105 } else {
1129 // File without newline at the end 1106 // File without newline at the end
1132 } 1109 }
1133 } 1110 }
1134 } else { 1111 } else {
1135 warning("Error opening file %s due to %s", path, strerror(errno)); 1112 warning("Error opening file %s due to %s", path, strerror(errno));
1136 } 1113 }
1137 } else { 1114 } else if (warnStatFailure) {
1138 warning("Error opening file %s due to %s", path, strerror(errno)); 1115 warning("Could not stat file %s due to %s", path, strerror(errno));
1139 } 1116 }
1140 } 1117 }
1141 1118
1142 class ServiceParseClosure : public ParseClosure { 1119 class ServiceParseClosure : public ParseClosure {
1143 GrowableArray<char*> _implNames; 1120 GrowableArray<char*> _implNames;
1162 size_t path_len = strlen(home) + strlen("/lib/graal/services/") + strlen(serviceName) + 1; 1139 size_t path_len = strlen(home) + strlen("/lib/graal/services/") + strlen(serviceName) + 1;
1163 char* path = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, path_len); 1140 char* path = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, path_len);
1164 char sep = os::file_separator()[0]; 1141 char sep = os::file_separator()[0];
1165 sprintf(path, "%s%clib%cgraal%cservices%c%s", home, sep, sep, sep, sep, serviceName); 1142 sprintf(path, "%s%clib%cgraal%cservices%c%s", home, sep, sep, sep, sep, serviceName);
1166 ServiceParseClosure closure; 1143 ServiceParseClosure closure;
1167 parse_lines(path, &closure, THREAD); 1144 parse_lines(path, &closure, true, THREAD);
1168 1145
1169 GrowableArray<char*>* implNames = closure.implNames(); 1146 GrowableArray<char*>* implNames = closure.implNames();
1170 objArrayOop servicesOop = oopFactory::new_objArray(serviceKlass(), implNames->length(), CHECK_NH); 1147 objArrayOop servicesOop = oopFactory::new_objArray(serviceKlass(), implNames->length(), CHECK_NH);
1171 objArrayHandle services(THREAD, servicesOop); 1148 objArrayHandle services(THREAD, servicesOop);
1172 for (int i = 0; i < implNames->length(); ++i) { 1149 for (int i = 0; i < implNames->length(); ++i) {