Search in sources :

Example 16 with AnalysisField

use of com.oracle.graal.pointsto.meta.AnalysisField 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)

Example 17 with AnalysisField

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

the class GraalObjectReplacer method updateDataDuringAnalysis.

/**
 * Some meta data must be updated during analysis. This is done here.
 */
public boolean updateDataDuringAnalysis(AnalysisMetaAccess metaAccess) {
    boolean result = false;
    List<AnalysisMethod> aMethods = new ArrayList<>();
    aMethods.addAll(methods.keySet());
    int index = 0;
    while (index < aMethods.size()) {
        AnalysisMethod aMethod = aMethods.get(index++);
        SubstrateMethod sMethod = methods.get(aMethod);
        SubstrateMethod[] implementations = new SubstrateMethod[aMethod.getImplementations().length];
        int idx = 0;
        for (AnalysisMethod impl : aMethod.getImplementations()) {
            SubstrateMethod sImpl = methods.get(impl);
            if (sImpl == null) {
                sImpl = createMethod(impl);
                aMethods.add(impl);
                result = true;
            }
            implementations[idx++] = sImpl;
        }
        if (sMethod.setImplementations(implementations)) {
            result = true;
        }
    }
    for (Map.Entry<AnalysisMethod, SubstrateMethod> entry : methods.entrySet()) {
        if (entry.getValue().setAnnotationsEncoding(Inflation.encodeAnnotations(metaAccess, entry.getKey().getAnnotations(), entry.getValue().getAnnotationsEncoding()))) {
            result = true;
        }
    }
    for (Map.Entry<AnalysisField, SubstrateField> entry : fields.entrySet()) {
        if (entry.getValue().setAnnotationsEncoding(Inflation.encodeAnnotations(metaAccess, entry.getKey().getAnnotations(), entry.getValue().getAnnotationsEncoding()))) {
            result = true;
        }
    }
    return result;
}
Also used : SubstrateMethod(com.oracle.svm.graal.meta.SubstrateMethod) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) ArrayList(java.util.ArrayList) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) SubstrateField(com.oracle.svm.graal.meta.SubstrateField) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with AnalysisField

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

the class GraalObjectReplacer method createField.

public SubstrateField createField(ResolvedJavaField original) {
    AnalysisField aField;
    if (original instanceof AnalysisField) {
        aField = (AnalysisField) original;
    } else {
        aField = ((HostedField) original).wrapped;
    }
    SubstrateField sField = fields.get(aField);
    if (sField == null) {
        assert !(original instanceof HostedField) : "too late to create new field";
        int modifiers = aField.getModifiers();
        if (ReadableJavaField.injectFinalForRuntimeCompilation(aField.wrapped)) {
            modifiers = modifiers | Modifier.FINAL;
        }
        sField = new SubstrateField(aMetaAccess, aField, modifiers, stringTable);
        fields.put(aField, sField);
        sField.setLinks(createType(aField.getType()), createType(aField.getDeclaringClass()));
        /*
             * Annotations are updated in every analysis iteration, but this is a starting point. It
             * also ensures that all types used by annotations are created eagerly.
             */
        sField.setAnnotationsEncoding(Inflation.encodeAnnotations(aMetaAccess, aField.getAnnotations(), null));
    }
    return sField;
}
Also used : HostedField(com.oracle.svm.hosted.meta.HostedField) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) SubstrateField(com.oracle.svm.graal.meta.SubstrateField)

Example 19 with AnalysisField

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

the class SVMMethodTypeFlowBuilder method checkUnsafeOffset.

@Override
protected void checkUnsafeOffset(ValueNode offsetNode) {
    if (!NativeImageOptions.ThrowUnsafeOffsetErrors.getValue()) {
        /* Skip the checks bellow. */
        return;
    }
    if (offsetNode instanceof LoadFieldNode) {
        LoadFieldNode offsetLoadNode = (LoadFieldNode) offsetNode;
        AnalysisField field = (AnalysisField) offsetLoadNode.field();
        if (!(field.wrapped instanceof ComputedValueField)) {
            UnsafeOffsetError.report("Field " + field + " is used as an offset in an unsafe operation, but no value recomputation found. \n Wrapped field: " + field.wrapped);
        }
    } else if (NativeImageOptions.ReportUnsafeOffsetWarnings.getValue()) {
        String message = "Offset used in an unsafe operation. Cannot determine if the offset value is recomputed.";
        message += "Location: " + offsetNode.getNodeSourcePosition() + "\n";
        message += "Node class: " + offsetNode.getClass().getName() + "\n";
        if (NativeImageOptions.UnsafeOffsetWarningsAreFatal.getValue()) {
            UnsafeOffsetError.report(message);
        } else {
            System.out.println(message);
        }
    }
}
Also used : ComputedValueField(com.oracle.svm.hosted.substitute.ComputedValueField) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode)

Example 20 with AnalysisField

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

the class BigBang method addSystemField.

@SuppressWarnings("try")
public AnalysisType addSystemField(Class<?> clazz, String fieldName) {
    AnalysisType type = addSystemClass(clazz, false, false);
    for (AnalysisField field : type.getInstanceFields(true)) {
        if (field.getName().equals(fieldName)) {
            try (Indent indent = debug.logAndIndent("add system field %s in class %s", fieldName, clazz.getName())) {
                field.registerAsAccessed();
                /*
                     * For system classes any instantiated (sub)type of the declared field type can
                     * be written to the field flow.
                     */
                TypeFlow<?> fieldDeclaredTypeFlow = field.getType().getTypeFlow(this, true);
                fieldDeclaredTypeFlow.addUse(this, type.getContextInsensitiveAnalysisObject().getInstanceFieldFlow(this, field, true));
            }
            return field.getType();
        }
    }
    throw shouldNotReachHere("field not found: " + fieldName);
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) Indent(org.graalvm.compiler.debug.Indent) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField)

Aggregations

AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)21 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)9 Indent (org.graalvm.compiler.debug.Indent)4 FieldTypeFlow (com.oracle.graal.pointsto.flow.FieldTypeFlow)3 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)3 SubstrateField (com.oracle.svm.graal.meta.SubstrateField)3 BigBang (com.oracle.graal.pointsto.BigBang)2 HostedField (com.oracle.svm.hosted.meta.HostedField)2 ComputedValueField (com.oracle.svm.hosted.substitute.ComputedValueField)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)2 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)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