Search in sources :

Example 1 with SubstrateField

use of com.oracle.svm.graal.meta.SubstrateField in project graal by oracle.

the class GraalObjectReplacer method registerImmutableObjects.

public void registerImmutableObjects(CompilationAccess access) {
    for (SubstrateMethod method : methods.values()) {
        access.registerAsImmutable(method);
        access.registerAsImmutable(method.getRawImplementations());
        access.registerAsImmutable(method.getEncodedLineNumberTable());
    }
    for (SubstrateField field : fields.values()) {
        access.registerAsImmutable(field);
    }
    for (FieldLocationIdentity fieldLocationIdentity : fieldLocationIdentities.values()) {
        access.registerAsImmutable(fieldLocationIdentity);
    }
    for (SubstrateType type : types.values()) {
        access.registerAsImmutable(type);
        access.registerAsImmutable(type.getRawInstanceFields());
    }
    for (SubstrateSignature signature : signatures.values()) {
        access.registerAsImmutable(signature);
        access.registerAsImmutable(signature.getRawParameterTypes());
    }
}
Also used : SubstrateMethod(com.oracle.svm.graal.meta.SubstrateMethod) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) SubstrateFieldLocationIdentity(com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity) SubstrateField(com.oracle.svm.graal.meta.SubstrateField) SubstrateType(com.oracle.svm.graal.meta.SubstrateType) SubstrateSignature(com.oracle.svm.graal.meta.SubstrateSignature)

Example 2 with SubstrateField

use of com.oracle.svm.graal.meta.SubstrateField 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 3 with SubstrateField

use of com.oracle.svm.graal.meta.SubstrateField 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 4 with SubstrateField

use of com.oracle.svm.graal.meta.SubstrateField in project graal by oracle.

the class GraalObjectReplacer method apply.

@Override
public Object apply(Object source) {
    if (source == null) {
        return null;
    }
    Object dest = source;
    if (source instanceof RelocatedPointer) {
        return dest;
    }
    if (source instanceof MetaAccessProvider) {
        dest = sMetaAccess;
    } else if (source instanceof GraalRuntime) {
        dest = sGraalRuntime;
    } else if (source instanceof AnalysisConstantReflectionProvider) {
        dest = sConstantReflectionProvider;
    } else if (source instanceof AnalysisConstantFieldProvider) {
        dest = sConstantFieldProvider;
    } else if (source instanceof ForeignCallsProvider) {
        dest = GraalSupport.getRuntimeConfig().getProviders().getForeignCalls();
    } else if (source instanceof HostedSnippetReflectionProvider) {
        dest = GraalSupport.getRuntimeConfig().getSnippetReflection();
    } else if (shouldBeReplaced(source)) {
        /*
             * The hash maps must be synchronized, because replace() may be called from
             * BigBang.finish(), which is multi-threaded.
             */
        synchronized (this) {
            if (source instanceof ResolvedJavaMethod) {
                dest = createMethod((ResolvedJavaMethod) source);
            } else if (source instanceof ResolvedJavaField) {
                dest = createField((ResolvedJavaField) source);
            } else if (source instanceof ResolvedJavaType) {
                dest = createType((ResolvedJavaType) source);
            } else if (source instanceof Signature) {
                dest = createSignature((Signature) source);
            } else if (source instanceof FieldLocationIdentity) {
                dest = fieldLocationIdentities.get(source);
                if (dest == null) {
                    SubstrateField destField = (SubstrateField) apply(((FieldLocationIdentity) source).getField());
                    dest = new SubstrateFieldLocationIdentity(destField);
                    fieldLocationIdentities.put((FieldLocationIdentity) source, (FieldLocationIdentity) dest);
                }
            }
        }
    }
    assert dest != null;
    String className = dest.getClass().getName();
    assert !className.contains(".hotspot.") || className.contains(".svm.jtt.hotspot.") : "HotSpot object in image " + className;
    assert !className.contains(".analysis.meta.") : "Analysis meta object in image " + className;
    assert !className.contains(".hosted.meta.") : "Hosted meta object in image " + className;
    return dest;
}
Also used : ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) AnalysisConstantReflectionProvider(com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider) AnalysisConstantFieldProvider(com.oracle.svm.hosted.ameta.AnalysisConstantFieldProvider) RelocatedPointer(org.graalvm.nativeimage.c.function.RelocatedPointer) SubstrateField(com.oracle.svm.graal.meta.SubstrateField) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) HostedSnippetReflectionProvider(com.oracle.svm.hosted.meta.HostedSnippetReflectionProvider) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) GraalRuntime(org.graalvm.compiler.api.runtime.GraalRuntime) SubstrateGraalRuntime(com.oracle.svm.graal.SubstrateGraalRuntime) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) SubstrateFieldLocationIdentity(com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity) SubstrateFieldLocationIdentity(com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity) Signature(jdk.vm.ci.meta.Signature) SubstrateSignature(com.oracle.svm.graal.meta.SubstrateSignature) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 5 with SubstrateField

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

Aggregations

SubstrateField (com.oracle.svm.graal.meta.SubstrateField)5 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)3 SubstrateFieldLocationIdentity (com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity)2 SubstrateMethod (com.oracle.svm.graal.meta.SubstrateMethod)2 SubstrateSignature (com.oracle.svm.graal.meta.SubstrateSignature)2 SubstrateType (com.oracle.svm.graal.meta.SubstrateType)2 HostedField (com.oracle.svm.hosted.meta.HostedField)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)2 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 DynamicHub (com.oracle.svm.core.hub.DynamicHub)1 SubstrateGraalRuntime (com.oracle.svm.graal.SubstrateGraalRuntime)1 AnalysisConstantFieldProvider (com.oracle.svm.hosted.ameta.AnalysisConstantFieldProvider)1 AnalysisConstantReflectionProvider (com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider)1 HostedSnippetReflectionProvider (com.oracle.svm.hosted.meta.HostedSnippetReflectionProvider)1 HostedType (com.oracle.svm.hosted.meta.HostedType)1 ArrayList (java.util.ArrayList)1 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1