Search in sources :

Example 1 with IntrinsicMethod

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

the class MethodHandlePlugin method handleInvoke.

@Override
public boolean handleInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
    IntrinsicMethod intrinsicMethod = methodHandleAccess.lookupMethodHandleIntrinsic(method);
    if (intrinsicMethod != null) {
        InvokeKind invokeKind = b.getInvokeKind();
        if (invokeKind != InvokeKind.Static) {
            args[0] = b.nullCheckedValue(args[0]);
        }
        StampPair invokeReturnStamp = b.getInvokeReturnStamp(b.getAssumptions());
        MethodHandleNode.GraphAdder adder = new MethodHandleNode.GraphAdder(b.getGraph()) {

            @Override
            public <T extends ValueNode> T add(T node) {
                return b.add(node);
            }
        };
        InvokeNode invoke = MethodHandleNode.tryResolveTargetInvoke(adder, methodHandleAccess, intrinsicMethod, method, b.bci(), invokeReturnStamp, args);
        if (invoke == null) {
            MethodHandleNode methodHandleNode = new MethodHandleNode(intrinsicMethod, invokeKind, method, b.bci(), invokeReturnStamp, args);
            if (invokeReturnStamp.getTrustedStamp().getStackKind() == JavaKind.Void) {
                b.add(methodHandleNode);
            } else {
                b.addPush(invokeReturnStamp.getTrustedStamp().getStackKind(), methodHandleNode);
            }
        } else {
            CallTargetNode callTarget = invoke.callTarget();
            NodeInputList<ValueNode> argumentsList = callTarget.arguments();
            for (int i = 0; i < argumentsList.size(); ++i) {
                argumentsList.initialize(i, b.append(argumentsList.get(i)));
            }
            boolean inlineEverything = false;
            if (safeForDeoptimization) {
                // If a MemberName suffix argument is dropped, the replaced call cannot
                // deoptimized since the necessary frame state cannot be reconstructed.
                // As such, it needs to recursively inline everything.
                inlineEverything = args.length != argumentsList.size();
            }
            if (inlineEverything && !callTarget.targetMethod().hasBytecodes()) {
                // we need to force-inline but we can not, leave the invoke as-is
                return false;
            }
            b.handleReplacedInvoke(invoke.getInvokeKind(), callTarget.targetMethod(), argumentsList.toArray(new ValueNode[argumentsList.size()]), inlineEverything);
        }
        return true;
    }
    return false;
}
Also used : MethodHandleNode(org.graalvm.compiler.replacements.nodes.MethodHandleNode) IntrinsicMethod(jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) StampPair(org.graalvm.compiler.core.common.type.StampPair) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode)

Example 2 with IntrinsicMethod

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

the class CheckGraalIntrinsics method test.

@Test
@SuppressWarnings("try")
public void test() throws ClassNotFoundException {
    HotSpotGraalRuntimeProvider rt = (HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class);
    HotSpotProviders providers = rt.getHostBackend().getProviders();
    Plugins graphBuilderPlugins = providers.getGraphBuilderPlugins();
    InvocationPlugins invocationPlugins = graphBuilderPlugins.getInvocationPlugins();
    HotSpotVMConfigStore store = rt.getVMConfig().getStore();
    List<VMIntrinsicMethod> intrinsics = store.getIntrinsics();
    List<String> missing = new ArrayList<>();
    EconomicMap<String, List<Binding>> bindings = invocationPlugins.getBindings(true);
    for (VMIntrinsicMethod intrinsic : intrinsics) {
        InvocationPlugin plugin = findPlugin(bindings, intrinsic);
        if (plugin == null) {
            ResolvedJavaMethod method = resolveIntrinsic(providers.getMetaAccess(), intrinsic);
            if (method != null) {
                IntrinsicMethod intrinsicMethod = providers.getConstantReflection().getMethodHandleAccess().lookupMethodHandleIntrinsic(method);
                if (intrinsicMethod != null) {
                    continue;
                }
            }
            String m = String.format("%s.%s%s", intrinsic.declaringClass, intrinsic.name, intrinsic.descriptor);
            if (!TO_BE_INVESTIGATED.contains(m) && !IGNORE.contains(m)) {
                missing.add(m);
            }
        }
    }
    if (!missing.isEmpty()) {
        Collections.sort(missing);
        String missingString = missing.stream().collect(Collectors.joining(String.format("%n    ")));
        fail("missing Graal intrinsics for:%n    %s", missingString);
    }
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) VMIntrinsicMethod(jdk.vm.ci.hotspot.VMIntrinsicMethod) IntrinsicMethod(jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) HotSpotGraalRuntimeProvider(org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider) HotSpotProviders(org.graalvm.compiler.hotspot.meta.HotSpotProviders) ArrayList(java.util.ArrayList) HotSpotGraalRuntimeProvider(org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ArrayList(java.util.ArrayList) List(java.util.List) HotSpotVMConfigStore(jdk.vm.ci.hotspot.HotSpotVMConfigStore) VMIntrinsicMethod(jdk.vm.ci.hotspot.VMIntrinsicMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins) GraalTest(org.graalvm.compiler.test.GraalTest) Test(org.junit.Test)

Aggregations

IntrinsicMethod (jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HotSpotVMConfigStore (jdk.vm.ci.hotspot.HotSpotVMConfigStore)1 VMIntrinsicMethod (jdk.vm.ci.hotspot.VMIntrinsicMethod)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 StampPair (org.graalvm.compiler.core.common.type.StampPair)1 HotSpotGraalRuntimeProvider (org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider)1 HotSpotProviders (org.graalvm.compiler.hotspot.meta.HotSpotProviders)1 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)1 InvokeKind (org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)1 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)1 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)1 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)1 MethodHandleNode (org.graalvm.compiler.replacements.nodes.MethodHandleNode)1 RuntimeProvider (org.graalvm.compiler.runtime.RuntimeProvider)1 GraalTest (org.graalvm.compiler.test.GraalTest)1 Test (org.junit.Test)1