Search in sources :

Example 1 with MethodTypeFlow

use of com.oracle.graal.pointsto.flow.MethodTypeFlow in project graal by oracle.

the class StaticAnalysisResultsBuilder method makeResults.

public StaticAnalysisResults makeResults(AnalysisMethod method) {
    MethodTypeFlow methodFlow = method.getTypeFlow();
    MethodFlowsGraph originalFlows = methodFlow.getOriginalMethodFlows();
    ArrayList<JavaTypeProfile> paramProfiles = new ArrayList<>(originalFlows.getParameters().length);
    for (int i = 0; i < originalFlows.getParameters().length; i++) {
        JavaTypeProfile paramProfile = makeTypeProfile(methodFlow.foldTypeFlow(bb, originalFlows.getParameter(i)));
        if (paramProfile != null) {
            ensureSize(paramProfiles, i);
            paramProfiles.set(i, paramProfile);
        }
    }
    JavaTypeProfile[] parameterTypeProfiles = null;
    if (paramProfiles.size() > 0) {
        parameterTypeProfiles = paramProfiles.toArray(new JavaTypeProfile[paramProfiles.size()]);
    }
    JavaTypeProfile resultTypeProfile = makeTypeProfile(methodFlow.foldTypeFlow(bb, originalFlows.getResult()));
    ArrayList<BytecodeEntry> entries = new ArrayList<>(method.getCodeSize());
    for (InstanceOfTypeFlow originalInstanceOf : originalFlows.getInstaceOfFlows()) {
        if (BytecodeLocation.hasValidBci(originalInstanceOf.getLocation())) {
            int bci = originalInstanceOf.getLocation().getBci();
            /* Fold the instanceof flows. */
            TypeState instanceOfTypeState = methodFlow.foldTypeFlow(bb, originalInstanceOf);
            originalInstanceOf.setState(bb, instanceOfTypeState);
            JavaTypeProfile typeProfile = makeTypeProfile(instanceOfTypeState);
            if (typeProfile != null) {
                ensureSize(entries, bci);
                assert entries.get(bci) == null : "In " + method.format("%h.%n(%p)") + " a profile with bci=" + bci + " already exists: " + entries.get(bci);
                entries.set(bci, createBytecodeEntry(method, bci, typeProfile, null, null));
            }
        }
    }
    for (InvokeTypeFlow originalInvoke : originalFlows.getInvokes()) {
        if (BytecodeLocation.hasValidBci(originalInvoke.getLocation())) {
            int bci = originalInvoke.getLocation().getBci();
            TypeState invokeTypeState = TypeState.forEmpty();
            if (originalInvoke.getTargetMethod().hasReceiver()) {
                invokeTypeState = methodFlow.foldTypeFlow(bb, originalInvoke.getReceiver());
                originalInvoke.setState(bb, invokeTypeState);
            }
            TypeFlow<?> originalReturn = originalInvoke.getActualReturn();
            TypeState returnTypeState = null;
            if (originalReturn != null) {
                returnTypeState = methodFlow.foldTypeFlow(bb, originalReturn);
                originalReturn.setState(bb, returnTypeState);
            }
            JavaTypeProfile typeProfile = makeTypeProfile(invokeTypeState);
            JavaMethodProfile methodProfile = makeMethodProfile(originalInvoke.getCallees());
            JavaTypeProfile invokeResultTypeProfile = originalReturn == null ? null : makeTypeProfile(returnTypeState);
            if (typeProfile != null || methodProfile != null || invokeResultTypeProfile != null) {
                ensureSize(entries, bci);
                assert entries.get(bci) == null : "In " + method.format("%h.%n(%p)") + " a profile with bci=" + bci + " already exists: " + entries.get(bci);
                entries.set(bci, createBytecodeEntry(method, bci, typeProfile, methodProfile, invokeResultTypeProfile));
            }
        }
    }
    if (PointstoOptions.PrintSynchronizedAnalysis.getValue(bb.getOptions())) {
        originalFlows.getMonitorEntries().stream().filter(m -> m.getState().typesCount() > 20).sorted(Comparator.comparingInt(m2 -> m2.getState().typesCount())).forEach(monitorEnter -> {
            TypeState monitorEntryState = monitorEnter.getState();
            String typesString = monitorEntryState.closeToAllInstantiated(bb) ? "close to all instantiated" : StreamSupport.stream(monitorEntryState.types().spliterator(), false).map(AnalysisType::getName).collect(Collectors.joining(", "));
            StringBuilder strb = new StringBuilder();
            strb.append("Location: ");
            String methodName = method.format("%h.%n(%p)");
            int bci = monitorEnter.getLocation().getBci();
            if (bci != BytecodeLocation.UNKNOWN_BCI) {
                StackTraceElement traceElement = method.asStackTraceElement(bci);
                String sourceLocation = traceElement.getFileName() + ":" + traceElement.getLineNumber();
                strb.append("@(").append(methodName).append(":").append(bci).append(")");
                strb.append("=(").append(sourceLocation).append(")");
            } else {
                strb.append("@(").append(methodName).append(")");
            }
            strb.append("\n");
            strb.append("Synchronized types #: ").append(monitorEntryState.typesCount()).append("\n");
            strb.append("Types: ").append(typesString).append("\n");
            System.out.println(strb);
        });
    }
    BytecodeEntry first = null;
    for (int i = entries.size() - 1; i >= 0; i--) {
        BytecodeEntry cur = entries.get(i);
        if (cur != null) {
            cur.next = first;
            first = cur;
        }
    }
    return createStaticAnalysisResults(method, parameterTypeProfiles, resultTypeProfile, first);
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) BytecodeEntry(com.oracle.graal.pointsto.results.StaticAnalysisResults.BytecodeEntry) ArrayList(java.util.ArrayList) TypeState(com.oracle.graal.pointsto.typestate.TypeState) InstanceOfTypeFlow(com.oracle.graal.pointsto.flow.InstanceOfTypeFlow) JavaMethodProfile(jdk.vm.ci.meta.JavaMethodProfile) InvokeTypeFlow(com.oracle.graal.pointsto.flow.InvokeTypeFlow) MethodTypeFlow(com.oracle.graal.pointsto.flow.MethodTypeFlow) MethodFlowsGraph(com.oracle.graal.pointsto.flow.MethodFlowsGraph) JavaTypeProfile(jdk.vm.ci.meta.JavaTypeProfile)

Example 2 with MethodTypeFlow

use of com.oracle.graal.pointsto.flow.MethodTypeFlow in project graal by oracle.

the class BigBang method addRootMethod.

@SuppressWarnings("try")
public AnalysisMethod addRootMethod(AnalysisMethod aMethod) {
    if (aMethod.isRootMethod()) {
        return aMethod;
    }
    aMethod.registerAsRootMethod();
    final MethodTypeFlow methodFlow = aMethod.getTypeFlow();
    try (Indent indent = debug.logAndIndent("add root method %s", aMethod.getName())) {
        boolean isStatic = Modifier.isStatic(aMethod.getModifiers());
        int paramCount = aMethod.getSignature().getParameterCount(!isStatic);
        int offset = 0;
        if (!isStatic) {
            methodFlow.setInitialReceiverFlow(this, aMethod.getDeclaringClass());
            offset = 1;
        }
        for (int i = offset; i < paramCount; i++) {
            AnalysisType declaredParamType = (AnalysisType) aMethod.getSignature().getParameterType(i - offset, aMethod.getDeclaringClass());
            if (declaredParamType.getJavaKind() == JavaKind.Object) {
                methodFlow.setInitialParameterFlow(this, declaredParamType, i);
            }
        }
    }
    postTask(new DebugContextRunnable() {

        @Override
        public void run(DebugContext ignore) {
            methodFlow.addContext(BigBang.this, BigBang.this.contextPolicy().emptyContext(), null);
        }

        @Override
        public DebugContext getDebug(OptionValues ignored, List<DebugHandlersFactory> factories) {
            return DebugContext.DISABLED;
        }
    });
    return aMethod;
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) Indent(org.graalvm.compiler.debug.Indent) OptionValues(org.graalvm.compiler.options.OptionValues) DebugHandlersFactory(org.graalvm.compiler.debug.DebugHandlersFactory) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugContextRunnable(com.oracle.graal.pointsto.util.CompletionExecutor.DebugContextRunnable) MethodTypeFlow(com.oracle.graal.pointsto.flow.MethodTypeFlow)

Aggregations

MethodTypeFlow (com.oracle.graal.pointsto.flow.MethodTypeFlow)2 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)2 InstanceOfTypeFlow (com.oracle.graal.pointsto.flow.InstanceOfTypeFlow)1 InvokeTypeFlow (com.oracle.graal.pointsto.flow.InvokeTypeFlow)1 MethodFlowsGraph (com.oracle.graal.pointsto.flow.MethodFlowsGraph)1 BytecodeEntry (com.oracle.graal.pointsto.results.StaticAnalysisResults.BytecodeEntry)1 TypeState (com.oracle.graal.pointsto.typestate.TypeState)1 DebugContextRunnable (com.oracle.graal.pointsto.util.CompletionExecutor.DebugContextRunnable)1 ArrayList (java.util.ArrayList)1 JavaMethodProfile (jdk.vm.ci.meta.JavaMethodProfile)1 JavaTypeProfile (jdk.vm.ci.meta.JavaTypeProfile)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 DebugHandlersFactory (org.graalvm.compiler.debug.DebugHandlersFactory)1 Indent (org.graalvm.compiler.debug.Indent)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 GraalDebugHandlersFactory (org.graalvm.compiler.printer.GraalDebugHandlersFactory)1