Search in sources :

Example 1 with TypeFlowBuilder

use of com.oracle.graal.pointsto.flow.builder.TypeFlowBuilder in project graal by oracle.

the class PointsToStats method reportPrunedTypeFlows.

private static void reportPrunedTypeFlows(BufferedWriter out) {
    doWrite(out, String.format("%-35s\n", "Summary"));
    doWrite(out, String.format("%-35s\t%-10s\n", "Type Flow Class", "Removed Count"));
    typeFlowBuilders.stream().filter(Objects::nonNull).filter(b -> !b.isMaterialized()).collect(Collectors.groupingBy(TypeFlowBuilder::getFlowClass)).forEach((flowClass, providers) -> {
        doWrite(out, String.format("%-35s\t%-10d\n", flowClass.getSimpleName(), providers.size()));
    });
    doWrite(out, String.format("\n%-35s\n", "Removed flows"));
    doWrite(out, String.format("%-35s\t%-10s\n", "Type Flow Class", "Location"));
    typeFlowBuilders.stream().filter(Objects::nonNull).filter(b -> !b.isMaterialized()).forEach((provider) -> {
        Object source = provider.getSource();
        String sourceStr;
        if (source instanceof ValueNode) {
            ValueNode value = (ValueNode) source;
            NodeSourcePosition srcPosition = value.getNodeSourcePosition();
            if (srcPosition != null) {
                sourceStr = srcPosition.toString();
            } else {
                sourceStr = value.toString() + " @ " + value.graph().method().format("%H.%n(%p)");
            }
        } else {
            sourceStr = source.toString();
        }
        doWrite(out, String.format("%-35s\t%-10s\n", provider.getFlowClass().getSimpleName(), sourceStr));
    });
}
Also used : UnknownTypeFlow(com.oracle.graal.pointsto.flow.UnknownTypeFlow) FilterTypeFlow(com.oracle.graal.pointsto.flow.FilterTypeFlow) AllInstantiatedTypeFlow(com.oracle.graal.pointsto.flow.AllInstantiatedTypeFlow) JavaWriteTypeFlow(com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.JavaWriteTypeFlow) StoreStaticFieldTypeFlow(com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreStaticFieldTypeFlow) StoreInstanceFieldTypeFlow(com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreInstanceFieldTypeFlow) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StoreIndexedTypeFlow(com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.StoreIndexedTypeFlow) BigBang(com.oracle.graal.pointsto.BigBang) UnsafePartitionLoadTypeFlow(com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafePartitionLoadTypeFlow) Path(java.nio.file.Path) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition) LoadIndexedTypeFlow(com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.LoadIndexedTypeFlow) InitialParamTypeFlow(com.oracle.graal.pointsto.flow.InitialParamTypeFlow) LoadStaticFieldTypeFlow(com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadStaticFieldTypeFlow) UnsafeLoadTypeFlow(com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafeLoadTypeFlow) FormalParamTypeFlow(com.oracle.graal.pointsto.flow.FormalParamTypeFlow) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FieldSinkTypeFlow(com.oracle.graal.pointsto.flow.FieldSinkTypeFlow) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) Collectors(java.util.stream.Collectors) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) Objects(java.util.Objects) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) List(java.util.List) MergeTypeFlow(com.oracle.graal.pointsto.flow.MergeTypeFlow) FieldTypeFlow(com.oracle.graal.pointsto.flow.FieldTypeFlow) Entry(java.util.Map.Entry) AtomicReadTypeFlow(com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.AtomicReadTypeFlow) CompareAndSwapTypeFlow(com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.CompareAndSwapTypeFlow) LocalDateTime(java.time.LocalDateTime) InstanceOfTypeFlow(com.oracle.graal.pointsto.flow.InstanceOfTypeFlow) AllSynchronizedTypeFlow(com.oracle.graal.pointsto.flow.AllSynchronizedTypeFlow) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TypeFlowBuilder(com.oracle.graal.pointsto.flow.builder.TypeFlowBuilder) DynamicNewInstanceTypeFlow(com.oracle.graal.pointsto.flow.DynamicNewInstanceTypeFlow) MonitorEnterTypeFlow(com.oracle.graal.pointsto.flow.MonitorEnterTypeFlow) AtomicWriteTypeFlow(com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.AtomicWriteTypeFlow) ActualReturnTypeFlow(com.oracle.graal.pointsto.flow.ActualReturnTypeFlow) LoadInstanceFieldTypeFlow(com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadInstanceFieldTypeFlow) CloneTypeFlow(com.oracle.graal.pointsto.flow.CloneTypeFlow) InvokeTypeFlow(com.oracle.graal.pointsto.flow.InvokeTypeFlow) JVMCIError(jdk.vm.ci.common.JVMCIError) SourceTypeFlow(com.oracle.graal.pointsto.flow.SourceTypeFlow) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) FieldFilterTypeFlow(com.oracle.graal.pointsto.flow.FieldFilterTypeFlow) JavaReadTypeFlow(com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.JavaReadTypeFlow) FileWriter(java.io.FileWriter) FormalReturnTypeFlow(com.oracle.graal.pointsto.flow.FormalReturnTypeFlow) IOException(java.io.IOException) UnsafePartitionStoreTypeFlow(com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafePartitionStoreTypeFlow) UnsafeWriteSinkTypeFlow(com.oracle.graal.pointsto.flow.UnsafeWriteSinkTypeFlow) Consumer(java.util.function.Consumer) NewInstanceTypeFlow(com.oracle.graal.pointsto.flow.NewInstanceTypeFlow) NullCheckTypeFlow(com.oracle.graal.pointsto.flow.NullCheckTypeFlow) DateTimeFormatter(java.time.format.DateTimeFormatter) FrozenFieldFilterTypeFlow(com.oracle.graal.pointsto.flow.FrozenFieldFilterTypeFlow) UnsafeStoreTypeFlow(com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafeStoreTypeFlow) TypeFlow(com.oracle.graal.pointsto.flow.TypeFlow) ArrayElementsTypeFlow(com.oracle.graal.pointsto.flow.ArrayElementsTypeFlow) Comparator(java.util.Comparator) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) FileSystems(java.nio.file.FileSystems) TypeFlowBuilder(com.oracle.graal.pointsto.flow.builder.TypeFlowBuilder) Objects(java.util.Objects) ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Example 2 with TypeFlowBuilder

use of com.oracle.graal.pointsto.flow.builder.TypeFlowBuilder in project graal by oracle.

the class MethodTypeFlowBuilder method apply.

protected void apply() {
    // assert method.getAnnotation(Fold.class) == null : method;
    if (method.getAnnotation(NodeIntrinsic.class) != null) {
        graph.getDebug().log("apply MethodTypeFlow on node intrinsic %s", method);
        AnalysisType returnType = (AnalysisType) method.getSignature().getReturnType(method.getDeclaringClass());
        if (returnType.getJavaKind() == JavaKind.Object) {
            /*
                 * This is a method used in a snippet, so most likely the return value does not
                 * matter at all. However, some methods return an object, and the snippet continues
                 * to work with the object. So pretend that this method returns an object of the
                 * exact return type.
                 */
            TypeFlow<?> returnTypeFlow = methodFlow.getResultFlow().getDeclaredType().getTypeFlow(this.bb, true);
            returnTypeFlow = new ProxyTypeFlow(null, returnTypeFlow);
            FormalReturnTypeFlow resultFlow = new FormalReturnTypeFlow(null, returnType, method);
            returnTypeFlow.addOriginalUse(this.bb, resultFlow);
            methodFlow.addMiscEntry(returnTypeFlow);
            methodFlow.setResult(resultFlow);
        }
        return;
    }
    if (!parse()) {
        return;
    }
    this.bb.getUnsupportedFeatures().checkMethod(method, graph);
    processedNodes = new NodeBitMap(graph);
    TypeFlowsOfNodes typeFlows = new TypeFlowsOfNodes();
    for (Node n : graph.getNodes()) {
        if (n instanceof ParameterNode) {
            ParameterNode node = (ParameterNode) n;
            if (node.getStackKind() == JavaKind.Object) {
                TypeFlowBuilder<?> paramBuilder = TypeFlowBuilder.create(bb, node, FormalParamTypeFlow.class, () -> {
                    boolean isStatic = Modifier.isStatic(method.getModifiers());
                    int index = node.index();
                    FormalParamTypeFlow parameter;
                    if (!isStatic && index == 0) {
                        AnalysisType paramType = method.getDeclaringClass();
                        parameter = new FormalReceiverTypeFlow(node, paramType, method);
                    } else {
                        int offset = isStatic ? 0 : 1;
                        AnalysisType paramType = (AnalysisType) method.getSignature().getParameterType(index - offset, method.getDeclaringClass());
                        parameter = new FormalParamTypeFlow(node, paramType, method, index);
                    }
                    methodFlow.setParameter(index, parameter);
                    return parameter;
                });
                typeFlowGraphBuilder.checkFormalParameterBuilder(paramBuilder);
                typeFlows.add(node, paramBuilder);
            }
        } else if (n instanceof BoxNode) {
            BoxNode node = (BoxNode) n;
            Object key = uniqueKey(node);
            BytecodeLocation boxSite = bb.analysisPolicy().createAllocationSite(bb, key, methodFlow.getMethod());
            AnalysisType type = (AnalysisType) StampTool.typeOrNull(node);
            TypeFlowBuilder<?> boxBuilder = TypeFlowBuilder.create(bb, node, BoxTypeFlow.class, () -> {
                BoxTypeFlow boxFlow = new BoxTypeFlow(node, type, boxSite);
                methodFlow.addAllocation(boxFlow);
                return boxFlow;
            });
            typeFlows.add(node, boxBuilder);
        }
        for (Node input : n.inputs()) {
            /*
                 * TODO change the handling of constants so that the SourceTypeFlow is created on
                 * demand, with the optimization that only one SourceTypeFlow is created ever for
                 * every distinct object (using, e.g., caching in a global IdentityHashMap).
                 */
            if (input instanceof ConstantNode && !typeFlows.contains((ConstantNode) input)) {
                ConstantNode node = (ConstantNode) input;
                if (node.asJavaConstant().isNull()) {
                    TypeFlowBuilder<SourceTypeFlow> sourceBuilder = TypeFlowBuilder.create(bb, node, SourceTypeFlow.class, () -> {
                        SourceTypeFlow constantSource = new SourceTypeFlow(node, TypeState.forNull());
                        methodFlow.addSource(constantSource);
                        return constantSource;
                    });
                    typeFlows.add(node, sourceBuilder);
                } else if (node.asJavaConstant().getJavaKind() == JavaKind.Object) {
                    /*
                         * TODO a SubstrateObjectConstant wrapping a PrimitiveConstant has kind
                         * equals to Object. Do we care about the effective value of these primitive
                         * constants in the analysis?
                         */
                    assert StampTool.isExactType(node);
                    AnalysisType type = (AnalysisType) StampTool.typeOrNull(node);
                    assert type.isInstantiated();
                    TypeFlowBuilder<SourceTypeFlow> sourceBuilder = TypeFlowBuilder.create(bb, node, SourceTypeFlow.class, () -> {
                        SourceTypeFlow constantSource = new SourceTypeFlow(node, TypeState.forConstant(this.bb, node.asJavaConstant(), type));
                        methodFlow.addSource(constantSource);
                        return constantSource;
                    });
                    typeFlows.add(node, sourceBuilder);
                }
            }
        }
    }
    // Propagate the type flows through the method's graph
    new NodeIterator(graph.start(), typeFlows).apply();
    /* Prune the method graph. Eliminate nodes with no uses. */
    typeFlowGraphBuilder.build();
    /*
         * Make sure that all existing InstanceOfNodes are registered even when only used as an
         * input of a conditional.
         */
    for (Node n : graph.getNodes()) {
        if (n instanceof InstanceOfNode) {
            InstanceOfNode instanceOf = (InstanceOfNode) n;
            markFieldsUsedInComparison(instanceOf.getValue());
        } else if (n instanceof ObjectEqualsNode) {
            ObjectEqualsNode compareNode = (ObjectEqualsNode) n;
            markFieldsUsedInComparison(compareNode.getX());
            markFieldsUsedInComparison(compareNode.getY());
        }
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) TypeFlowBuilder(com.oracle.graal.pointsto.flow.builder.TypeFlowBuilder) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) WordCastNode(org.graalvm.compiler.word.WordCastNode) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode) ObjectEqualsNode(org.graalvm.compiler.nodes.calc.ObjectEqualsNode) BasicObjectCloneNode(org.graalvm.compiler.replacements.nodes.BasicObjectCloneNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AnalysisUnsafePartitionLoadNode(com.oracle.graal.pointsto.nodes.AnalysisUnsafePartitionLoadNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AnalysisArraysCopyOfNode(com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode) DynamicNewInstanceNode(org.graalvm.compiler.nodes.java.DynamicNewInstanceNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) NewMultiArrayNode(org.graalvm.compiler.nodes.java.NewMultiArrayNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) BinaryMathIntrinsicNode(org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode) IfNode(org.graalvm.compiler.nodes.IfNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) UnsafeCompareAndSwapNode(org.graalvm.compiler.nodes.java.UnsafeCompareAndSwapNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode) BasicArrayCopyNode(org.graalvm.compiler.replacements.nodes.BasicArrayCopyNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) UnaryMathIntrinsicNode(org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) BytecodeExceptionNode(org.graalvm.compiler.nodes.extended.BytecodeExceptionNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) AnalysisUnsafePartitionStoreNode(com.oracle.graal.pointsto.nodes.AnalysisUnsafePartitionStoreNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) BytecodeLocation(com.oracle.graal.pointsto.flow.context.BytecodeLocation) NodeIntrinsic(org.graalvm.compiler.graph.Node.NodeIntrinsic) PostOrderNodeIterator(org.graalvm.compiler.phases.graph.PostOrderNodeIterator) NodeBitMap(org.graalvm.compiler.graph.NodeBitMap) ObjectEqualsNode(org.graalvm.compiler.nodes.calc.ObjectEqualsNode) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode)

Aggregations

BigBang (com.oracle.graal.pointsto.BigBang)1 ActualReturnTypeFlow (com.oracle.graal.pointsto.flow.ActualReturnTypeFlow)1 AllInstantiatedTypeFlow (com.oracle.graal.pointsto.flow.AllInstantiatedTypeFlow)1 AllSynchronizedTypeFlow (com.oracle.graal.pointsto.flow.AllSynchronizedTypeFlow)1 ArrayElementsTypeFlow (com.oracle.graal.pointsto.flow.ArrayElementsTypeFlow)1 CloneTypeFlow (com.oracle.graal.pointsto.flow.CloneTypeFlow)1 DynamicNewInstanceTypeFlow (com.oracle.graal.pointsto.flow.DynamicNewInstanceTypeFlow)1 FieldFilterTypeFlow (com.oracle.graal.pointsto.flow.FieldFilterTypeFlow)1 FieldSinkTypeFlow (com.oracle.graal.pointsto.flow.FieldSinkTypeFlow)1 FieldTypeFlow (com.oracle.graal.pointsto.flow.FieldTypeFlow)1 FilterTypeFlow (com.oracle.graal.pointsto.flow.FilterTypeFlow)1 FormalParamTypeFlow (com.oracle.graal.pointsto.flow.FormalParamTypeFlow)1 FormalReturnTypeFlow (com.oracle.graal.pointsto.flow.FormalReturnTypeFlow)1 FrozenFieldFilterTypeFlow (com.oracle.graal.pointsto.flow.FrozenFieldFilterTypeFlow)1 InitialParamTypeFlow (com.oracle.graal.pointsto.flow.InitialParamTypeFlow)1 InstanceOfTypeFlow (com.oracle.graal.pointsto.flow.InstanceOfTypeFlow)1 InvokeTypeFlow (com.oracle.graal.pointsto.flow.InvokeTypeFlow)1 LoadInstanceFieldTypeFlow (com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadInstanceFieldTypeFlow)1 LoadStaticFieldTypeFlow (com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadStaticFieldTypeFlow)1 MergeTypeFlow (com.oracle.graal.pointsto.flow.MergeTypeFlow)1