Search in sources :

Example 26 with AnalysisType

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

the class Inflation method handleUnknownObjectField.

/**
 * Register a field as containing unknown object(s), i.e., is usually written only in hosted
 * code. It can have multiple declared types provided via annotation.
 */
private void handleUnknownObjectField(AnalysisField aField, AnalysisType... declaredTypes) {
    assert aField.getJavaKind() == JavaKind.Object;
    aField.registerAsWritten(null);
    /* Link the field with all declared types. */
    for (AnalysisType fieldDeclaredType : declaredTypes) {
        TypeFlow<?> fieldDeclaredTypeFlow = fieldDeclaredType.getTypeFlow(this, true);
        if (aField.isStatic()) {
            fieldDeclaredTypeFlow.addUse(this, aField.getStaticFieldFlow());
        } else {
            fieldDeclaredTypeFlow.addUse(this, aField.getInitialInstanceFieldFlow());
            if (fieldDeclaredType.isArray()) {
                AnalysisType fieldComponentType = fieldDeclaredType.getComponentType();
                aField.getInitialInstanceFieldFlow().addUse(this, aField.getInstanceFieldFlow());
                // object field is not empty?
                if (!fieldComponentType.isPrimitive()) {
                    /*
                         * Write the component type abstract object into the field array elements
                         * type flow, i.e., the array elements type flow of the abstract object of
                         * the field declared type.
                         *
                         * This is required so that the index loads from this array return all the
                         * possible objects that can be stored in the array.
                         */
                    TypeFlow<?> elementsFlow = fieldDeclaredType.getContextInsensitiveAnalysisObject().getArrayElementsFlow(this, true);
                    fieldComponentType.getTypeFlow(this, false).addUse(this, elementsFlow);
                /*
                         * In the current implementation it is not necessary to do it it recursively
                         * for multidimensional arrays since we don't model individual array
                         * elements, so from the point of view of the static analysis the field's
                         * array elements value is non null (in the case of a n-dimensional array
                         * that value is another array, n-1 dimensional).
                         */
                }
            }
        }
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType)

Example 27 with AnalysisType

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

the class Inflation method fillInterfaces.

/**
 * Fill array returned by Class.getInterfaces().
 */
private void fillInterfaces(AnalysisType type) {
    SVMHost svmHost = (SVMHost) hostVM;
    DynamicHub hub = svmHost.dynamicHub(type);
    AnalysisType[] aInterfaces = type.getInterfaces();
    if (aInterfaces.length == 0) {
        hub.setInterfacesEncoding(null);
    } else if (aInterfaces.length == 1) {
        hub.setInterfacesEncoding(svmHost.dynamicHub(aInterfaces[0]));
    } else {
        /*
             * Many interfaces arrays are the same, e.g., all arrays implement the same two
             * interfaces. We want to avoid duplicate arrays with the same content in the native
             * image heap.
             */
        hub.setInterfacesEncoding(interfacesEncodings.computeIfAbsent(new InterfacesEncodingKey(aInterfaces), k -> k.createHubs()));
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) SVMHost(com.oracle.svm.hosted.SVMHost) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 28 with AnalysisType

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

the class Inflation method extractAnnotationTypes.

private List<AnalysisType> extractAnnotationTypes(AnalysisField field, UnknownObjectField unknownObjectField) {
    List<Class<?>> annotationTypes = new ArrayList<>(Arrays.asList(unknownObjectField.types()));
    for (String annotationTypeName : unknownObjectField.fullyQualifiedTypes()) {
        try {
            Class<?> annotationType = Class.forName(annotationTypeName);
            annotationTypes.add(annotationType);
        } catch (ClassNotFoundException e) {
            throw shouldNotReachHere("Annotation type not found " + annotationTypeName);
        }
    }
    List<AnalysisType> aAnnotationTypes = new ArrayList<>();
    AnalysisType declaredType = field.getType();
    for (Class<?> annotationType : annotationTypes) {
        AnalysisType aAnnotationType = metaAccess.lookupJavaType(annotationType);
        assert !WordBase.class.isAssignableFrom(annotationType) : "Annotation type must not be a subtype of WordBase: field: " + field + " | declared type: " + declaredType + " | annotation type: " + annotationType;
        assert declaredType.isAssignableFrom(aAnnotationType) : "Annotation type must be a subtype of the declared type: field: " + field + " | declared type: " + declaredType + " | annotation type: " + annotationType;
        assert aAnnotationType.isArray() || (aAnnotationType.isInstanceClass() && !Modifier.isAbstract(aAnnotationType.getModifiers())) : "Annotation type failure: field: " + field + " | annotation type " + aAnnotationType;
        aAnnotationTypes.add(aAnnotationType);
    }
    return aAnnotationTypes;
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) ArrayList(java.util.ArrayList) WordBase(org.graalvm.word.WordBase)

Example 29 with AnalysisType

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

the class GraalSupport method registerStatistics.

private static <S> void registerStatistics(Map<Class<?>, S> cache, Class<?> phaseClass, Class<S> statisticsClass, Function<Class<?>, S> lookup, DuringAnalysisAccessImpl access) {
    AnalysisType statisticsType = access.getMetaAccess().lookupJavaType(statisticsClass);
    if (!statisticsType.isInstantiated()) {
        /*
             * There is no allocation of statistics objects at runtime, thus their type must be
             * correctly registered as in heap.
             */
        statisticsType.registerAsInHeap();
        access.requireAnalysisIteration();
    }
    for (Class<?> phaseSubClass : access.findSubclasses(phaseClass)) {
        if (Modifier.isAbstract(phaseSubClass.getModifiers()) || phaseSubClass.getName().contains(".hosted.") || phaseSubClass.getName().contains(".hotspot.")) {
            /* Class is abstract or SVM hosted. */
            continue;
        }
        AnalysisType phaseSubClassType = access.getMetaAccess().lookupJavaType(phaseSubClass);
        if (!phaseSubClassType.isInstantiated()) {
            /* The sub class is not instantiated, it doesn't need a statistics object. */
            continue;
        }
        if (cache.containsKey(phaseSubClass)) {
            /* The statistics object for the sub class was already registered. */
            continue;
        }
        cache.put(phaseSubClass, lookup.apply(phaseSubClass));
        access.requireAnalysisIteration();
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType)

Example 30 with AnalysisType

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

the class GraalObjectReplacer method updateSubstrateDataAfterCompilation.

/**
 * Updates all relevant data from universe building. Object replacement is done during analysis.
 * Therefore all substrate VM related data has to be updated after building the substrate
 * universe.
 */
@SuppressWarnings("try")
public void updateSubstrateDataAfterCompilation(HostedUniverse hUniverse) {
    for (Map.Entry<AnalysisType, SubstrateType> entry : types.entrySet()) {
        AnalysisType aType = entry.getKey();
        SubstrateType sType = entry.getValue();
        if (!hUniverse.contains(aType)) {
            continue;
        }
        HostedType hType = hUniverse.lookup(aType);
        DynamicHub uniqueImplementation = null;
        if (hType.getUniqueConcreteImplementation() != null) {
            uniqueImplementation = hType.getUniqueConcreteImplementation().getHub();
        }
        sType.setTypeCheckData(hType.getInstanceOfFromTypeID(), hType.getInstanceOfNumTypeIDs(), uniqueImplementation);
        SubstrateField[] originalFields = sType.getInstanceFields(false);
        if (originalFields != null) {
            /*
                 * What we do here is just a reordering of the instance fields array. The fields
                 * array already contains all the fields, but in the order of the AnalysisType. As
                 * the UniverseBuilder reorders the fields, we re-construct the fields array in the
                 * order of the HostedType. The correct order is essential for materialization
                 * during deoptimization.
                 */
            SubstrateField[] newFields = createFields(hType);
            sType.setInstanceFields(newFields);
        }
    }
    for (Map.Entry<AnalysisField, SubstrateField> entry : fields.entrySet()) {
        AnalysisField aField = entry.getKey();
        SubstrateField sField = entry.getValue();
        HostedField hField = hUniverse.lookup(aField);
        sField.setSubstrateData(hField.getLocation(), hField.isAccessed(), hField.isWritten(), hField.getConstantValue());
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) HostedType(com.oracle.svm.hosted.meta.HostedType) HostedField(com.oracle.svm.hosted.meta.HostedField) DynamicHub(com.oracle.svm.core.hub.DynamicHub) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) SubstrateField(com.oracle.svm.graal.meta.SubstrateField) HashMap(java.util.HashMap) Map(java.util.Map) SubstrateType(com.oracle.svm.graal.meta.SubstrateType)

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