use of com.oracle.svm.hosted.c.info.StructFieldInfo in project graal by oracle.
the class RawStructureLayoutPlanner method planLayout.
/**
* Compute the offsets of each field.
*/
private void planLayout(RawStructureInfo info) {
/* Inherit from the parent type. */
int currentOffset = info.getParentInfo() != null ? info.getParentInfo().getSizeInfo().getProperty() : 0;
List<StructFieldInfo> fields = new ArrayList<>();
for (ElementInfo child : info.getChildren()) {
if (child instanceof StructFieldInfo) {
fields.add((StructFieldInfo) child);
} else if (child instanceof StructBitfieldInfo) {
throw UserError.abort("StructBitfield is currently not supported by RawStructures!");
}
}
/*
* Sort fields in field size descending order. Note that prior to this, the fields are
* already sorted in alphabetical order.
*/
fields.sort((f1, f2) -> f2.getSizeInfo().getProperty() - f1.getSizeInfo().getProperty());
for (StructFieldInfo finfo : fields) {
assert findParentFieldInfo(finfo, info.getParentInfo()) == null;
int fieldSize = finfo.getSizeInfo().getProperty();
currentOffset = alignOffset(currentOffset, fieldSize);
assert currentOffset % fieldSize == 0;
finfo.getOffsetInfo().setProperty(currentOffset);
currentOffset += fieldSize;
}
info.getSizeInfo().setProperty(currentOffset);
info.setPlanned();
}
use of com.oracle.svm.hosted.c.info.StructFieldInfo in project graal by oracle.
the class JNIFunctionTablesFeature method buildInvokesInitializer.
private JNIStructFunctionsInitializer<JNIInvokeInterface> buildInvokesInitializer(CompilationAccessImpl access, CFunctionPointer unimplemented) {
HostedType invokes = access.getMetaAccess().lookupJavaType(JNIInvocationInterface.class);
HostedMethod[] methods = invokes.getDeclaredMethods();
int index = 0;
int[] offsets = new int[methods.length];
CFunctionPointer[] pointers = new CFunctionPointer[offsets.length];
for (HostedMethod method : methods) {
StructFieldInfo field = findFieldFor(invokeInterfaceMetadata, method.getName());
offsets[index] = field.getOffsetInfo().getProperty();
pointers[index] = getStubFunctionPointer(access, method);
index++;
}
VMError.guarantee(index == offsets.length && index == pointers.length);
return new JNIStructFunctionsInitializer<>(JNIInvokeInterface.class, offsets, pointers, unimplemented);
}
use of com.oracle.svm.hosted.c.info.StructFieldInfo 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);
}
use of com.oracle.svm.hosted.c.info.StructFieldInfo in project graal by oracle.
the class JNIJavaCallWrapperMethod method getJNIValueOffsetOf.
private StructFieldInfo getJNIValueOffsetOf(ResolvedJavaType jniValueType, JavaKind kind) {
String name = String.valueOf(kind.isObject() ? 'l' : Character.toLowerCase(kind.getTypeChar()));
StructInfo structInfo = (StructInfo) nativeLibs.findElementInfo(jniValueType);
for (ElementInfo elementInfo : structInfo.getChildren()) {
if (elementInfo instanceof StructFieldInfo) {
StructFieldInfo fieldInfo = (StructFieldInfo) elementInfo;
if (name.equals(fieldInfo.getName())) {
return fieldInfo;
}
}
}
throw VMError.shouldNotReachHere();
}
use of com.oracle.svm.hosted.c.info.StructFieldInfo in project graal by oracle.
the class CInterfaceInvocationPlugin method makeLocationIdentity.
private static LocationIdentity makeLocationIdentity(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, AccessorInfo accessorInfo) {
LocationIdentity locationIdentity;
if (accessorInfo.hasLocationIdentityParameter()) {
ValueNode locationIdentityNode = args[accessorInfo.locationIdentityParameterNumber(true)];
if (!locationIdentityNode.isConstant()) {
throw UserError.abort(new CInterfaceError("locationIdentity is not a compile time constant for call to " + method.format("%H.%n(%p)") + " in " + b.getMethod().asStackTraceElement(b.bci()), method).getMessage());
}
locationIdentity = (LocationIdentity) SubstrateObjectConstant.asObject(locationIdentityNode.asConstant());
} else if (accessorInfo.hasUniqueLocationIdentity()) {
StructFieldInfo fieldInfo = (StructFieldInfo) accessorInfo.getParent();
assert fieldInfo.getLocationIdentity() != null;
locationIdentity = fieldInfo.getLocationIdentity();
} else {
locationIdentity = CInterfaceLocationIdentity.DEFAULT_LOCATION_IDENTITY;
}
return locationIdentity;
}
Aggregations