Search in sources :

Example 21 with MetaAccessProvider

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

the class ReplacementsImpl method getSubstitution.

@Override
public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
    StructuredGraph result;
    InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
    if (plugin != null && (!plugin.inlineOnly() || invokeBci >= 0)) {
        MetaAccessProvider metaAccess = providers.getMetaAccess();
        if (plugin instanceof MethodSubstitutionPlugin) {
            MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
            ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess);
            StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(substitute) : null;
            if (graph == null || graph.trackNodeSourcePosition() != trackNodeSourcePosition) {
                try (DebugContext debug = openDebugContext("Substitution_", method)) {
                    graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method, trackNodeSourcePosition, replaceePosition);
                    if (!UseSnippetGraphCache.getValue(options)) {
                        return graph;
                    }
                    graph.freeze();
                    graphs.putIfAbsent(substitute, graph);
                    graph = graphs.get(substitute);
                }
            }
            assert graph.isFrozen();
            result = graph;
        } else {
            Bytecode code = new ResolvedJavaMethodBytecode(method);
            ConstantReflectionProvider constantReflection = providers.getConstantReflection();
            ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider();
            StampProvider stampProvider = providers.getStampProvider();
            try (DebugContext debug = openDebugContext("Substitution_", method)) {
                result = new IntrinsicGraphBuilder(options, debug, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin);
            }
        }
    } else {
        result = null;
    }
    return result;
}
Also used : StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) GeneratedInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) DebugContext(org.graalvm.compiler.debug.DebugContext) MethodSubstitutionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider)

Example 22 with MetaAccessProvider

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

the class TruffleCompilerImpl method getSkippedExceptionTypes.

private ResolvedJavaType[] getSkippedExceptionTypes(TruffleCompilerRuntime runtime) {
    final MetaAccessProvider metaAccess = providers.getMetaAccess();
    ResolvedJavaType[] head = metaAccess.lookupJavaTypes(new Class<?>[] { ArithmeticException.class, IllegalArgumentException.class, VirtualMachineError.class, IndexOutOfBoundsException.class, ClassCastException.class, BufferUnderflowException.class, BufferOverflowException.class });
    ResolvedJavaType[] tail = { runtime.resolveType(metaAccess, "com.oracle.truffle.api.nodes.UnexpectedResultException"), runtime.resolveType(metaAccess, "com.oracle.truffle.api.nodes.SlowPathException") };
    ResolvedJavaType[] skippedExceptionTypes = new ResolvedJavaType[head.length + tail.length];
    System.arraycopy(head, 0, skippedExceptionTypes, 0, head.length);
    System.arraycopy(tail, 0, skippedExceptionTypes, head.length, tail.length);
    return skippedExceptionTypes;
}
Also used : MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 23 with MetaAccessProvider

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

the class HotSpotTruffleRuntime method getTruffleCallBoundaryMethods.

@Override
public synchronized Iterable<ResolvedJavaMethod> getTruffleCallBoundaryMethods() {
    if (truffleCallBoundaryMethods == null) {
        truffleCallBoundaryMethods = new ArrayList<>();
        MetaAccessProvider metaAccess = getMetaAccess();
        ResolvedJavaType type = metaAccess.lookupJavaType(OptimizedCallTarget.class);
        for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
            if (method.getAnnotation(TruffleCallBoundary.class) != null) {
                truffleCallBoundaryMethods.add(method);
            }
        }
    }
    return truffleCallBoundaryMethods;
}
Also used : TruffleCallBoundary(org.graalvm.compiler.truffle.runtime.TruffleCallBoundary) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 24 with MetaAccessProvider

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

the class CFunctionCallStubMethod method adaptSignatureAndConvertArguments.

private static Signature adaptSignatureAndConvertArguments(ResolvedJavaMethod method, HostedProviders providers, NativeLibraries nativeLibraries, HostedGraphKit kit, Signature signature, List<ValueNode> arguments) {
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    JavaType returnType = signature.getReturnType(null);
    JavaType[] parameterTypes = signature.toParameterTypes(null);
    for (int i = 0; i < parameterTypes.length; i++) {
        if (!isPrimitiveOrWord(providers, parameterTypes[i])) {
            ElementInfo typeInfo = nativeLibraries.findElementInfo(parameterTypes[i]);
            if (typeInfo instanceof EnumInfo) {
                UserError.guarantee(typeInfo.getChildren().stream().anyMatch(EnumValueInfo.class::isInstance), "Enum class " + returnType.toJavaName() + " needs a method that is annotated with @" + CEnumValue.class.getSimpleName() + " because it is used as a parameter of a method annotated with @" + CFunction.class.getSimpleName() + ": " + method.format("%H.%n(%p)"));
                ValueNode argumentValue = arguments.get(i);
                IsNullNode isNull = kit.unique(new IsNullNode(argumentValue));
                kit.startIf(isNull, BranchProbabilityNode.VERY_SLOW_PATH_PROBABILITY);
                kit.thenPart();
                ResolvedJavaType enumExceptionType = metaAccess.lookupJavaType(RuntimeException.class);
                NewInstanceNode enumException = kit.append(new NewInstanceNode(enumExceptionType, true));
                Iterator<ResolvedJavaMethod> enumExceptionCtor = Arrays.stream(enumExceptionType.getDeclaredConstructors()).filter(c -> c.getSignature().getParameterCount(false) == 1 && c.getSignature().getParameterType(0, null).equals(metaAccess.lookupJavaType(String.class))).iterator();
                ConstantNode enumExceptionMessage = kit.createConstant(kit.getConstantReflection().forString("null return value cannot be converted to a C enum value"), JavaKind.Object);
                kit.createJavaCallWithExceptionAndUnwind(InvokeKind.Special, enumExceptionCtor.next(), enumException, enumExceptionMessage);
                assert !enumExceptionCtor.hasNext();
                kit.append(new UnwindNode(enumException));
                kit.endIf();
                CInterfaceEnumTool tool = new CInterfaceEnumTool(metaAccess, providers.getSnippetReflection());
                argumentValue = tool.createEnumValueInvoke(kit, (EnumInfo) typeInfo, cEnumKind, argumentValue);
                arguments.set(i, argumentValue);
                parameterTypes[i] = metaAccess.lookupJavaType(cEnumKind.toJavaClass());
            } else {
                throw UserError.abort("@" + CFunction.class.getSimpleName() + " parameter types are restricted to primitive types, word types and enumerations (@" + CEnum.class.getSimpleName() + "): " + method.format("%H.%n(%p)"));
            }
        }
    }
    if (!isPrimitiveOrWord(providers, returnType)) {
        // Assume enum: actual checks and conversion are in adaptReturnValue()
        returnType = providers.getWordTypes().getWordImplType();
    }
    JavaType actualReturnType = returnType;
    return new Signature() {

        @Override
        public int getParameterCount(boolean receiver) {
            return parameterTypes.length;
        }

        @Override
        public JavaType getParameterType(int index, ResolvedJavaType accessingClass) {
            return parameterTypes[index];
        }

        @Override
        public JavaType getReturnType(ResolvedJavaType accessingClass) {
            return actualReturnType;
        }
    };
}
Also used : HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Signature(jdk.vm.ci.meta.Signature) Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) CInterfaceEnumTool(com.oracle.svm.hosted.phases.CInterfaceEnumTool) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) EnumValueInfo(com.oracle.svm.hosted.c.info.EnumValueInfo) JavaKind(jdk.vm.ci.meta.JavaKind) Transition(org.graalvm.nativeimage.c.function.CFunction.Transition) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) UserError(com.oracle.svm.core.util.UserError) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ImageSingletons(org.graalvm.nativeimage.ImageSingletons) Iterator(java.util.Iterator) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) CustomSubstitutionMethod(com.oracle.svm.hosted.annotation.CustomSubstitutionMethod) CFunction(org.graalvm.nativeimage.c.function.CFunction) SharedMethod(com.oracle.svm.core.meta.SharedMethod) CGlobalDataInfo(com.oracle.svm.core.graal.code.CGlobalDataInfo) CEnumLookup(org.graalvm.nativeimage.c.constant.CEnumLookup) CEnumValue(org.graalvm.nativeimage.c.constant.CEnumValue) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) List(java.util.List) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CEnum(org.graalvm.nativeimage.c.constant.CEnum) HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) Signature(jdk.vm.ci.meta.Signature) ValueNode(org.graalvm.compiler.nodes.ValueNode) CInterfaceEnumTool(com.oracle.svm.hosted.phases.CInterfaceEnumTool) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 25 with MetaAccessProvider

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

the class ObjectEqualsNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode xAlias = tool.getAlias(getX());
    ValueNode yAlias = tool.getAlias(getY());
    VirtualObjectNode xVirtual = xAlias instanceof VirtualObjectNode ? (VirtualObjectNode) xAlias : null;
    VirtualObjectNode yVirtual = yAlias instanceof VirtualObjectNode ? (VirtualObjectNode) yAlias : null;
    if (xVirtual != null && yVirtual == null) {
        virtualizeNonVirtualComparison(xVirtual, yAlias, tool);
    } else if (xVirtual == null && yVirtual != null) {
        virtualizeNonVirtualComparison(yVirtual, xAlias, tool);
    } else if (xVirtual != null && yVirtual != null) {
        if (xVirtual.hasIdentity() ^ yVirtual.hasIdentity()) {
            /*
                 * One of the two objects has identity, the other doesn't. In code, this looks like
                 * "Integer.valueOf(a) == new Integer(b)", which is always false.
                 *
                 * In other words: an object created via valueOf can never be equal to one created
                 * by new in the same compilation unit.
                 */
            tool.replaceWithValue(LogicConstantNode.contradiction(graph()));
        } else if (!xVirtual.hasIdentity() && !yVirtual.hasIdentity()) {
            ResolvedJavaType type = xVirtual.type();
            if (type.equals(yVirtual.type())) {
                MetaAccessProvider metaAccess = tool.getMetaAccessProvider();
                if (type.equals(metaAccess.lookupJavaType(Integer.class)) || type.equals(metaAccess.lookupJavaType(Long.class))) {
                    // both are virtual without identity: check contents
                    assert xVirtual.entryCount() == 1 && yVirtual.entryCount() == 1;
                    assert xVirtual.entryKind(0).getStackKind() == JavaKind.Int || xVirtual.entryKind(0) == JavaKind.Long;
                    IntegerEqualsNode equals = new IntegerEqualsNode(tool.getEntry(xVirtual, 0), tool.getEntry(yVirtual, 0));
                    tool.addNode(equals);
                    tool.replaceWithValue(equals);
                }
            }
        } else {
            // both are virtual with identity: check if they refer to the same object
            tool.replaceWithValue(LogicConstantNode.forBoolean(xVirtual == yVirtual, graph()));
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Aggregations

MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)34 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)18 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)11 DebugContext (org.graalvm.compiler.debug.DebugContext)9 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)9 OptionValues (org.graalvm.compiler.options.OptionValues)9 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)8 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)8 Method (java.lang.reflect.Method)7 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)7 Providers (org.graalvm.compiler.phases.util.Providers)7 RuntimeProvider (org.graalvm.compiler.runtime.RuntimeProvider)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)6 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)6 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)5 PhaseSuite (org.graalvm.compiler.phases.PhaseSuite)5 ArrayList (java.util.ArrayList)4 JavaKind (jdk.vm.ci.meta.JavaKind)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)4