Search in sources :

Example 16 with AnalysisType

use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.

the class UniverseBuilder method collectMonitorFieldInfo.

// @formatter:off
// /**
// * New version of the method that uses the static analysis results collected by the static
// * analysis results builder instead of accessing the type states directly.
// */
// @SuppressWarnings("try")
// private void collectHashCodeFieldInfo() {
// 
// AnalysisMethod method = null;
// try {
// method = aMetaAccess.lookupJavaMethod(System.class.getMethod("identityHashCode", Object.class));
// } catch (NoSuchMethodException | SecurityException e) {
// throw shouldNotReachHere();
// }
// if (method == null) {
// return;
// }
// 
// try (Indent indent = Debug.logAndIndent("check types for which identityHashCode is invoked")) {
// 
// // Check which types may be a parameter of System.identityHashCode (which is invoked by
// // Object.hashCode).
// 
// HostedMethod hMethod = hUniverse.methods.get(method);
// JavaTypeProfile paramProfile = hMethod.getProfilingInfo().getParameterTypeProfile(0);
// 
// if (paramProfile == null) {
// 
// // This is the case if the identityHashCode parameter type is unknown. So all
// // classes get the hashCode field.
// // But this is only a fail-safe, because it cannot happen in the current
// // implementation of the analysis pass.
// 
// Debug.log("all types need a hashCode field");
// for (HostedType hType : hUniverse.getTypes()) {
// if (hType.isInstanceClass()) {
// ((HostedInstanceClass) hType).setNeedHashCodeField();
// }
// }
// hUniverse.getObjectClass().setNeedHashCodeField();
// } else {
// 
// // Mark all paramter types of System.identityHashCode to have a hash-code field.
// 
// for (ProfiledType type : paramProfile.getTypes()) {
// Debug.log("type %s is argument to identityHashCode", type);
// 
// /*
// * Array types get a hash-code field by default. So we only have to deal with
// * instance types here.
// */
// if (type.getType().isInstanceClass()) {
// HostedInstanceClass hType = (HostedInstanceClass) hUniverse.lookup(type.getType());
// hType.setNeedHashCodeField();
// }
// }
// }
// }
// }
// @formatter:on
private void collectMonitorFieldInfo(BigBang bb) {
    if (!SubstrateOptions.MultiThreaded.getValue()) {
        /* No locking information needed in single-threaded mode. */
        return;
    }
    TypeState allSynchronizedTypeState = bb.getAllSynchronizedTypeState();
    for (AnalysisType aType : allSynchronizedTypeState.types()) {
        if (canHaveMonitorFields(aType)) {
            final HostedInstanceClass hostedInstanceClass = (HostedInstanceClass) hUniverse.lookup(aType);
            hostedInstanceClass.setNeedMonitorField();
        }
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) TypeState(com.oracle.graal.pointsto.typestate.TypeState)

Example 17 with AnalysisType

use of com.oracle.graal.pointsto.meta.AnalysisType 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 18 with AnalysisType

use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.

the class MultiTypeState method typesIterator.

/**
 * It iterates over the types bit set and gets the types using
 * {@link AnalysisUniverse#getType(int)}. The types are iterated in ascending order of their IDs
 * by way of bit set iteration.
 */
@Override
public Iterator<AnalysisType> typesIterator() {
    return new Iterator<AnalysisType>() {

        /**
         * Initialize to the index of the first set bit.
         */
        private int currentTypeId = typesBitSet.nextSetBit(0);

        @Override
        public boolean hasNext() {
            return currentTypeId >= 0;
        }

        @Override
        public AnalysisType next() {
            AnalysisType next = bigbang.getUniverse().getType(currentTypeId);
            currentTypeId = typesBitSet.nextSetBit(currentTypeId + 1);
            return next;
        }
    };
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) Iterator(java.util.Iterator)

Example 19 with AnalysisType

use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.

the class UnknownTypeState method forContextInsensitiveTypeState.

/**
 * Simplifies a type state by replacing all context sensitive objects with context insensitive
 * objects.
 */
public static TypeState forContextInsensitiveTypeState(BigBang bb, TypeState state) {
    if (!PointstoOptions.AllocationSiteSensitiveHeap.getValue(bb.getOptions()) || state.isEmpty() || state.isNull() || state.isUnknown()) {
        /* The type state is already context insensitive. */
        return state;
    } else {
        if (state.isSingleTypeState()) {
            AnalysisType type = state.exactType();
            AnalysisObject analysisObject = type.getContextInsensitiveAnalysisObject();
            return new SingleTypeState(bb, state.canBeNull(), bb.analysisPolicy().makePoperties(bb, analysisObject), analysisObject);
        } else {
            MultiTypeState multiState = (MultiTypeState) state;
            AnalysisObject[] objectsArray = new AnalysisObject[multiState.typesCount()];
            int i = 0;
            for (AnalysisType type : multiState.types()) {
                objectsArray[i++] = type.getContextInsensitiveAnalysisObject();
            }
            /*
                 * For types use the already created bit set. Since the original type state is
                 * immutable its types bit set cannot change.
                 */
            BitSet typesBitSet = multiState.typesBitSet;
            int properties = bb.analysisPolicy().makePoperties(bb, objectsArray);
            return new MultiTypeState(bb, multiState.canBeNull(), properties, typesBitSet, objectsArray);
        }
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) AnalysisObject(com.oracle.graal.pointsto.flow.context.object.AnalysisObject) BitSet(java.util.BitSet)

Example 20 with AnalysisType

use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.

the class MethodTypeFlowBuilder method processNewInstance.

protected void processNewInstance(NewInstanceNode node, TypeFlowsOfNodes state) {
    AnalysisType type = (AnalysisType) node.instanceClass();
    assert type.isInstantiated();
    Object key = uniqueKey(node);
    BytecodeLocation allocationLabel = bb.analysisPolicy().createAllocationSite(bb, key, method);
    TypeFlowBuilder<?> newInstanceBuilder = TypeFlowBuilder.create(bb, node, NewInstanceTypeFlow.class, () -> {
        NewInstanceTypeFlow newInstance = createNewInstanceTypeFlow(node, type, allocationLabel);
        /* Instance fields of a new object are initialized to null state in AnalysisField. */
        methodFlow.addAllocation(newInstance);
        return newInstance;
    });
    state.add(node, newInstanceBuilder);
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) BytecodeLocation(com.oracle.graal.pointsto.flow.context.BytecodeLocation)

Aggregations

AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)38 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)10 TypeState (com.oracle.graal.pointsto.typestate.TypeState)7 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)6 AnalysisObject (com.oracle.graal.pointsto.flow.context.object.AnalysisObject)5 DynamicHub (com.oracle.svm.core.hub.DynamicHub)5 ArrayList (java.util.ArrayList)5 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)4 SVMHost (com.oracle.svm.hosted.SVMHost)4 JavaKind (jdk.vm.ci.meta.JavaKind)4 Indent (org.graalvm.compiler.debug.Indent)4 MethodTypeFlow (com.oracle.graal.pointsto.flow.MethodTypeFlow)3 BytecodeLocation (com.oracle.graal.pointsto.flow.context.BytecodeLocation)3 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)3 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)3 DuringAnalysisAccessImpl (com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl)3 HostedType (com.oracle.svm.hosted.meta.HostedType)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 BigBang (com.oracle.graal.pointsto.BigBang)2 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2