use of com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod.CallVariant in project graal by oracle.
the class JNIFunctionTablesFeature method buildFunctionsInitializer.
private JNIStructFunctionsInitializer<JNINativeInterface> buildFunctionsInitializer(CompilationAccessImpl access, CFunctionPointer unimplemented) {
Class<JNIFunctions> clazz = JNIFunctions.class;
HostedType functions = access.getMetaAccess().lookupJavaType(clazz);
HostedMethod[] methods = functions.getDeclaredMethods();
int index = 0;
int count = methods.length + generatedMethods.length;
// Call, CallStatic, CallNonvirtual: for each return value kind: array, va_list, varargs
// NewObject: array, va_list, varargs
count += (jniKinds.size() * 3 + 1) * 3;
int[] offsets = new int[count];
CFunctionPointer[] pointers = new CFunctionPointer[offsets.length];
for (HostedMethod method : methods) {
StructFieldInfo field = findFieldFor(functionTableMetadata, method.getName());
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = getStubFunctionPointer(access, method);
index++;
}
for (ResolvedJavaMethod accessor : generatedMethods) {
StructFieldInfo field = findFieldFor(functionTableMetadata, accessor.getName());
AnalysisUniverse analysisUniverse = access.getUniverse().getBigBang().getUniverse();
AnalysisMethod analysisMethod = analysisUniverse.lookup(accessor);
HostedMethod hostedMethod = access.getUniverse().lookup(analysisMethod);
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = MethodPointer.factory(hostedMethod);
index++;
}
for (CallVariant variant : CallVariant.values()) {
CFunctionPointer trampoline = prepareCallTrampoline(access, variant, false);
String suffix = (variant == CallVariant.ARRAY) ? "A" : ((variant == CallVariant.VA_LIST) ? "V" : "");
CFunctionPointer nonvirtualTrampoline = prepareCallTrampoline(access, variant, true);
for (JavaKind kind : jniKinds) {
String[] prefixes = { "Call", "CallStatic" };
for (String prefix : prefixes) {
StructFieldInfo field = findFieldFor(functionTableMetadata, prefix + kind.name() + "Method" + suffix);
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = trampoline;
index++;
}
StructFieldInfo field = findFieldFor(functionTableMetadata, "CallNonvirtual" + kind.name() + "Method" + suffix);
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = nonvirtualTrampoline;
index++;
}
StructFieldInfo field = findFieldFor(functionTableMetadata, "NewObject" + suffix);
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = trampoline;
index++;
}
VMError.guarantee(index == offsets.length && index == pointers.length);
return new JNIStructFunctionsInitializer<>(JNINativeInterface.class, offsets, pointers, unimplemented);
}
Aggregations