Mercurial > hg > graal-jvmci-8
comparison src/share/vm/graal/graalRuntime.cpp @ 21031:e1c063565b3c
Graal Services: use services files in jre/lib/graal/services
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Wed, 15 Apr 2015 18:21:00 +0200 |
parents | 23433619a7cd |
children | 4527d2428f37 |
comparison
equal
deleted
inserted
replaced
21030:c8166c23047d | 21031:e1c063565b3c |
---|---|
628 JVM_ENTRY(jobject, JVM_GetGraalRuntime(JNIEnv *env, jclass c)) | 628 JVM_ENTRY(jobject, JVM_GetGraalRuntime(JNIEnv *env, jclass c)) |
629 GraalRuntime::initialize_HotSpotGraalRuntime(); | 629 GraalRuntime::initialize_HotSpotGraalRuntime(); |
630 return GraalRuntime::get_HotSpotGraalRuntime_jobject(); | 630 return GraalRuntime::get_HotSpotGraalRuntime_jobject(); |
631 JVM_END | 631 JVM_END |
632 | 632 |
633 // private static String[] Graal.getServiceImpls(Class service) | 633 // private static String[] Services.getServiceImpls(Class service) |
634 JVM_ENTRY(jobject, JVM_GetGraalServiceImpls(JNIEnv *env, jclass c, jclass serviceClass)) | 634 JVM_ENTRY(jobject, JVM_GetGraalServiceImpls(JNIEnv *env, jclass c, jclass serviceClass)) |
635 HandleMark hm; | 635 HandleMark hm; |
636 ResourceMark rm; | |
636 KlassHandle serviceKlass(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(serviceClass))); | 637 KlassHandle serviceKlass(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(serviceClass))); |
637 return JNIHandles::make_local(THREAD, GraalRuntime::get_service_impls(serviceKlass, THREAD)()); | 638 return JNIHandles::make_local(THREAD, GraalRuntime::get_service_impls(serviceKlass, THREAD)()); |
638 JVM_END | 639 JVM_END |
639 | 640 |
640 // private static TruffleRuntime Truffle.createRuntime() | 641 // private static TruffleRuntime Truffle.createRuntime() |
1072 vm_abort(false); | 1073 vm_abort(false); |
1073 } | 1074 } |
1074 return klass; | 1075 return klass; |
1075 } | 1076 } |
1076 | 1077 |
1078 Handle GraalRuntime::get_service_impls(KlassHandle serviceKlass, TRAPS) { | |
1079 const char* home = Arguments::get_java_home(); | |
1080 const char* serviceName = serviceKlass->external_name(); | |
1081 size_t path_len = strlen(home) + strlen("/lib/graal/services/") + strlen(serviceName) + 1; | |
1082 char* path = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, path_len); | |
1083 char sep = os::file_separator()[0]; | |
1084 sprintf(path, "%s%clib%cgraal%cservices%c%s", home, sep, sep, sep, sep, serviceName); | |
1085 struct stat st; | |
1086 if (os::stat(path, &st) == 0) { | |
1087 int file_handle = os::open(path, 0, 0); | |
1088 if (file_handle != -1) { | |
1089 char* buffer = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, st.st_size + 1); | |
1090 int num_read = (int) os::read(file_handle, (char*) buffer, st.st_size); | |
1091 if (num_read == -1) { | |
1092 warning("Error reading file %s due to %s", path, strerror(errno)); | |
1093 } else if (num_read != st.st_size) { | |
1094 warning("Only read %d of " SIZE_FORMAT " bytes from %s", num_read, (size_t) st.st_size, path); | |
1095 } | |
1096 os::close(file_handle); | |
1097 if (num_read == st.st_size) { | |
1098 buffer[num_read] = '\0'; | |
1099 GrowableArray<char*>* implNames = new GrowableArray<char*>(); | |
1100 char* line = buffer; | |
1101 while (line - buffer < num_read) { | |
1102 char* nl = strchr(line, '\n'); | |
1103 if (nl != NULL) { | |
1104 *nl = '\0'; | |
1105 } | |
1106 // Turn all '.'s into '/'s | |
1107 for (size_t index = 0; line[index] != '\0'; index++) { | |
1108 if (line[index] == '.') { | |
1109 line[index] = '/'; | |
1110 } | |
1111 } | |
1112 implNames->append(line); | |
1113 if (nl != NULL) { | |
1114 line = nl + 1; | |
1115 } else { | |
1116 // File without newline at the end | |
1117 break; | |
1118 } | |
1119 } | |
1120 | |
1121 objArrayOop servicesOop = oopFactory::new_objArray(serviceKlass(), implNames->length(), CHECK_NH); | |
1122 objArrayHandle services(THREAD, servicesOop); | |
1123 for (int i = 0; i < implNames->length(); ++i) { | |
1124 char* implName = implNames->at(i); | |
1125 Handle service = create_Service(implName, CHECK_NH); | |
1126 services->obj_at_put(i, service()); | |
1127 } | |
1128 return services; | |
1129 } | |
1130 } else { | |
1131 warning("Error opening file %s due to %s", path, strerror(errno)); | |
1132 } | |
1133 } else { | |
1134 warning("Error opening file %s due to %s", path, strerror(errno)); | |
1135 } | |
1136 return Handle(); | |
1137 } | |
1138 | |
1077 #include "graalRuntime.inline.hpp" | 1139 #include "graalRuntime.inline.hpp" |