Search in sources :

Example 66 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class InfoTreeBuilder method elementKind.

private ElementKind elementKind(Collection<AccessorInfo> accessorInfos) {
    ElementKind overallKind = ElementKind.UNKNOWN;
    AccessorInfo overallKindAccessor = null;
    for (AccessorInfo accessorInfo : accessorInfos) {
        ResolvedJavaMethod method = (ResolvedJavaMethod) accessorInfo.getAnnotatedElement();
        ElementKind newKind;
        switch(accessorInfo.getAccessorKind()) {
            case GETTER:
                newKind = elementKind((ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass()));
                break;
            case SETTER:
                newKind = elementKind((ResolvedJavaType) method.getSignature().getParameterType(accessorInfo.valueParameterNumber(false), method.getDeclaringClass()));
                break;
            default:
                continue;
        }
        if (overallKind == ElementKind.UNKNOWN) {
            overallKind = newKind;
            overallKindAccessor = accessorInfo;
        } else if (overallKind != newKind) {
            nativeLibs.addError("Accessor methods mix integer, floating point, and pointer kinds", overallKindAccessor.getAnnotatedElement(), method);
        }
    }
    return overallKind;
}
Also used : ElementKind(com.oracle.svm.hosted.c.info.SizableInfo.ElementKind) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 67 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class InfoTreeBuilder method createRawStructInfo.

private void createRawStructInfo(ResolvedJavaType type) {
    if (!validInterfaceDefinition(type, RawStructure.class)) {
        return;
    }
    Map<String, List<AccessorInfo>> fieldAccessorInfos = new TreeMap<>();
    List<AccessorInfo> structAccessorInfos = new ArrayList<>();
    for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
        String fieldName;
        AccessorInfo accessorInfo;
        RawField fieldAnnotation = getMethodAnnotation(method, RawField.class);
        if (fieldAnnotation != null) {
            if (method.getSignature().getReturnKind() == JavaKind.Void) {
                accessorInfo = new AccessorInfo(method, AccessorKind.SETTER, false, hasLocationIdentityParameter(method), hasUniqueLocationIdentity(method));
            } else {
                accessorInfo = new AccessorInfo(method, AccessorKind.GETTER, false, hasLocationIdentityParameter(method), hasUniqueLocationIdentity(method));
            }
            fieldName = getStructFieldName(method, "", accessorInfo.getAccessorKind());
        } else if (method.getSignature().getReturnType(method.getDeclaringClass()).equals(method.getDeclaringClass())) {
            fieldName = null;
            accessorInfo = new AccessorInfo(method, AccessorKind.ADDRESS, method.getSignature().getParameterCount(false) > 0, false, false);
        } else {
            nativeLibs.addError("Unexpected method without annotation", method);
            continue;
        }
        if (accessorValid(accessorInfo)) {
            if (fieldName == null) {
                structAccessorInfos.add(accessorInfo);
            } else {
                Map<String, List<AccessorInfo>> map = fieldAccessorInfos;
                List<AccessorInfo> accessorInfos = map.get(fieldName);
                if (accessorInfos == null) {
                    accessorInfos = new ArrayList<>();
                    map.put(fieldName, accessorInfos);
                }
                accessorInfos.add(accessorInfo);
            }
            nativeLibs.registerElementInfo(method, accessorInfo);
        }
    }
    String typeName = getStructName(type);
    StructInfo structInfo = StructInfo.create(typeName, type);
    structInfo.adoptChildren(structAccessorInfos);
    for (Map.Entry<String, List<AccessorInfo>> entry : fieldAccessorInfos.entrySet()) {
        StructFieldInfo fieldInfo = new StructFieldInfo(entry.getKey(), elementKind(entry.getValue()));
        fieldInfo.adoptChildren(entry.getValue());
        structInfo.adoptChild(fieldInfo);
    }
    nativeCodeInfo.adoptChild(structInfo);
    nativeLibs.registerElementInfo(type, structInfo);
}
Also used : ArrayList(java.util.ArrayList) RawStructure(org.graalvm.nativeimage.c.struct.RawStructure) RawField(org.graalvm.nativeimage.c.struct.RawField) TreeMap(java.util.TreeMap) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 68 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class RestrictHeapAccessCalleesFeature method findAssertionConstructor.

/**
 * Look up an AssertionError constructor.
 */
private static ResolvedJavaMethod findAssertionConstructor(DuringAnalysisAccess access, Class<?>... parameterTypes) {
    try {
        final Constructor<AssertionError> reflectiveConstructor = AssertionError.class.getConstructor(parameterTypes);
        final ResolvedJavaMethod resolvedConstructor = ((DuringAnalysisAccessImpl) access).getMetaAccess().lookupJavaMethod(reflectiveConstructor);
        return resolvedConstructor;
    } catch (NoSuchMethodException | SecurityException ex) {
        throw VMError.shouldNotReachHere("Should have found AssertionError constructor." + ex);
    }
}
Also used : ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 69 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class QueryResultParser method visitConstantInfo.

@Override
protected void visitConstantInfo(ConstantInfo constantInfo) {
    TargetDescription target = nativeLibs.getTarget();
    switch(constantInfo.getKind()) {
        case INTEGER:
            parseIntegerProperty(constantInfo.getSizeInfo());
            parseSignedness(constantInfo.getSignednessInfo());
            parseIntegerConstantValue(constantInfo.getValueInfo());
            /*
                 * From the point of view of the C compiler, plain #define constants have the type
                 * int and therefore size 4. But sometimes we want to access such values as short or
                 * byte to avoid casts. Check the actual value of the constant, and if it fits the
                 * declared type of the constant, then change the actual size to the declared size.
                 */
            ResolvedJavaMethod method = (ResolvedJavaMethod) constantInfo.getAnnotatedElement();
            ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
            JavaKind returnKind = returnType.getJavaKind();
            if (returnKind == JavaKind.Object) {
                returnKind = target.wordJavaKind;
            }
            int declaredSize = target.arch.getPlatformKind(returnKind).getSizeInBytes();
            int actualSize = constantInfo.getSizeInfo().getProperty();
            if (declaredSize != actualSize) {
                long value = (long) constantInfo.getValueInfo().getProperty();
                if (value >= returnKind.getMinValue() && value <= returnKind.getMaxValue()) {
                    constantInfo.getSizeInfo().setProperty(declaredSize);
                }
            }
            break;
        case POINTER:
            parseIntegerProperty(constantInfo.getSizeInfo());
            parseIntegerConstantValue(constantInfo.getValueInfo());
            break;
        case FLOAT:
            parseIntegerProperty(constantInfo.getSizeInfo());
            parseFloatValue(constantInfo.getValueInfo());
            break;
        case STRING:
            parseStringValue(constantInfo.getValueInfo());
            break;
        case BYTEARRAY:
            parseByteArrayValue(constantInfo.getValueInfo());
            break;
        default:
            throw shouldNotReachHere();
    }
}
Also used : TargetDescription(jdk.vm.ci.code.TargetDescription) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 70 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class BytecodeParser method createStateAfterStartOfReplacementGraph.

/**
 * Creates the frame state after the start node of a graph for an {@link IntrinsicContext
 * intrinsic} that is the parse root (either for root compiling or for post-parse inlining).
 */
private FrameState createStateAfterStartOfReplacementGraph() {
    assert parent == null;
    assert frameState.getMethod().equals(intrinsicContext.getIntrinsicMethod());
    assert bci() == 0;
    assert frameState.stackSize() == 0;
    FrameState stateAfterStart;
    if (intrinsicContext.isPostParseInlined()) {
        stateAfterStart = graph.add(new FrameState(BytecodeFrame.BEFORE_BCI));
    } else {
        ResolvedJavaMethod original = intrinsicContext.getOriginalMethod();
        ValueNode[] locals;
        if (original.getMaxLocals() == frameState.localsSize() || original.isNative()) {
            locals = new ValueNode[original.getMaxLocals()];
            for (int i = 0; i < locals.length; i++) {
                ValueNode node = frameState.locals[i];
                if (node == FrameState.TWO_SLOT_MARKER) {
                    node = null;
                }
                locals[i] = node;
            }
        } else {
            locals = new ValueNode[original.getMaxLocals()];
            int parameterCount = original.getSignature().getParameterCount(!original.isStatic());
            for (int i = 0; i < parameterCount; i++) {
                ValueNode param = frameState.locals[i];
                if (param == FrameState.TWO_SLOT_MARKER) {
                    param = null;
                }
                locals[i] = param;
                assert param == null || param instanceof ParameterNode || param.isConstant();
            }
        }
        ValueNode[] stack = {};
        int stackSize = 0;
        ValueNode[] locks = {};
        List<MonitorIdNode> monitorIds = Collections.emptyList();
        stateAfterStart = graph.add(new FrameState(null, new ResolvedJavaMethodBytecode(original), 0, locals, stack, stackSize, locks, monitorIds, false, false));
    }
    return stateAfterStart;
}
Also used : MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameState(org.graalvm.compiler.nodes.FrameState) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)331 ValueNode (org.graalvm.compiler.nodes.ValueNode)104 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)89 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)67 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)66 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 Test (org.junit.Test)54 DebugContext (org.graalvm.compiler.debug.DebugContext)35 OptionValues (org.graalvm.compiler.options.OptionValues)32 InstalledCode (jdk.vm.ci.code.InstalledCode)24 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)23 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)22 JavaKind (jdk.vm.ci.meta.JavaKind)21 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)20 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)19 JavaConstant (jdk.vm.ci.meta.JavaConstant)17 LogicNode (org.graalvm.compiler.nodes.LogicNode)17 ArrayList (java.util.ArrayList)16