Search in sources :

Example 1 with ElementInfo

use of com.oracle.svm.hosted.c.info.ElementInfo in project graal by oracle.

the class SizeAndSignednessVerifier method visitEnumValueInfo.

@Override
protected void visitEnumValueInfo(EnumValueInfo valueInfo) {
    ResolvedJavaMethod method = (ResolvedJavaMethod) valueInfo.getAnnotatedElement();
    ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
    EnumInfo enumInfo = (EnumInfo) valueInfo.getParent();
    for (ElementInfo info : enumInfo.getChildren()) {
        if (info instanceof EnumConstantInfo) {
            EnumConstantInfo constantInfo = (EnumConstantInfo) info;
            checkSizeAndSignedness(constantInfo, returnType, method, true);
        }
    }
}
Also used : EnumConstantInfo(com.oracle.svm.hosted.c.info.EnumConstantInfo) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 2 with ElementInfo

use of com.oracle.svm.hosted.c.info.ElementInfo in project graal by oracle.

the class CEntryPointCallStubMethod method adaptParameterTypes.

private EnumInfo[] adaptParameterTypes(HostedProviders providers, NativeLibraries nativeLibraries, HostedGraphKit kit, JavaType[] parameterTypes, JavaType[] parameterLoadTypes, Purpose purpose) {
    EnumInfo[] parameterEnumInfos = null;
    for (int i = 0; i < parameterTypes.length; i++) {
        if (!parameterTypes[i].getJavaKind().isPrimitive() && !providers.getWordTypes().isWord(parameterTypes[i])) {
            ElementInfo typeInfo = nativeLibraries.findElementInfo(parameterTypes[i]);
            if (typeInfo instanceof EnumInfo) {
                UserError.guarantee(typeInfo.getChildren().stream().anyMatch(EnumLookupInfo.class::isInstance), "Enum class " + parameterTypes[i].toJavaName() + " needs a method that is annotated with @" + CEnumLookup.class + " because it is used as a parameter of an entry point method: " + targetMethod.format("%H.%n(%p)"));
                if (parameterEnumInfos == null) {
                    parameterEnumInfos = new EnumInfo[parameterTypes.length];
                }
                parameterEnumInfos[i] = (EnumInfo) typeInfo;
                parameterLoadTypes[i] = providers.getMetaAccess().lookupJavaType(cEnumParameterKind.toJavaClass());
                final int parameterIndex = i;
                FrameState initialState = kit.getGraph().start().stateAfter();
                Iterator<ValueNode> matchingNodes = initialState.values().filter(node -> ((ParameterNode) node).index() == parameterIndex).iterator();
                ValueNode parameterNode = matchingNodes.next();
                assert !matchingNodes.hasNext() && parameterNode.usages().filter(n -> n != initialState).isEmpty();
                parameterNode.setStamp(StampFactory.forKind(cEnumParameterKind));
            } else if (purpose != Purpose.ANALYSIS) {
                // for analysis test cases: abort only during compilation
                throw UserError.abort("Entry point method parameter types are restricted to primitive types, word types and enumerations (@" + CEnum.class.getSimpleName() + "): " + targetMethod.format("%H.%n(%p)"));
            }
        }
    }
    return parameterEnumInfos;
}
Also used : Isolate(org.graalvm.nativeimage.Isolate) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GraphProvider(com.oracle.graal.pointsto.infrastructure.GraphProvider) NativeBootImage(com.oracle.svm.hosted.image.NativeBootImage) Constant(jdk.vm.ci.meta.Constant) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) CInterfaceEnumTool(com.oracle.svm.hosted.phases.CInterfaceEnumTool) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) JavaKind(jdk.vm.ci.meta.JavaKind) IsolateThread(org.graalvm.nativeimage.IsolateThread) UserError(com.oracle.svm.core.util.UserError) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointPrologueBailoutNode(com.oracle.svm.core.graal.nodes.CEntryPointPrologueBailoutNode) CEntryPointSetup(com.oracle.svm.core.c.function.CEntryPointSetup) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) ConstantPool(jdk.vm.ci.meta.ConstantPool) CEnumValue(org.graalvm.nativeimage.c.constant.CEnumValue) UniverseMetaAccess(com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) VMError(com.oracle.svm.core.util.VMError) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) FrameState(org.graalvm.compiler.nodes.FrameState) Type(java.lang.reflect.Type) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) NoPrologue(com.oracle.svm.core.c.function.CEntryPointOptions.NoPrologue) NoEpilogue(com.oracle.svm.core.c.function.CEntryPointOptions.NoEpilogue) SpeculationLog(jdk.vm.ci.meta.SpeculationLog) CEnum(org.graalvm.nativeimage.c.constant.CEnum) HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Signature(jdk.vm.ci.meta.Signature) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) EnumValueInfo(com.oracle.svm.hosted.c.info.EnumValueInfo) DebugContext(org.graalvm.compiler.debug.DebugContext) CEntryPointCallStubs(com.oracle.svm.core.code.CEntryPointCallStubs) EnumLookupInfo(com.oracle.svm.hosted.c.info.EnumLookupInfo) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) Iterator(java.util.Iterator) CEnumLookup(org.graalvm.nativeimage.c.constant.CEnumLookup) ExceptionHandler(jdk.vm.ci.meta.ExceptionHandler) ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) SubstrateGraphKit(com.oracle.svm.core.graal.replacements.SubstrateGraphKit) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) LineNumberTable(jdk.vm.ci.meta.LineNumberTable) LocalVariableTable(jdk.vm.ci.meta.LocalVariableTable) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DeadEndNode(com.oracle.svm.core.graal.nodes.DeadEndNode) LeaveAction(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode.LeaveAction) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CEnumLookup(org.graalvm.nativeimage.c.constant.CEnumLookup) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) CEnum(org.graalvm.nativeimage.c.constant.CEnum) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameState(org.graalvm.compiler.nodes.FrameState) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 3 with ElementInfo

use of com.oracle.svm.hosted.c.info.ElementInfo in project graal by oracle.

the class NativeLibraries method findElementInfo.

public ElementInfo findElementInfo(Object e) {
    Object element = unwrap(e);
    ElementInfo result = elementToInfo.get(element);
    if (result == null && element instanceof ResolvedJavaType && ((ResolvedJavaType) element).getInterfaces().length == 1) {
        result = findElementInfo(((ResolvedJavaType) element).getInterfaces()[0]);
    }
    return result;
}
Also used : ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 4 with ElementInfo

use of com.oracle.svm.hosted.c.info.ElementInfo 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();
}
Also used : ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) ArrayList(java.util.ArrayList) StructBitfieldInfo(com.oracle.svm.hosted.c.info.StructBitfieldInfo)

Example 5 with ElementInfo

use of com.oracle.svm.hosted.c.info.ElementInfo 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();
}
Also used : StructInfo(com.oracle.svm.hosted.c.info.StructInfo) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo)

Aggregations

ElementInfo (com.oracle.svm.hosted.c.info.ElementInfo)10 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)7 EnumInfo (com.oracle.svm.hosted.c.info.EnumInfo)5 CInterfaceEnumTool (com.oracle.svm.hosted.phases.CInterfaceEnumTool)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)3 UserError (com.oracle.svm.core.util.UserError)3 NativeLibraries (com.oracle.svm.hosted.c.NativeLibraries)3 EnumValueInfo (com.oracle.svm.hosted.c.info.EnumValueInfo)3 HostedGraphKit (com.oracle.svm.hosted.phases.HostedGraphKit)3 Arrays (java.util.Arrays)3 Iterator (java.util.Iterator)3 JavaType (jdk.vm.ci.meta.JavaType)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 CEnumLookup (org.graalvm.nativeimage.c.constant.CEnumLookup)3 GraphProvider (com.oracle.graal.pointsto.infrastructure.GraphProvider)2 UniverseMetaAccess (com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess)2 WrappedJavaMethod (com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod)2 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)2 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)2