Search in sources :

Example 1 with JavaMethodProfile

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

the class StaticAnalysisResultsBuilder method cachedMethodProfile.

private JavaMethodProfile cachedMethodProfile(JavaMethodProfile[] cache, int cacheIdx, Collection<AnalysisMethod> callees) {
    JavaMethodProfile result = cache[cacheIdx];
    if (result == null) {
        result = createMethodProfile(callees);
        cache[cacheIdx] = result;
    }
    return result;
}
Also used : JavaMethodProfile(jdk.vm.ci.meta.JavaMethodProfile)

Example 2 with JavaMethodProfile

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

the class StaticAnalysisResultsBuilder method createMethodProfile.

private JavaMethodProfile createMethodProfile(Collection<AnalysisMethod> callees) {
    ProfiledMethod[] pitems = new ProfiledMethod[callees.size()];
    double probability = 1d / pitems.length;
    int idx = 0;
    for (AnalysisMethod aMethod : callees) {
        ResolvedJavaMethod convertedMethod = converter == null ? aMethod : converter.lookup(aMethod);
        pitems[idx++] = new ProfiledMethod(convertedMethod, probability);
    }
    return new JavaMethodProfile(0, pitems);
}
Also used : ProfiledMethod(jdk.vm.ci.meta.JavaMethodProfile.ProfiledMethod) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) JavaMethodProfile(jdk.vm.ci.meta.JavaMethodProfile) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with JavaMethodProfile

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

the class DevirtualizeCallsPhase method run.

@Override
protected void run(StructuredGraph graph) {
    for (Invoke invoke : graph.getInvokes()) {
        if (invoke.callTarget() instanceof SubstrateMethodCallTargetNode) {
            SubstrateMethodCallTargetNode callTarget = (SubstrateMethodCallTargetNode) invoke.callTarget();
            JavaMethodProfile methodProfile = callTarget.getMethodProfile();
            if (methodProfile != null) {
                if (methodProfile.getMethods().length == 0) {
                    unreachableInvoke(graph, invoke, callTarget);
                } else if (methodProfile.getMethods().length == 1) {
                    if (callTarget.invokeKind().isIndirect()) {
                        singleCallee((HostedMethod) methodProfile.getMethods()[0].getMethod(), graph, invoke, callTarget);
                    }
                }
            }
        }
    }
}
Also used : HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) SubstrateMethodCallTargetNode(com.oracle.svm.hosted.nodes.SubstrateMethodCallTargetNode) JavaMethodProfile(jdk.vm.ci.meta.JavaMethodProfile) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 4 with JavaMethodProfile

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

the class StaticAnalysisResultsBuilder method makeMethodProfile.

private JavaMethodProfile makeMethodProfile(Collection<AnalysisMethod> callees) {
    if (PointstoOptions.AnalysisSizeCutoff.getValue(bb.getOptions()) != -1 && callees.size() > PointstoOptions.AnalysisSizeCutoff.getValue(bb.getOptions())) {
        return null;
    }
    if (callees.isEmpty()) {
        synchronized (methods0) {
            return cachedMethodProfile(methods0, 0, callees);
        }
    } else if (callees.size() == 1) {
        synchronized (methods1) {
            return cachedMethodProfile(methods1, callees.iterator().next().getId(), callees);
        }
    }
    synchronized (methods) {
        JavaMethodProfile created = createMethodProfile(callees);
        methods.putIfAbsent(created, created);
        return created;
    }
}
Also used : JavaMethodProfile(jdk.vm.ci.meta.JavaMethodProfile)

Example 5 with JavaMethodProfile

use of jdk.vm.ci.meta.JavaMethodProfile 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)

Aggregations

JavaMethodProfile (jdk.vm.ci.meta.JavaMethodProfile)5 InstanceOfTypeFlow (com.oracle.graal.pointsto.flow.InstanceOfTypeFlow)1 InvokeTypeFlow (com.oracle.graal.pointsto.flow.InvokeTypeFlow)1 MethodFlowsGraph (com.oracle.graal.pointsto.flow.MethodFlowsGraph)1 MethodTypeFlow (com.oracle.graal.pointsto.flow.MethodTypeFlow)1 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 BytecodeEntry (com.oracle.graal.pointsto.results.StaticAnalysisResults.BytecodeEntry)1 TypeState (com.oracle.graal.pointsto.typestate.TypeState)1 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)1 SubstrateMethodCallTargetNode (com.oracle.svm.hosted.nodes.SubstrateMethodCallTargetNode)1 ArrayList (java.util.ArrayList)1 ProfiledMethod (jdk.vm.ci.meta.JavaMethodProfile.ProfiledMethod)1 JavaTypeProfile (jdk.vm.ci.meta.JavaTypeProfile)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 Invoke (org.graalvm.compiler.nodes.Invoke)1