Search in sources :

Example 1 with AnalysisArraysCopyOfNode

use of com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode in project graal by oracle.

the class SubstrateGraphBuilderPlugins method registerArraysPlugins.

private static void registerArraysPlugins(InvocationPlugins plugins, boolean analysis) {
    Registration r = new Registration(plugins, Arrays.class).setAllowOverwrite(true);
    r.register2("copyOf", Object[].class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength) {
            if (analysis) {
                b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength));
            } else {
                /* Get the class from the original node. */
                GetClassNode originalArrayType = b.add(new GetClassNode(original.stamp(NodeView.DEFAULT), b.nullCheckedValue(original)));
                ValueNode originalLength = b.add(ArrayLengthNode.create(original, b.getConstantReflection()));
                Stamp stamp = b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp().join(original.stamp(NodeView.DEFAULT));
                b.addPush(JavaKind.Object, new SubstrateArraysCopyOfNode(stamp, original, originalLength, newLength, originalArrayType));
            }
            return true;
        }
    });
    r.register3("copyOf", Object[].class, int.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength, ValueNode newArrayType) {
            if (analysis) {
                /*
                     * If the new array type comes from a GetClassNode or is a constant we can infer
                     * the concrete type of the new array, otherwise we conservatively assume that
                     * the new array can have any of the instantiated array types.
                     */
                b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength, newArrayType));
            } else {
                Stamp stamp;
                if (newArrayType.isConstant()) {
                    ResolvedJavaType newType = b.getConstantReflection().asJavaType(newArrayType.asConstant());
                    stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(newType));
                } else {
                    stamp = b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp();
                }
                ValueNode originalLength = b.add(ArrayLengthNode.create(original, b.getConstantReflection()));
                b.addPush(JavaKind.Object, new SubstrateArraysCopyOfNode(stamp, original, originalLength, newLength, newArrayType));
            }
            return true;
        }
    });
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) SubstrateArraysCopyOfNode(com.oracle.svm.core.graal.jdk.SubstrateArraysCopyOfNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) AnalysisArraysCopyOfNode(com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Arrays(java.util.Arrays) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with AnalysisArraysCopyOfNode

use of com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode in project graal by oracle.

the class PointstoGraphBuilderPlugins method registerArraysPlugins.

public static void registerArraysPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Arrays.class).setAllowOverwrite(true);
    r.register2("copyOf", Object[].class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength) {
            b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength));
            return true;
        }
    });
    r.register3("copyOf", Object[].class, int.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength, ValueNode newObjectElementType) {
            if (newObjectElementType instanceof GetClassNode || newObjectElementType.isConstant()) {
                // We can infer the concrete type of the new array
                b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength, newObjectElementType));
                return true;
            }
            return false;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AnalysisArraysCopyOfNode(com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) Arrays(java.util.Arrays) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

AnalysisArraysCopyOfNode (com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode)2 Arrays (java.util.Arrays)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)2 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)2 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)2 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)2 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)2 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)1 SubstrateArraysCopyOfNode (com.oracle.svm.core.graal.jdk.SubstrateArraysCopyOfNode)1 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)1 Stamp (org.graalvm.compiler.core.common.type.Stamp)1