Search in sources :

Example 6 with AnalysisField

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

the class Inflation method checkType.

private void checkType(AnalysisType type) {
    SVMHost svmHost = (SVMHost) hostVM;
    if (type.getJavaKind() == JavaKind.Object) {
        if (type.isArray() && (type.isInstantiated() || type.isInTypeCheck())) {
            svmHost.dynamicHub(type).getComponentHub().setArrayHub(svmHost.dynamicHub(type));
        }
        try {
            AnalysisType enclosingType = type.getEnclosingType();
            if (enclosingType != null) {
                svmHost.dynamicHub(type).setEnclosingClass(svmHost.dynamicHub(enclosingType));
            }
        } catch (UnsupportedFeatureException ex) {
            getUnsupportedFeatures().addMessage(type.toJavaName(true), null, ex.getMessage(), null, ex);
        }
        fillGenericInfo(type);
        fillInterfaces(type);
        /*
             * Support for Java annotations.
             */
        svmHost.dynamicHub(type).setAnnotationsEncoding(encodeAnnotations(metaAccess, type.getAnnotations(), svmHost.dynamicHub(type).getAnnotationsEncoding()));
        /*
             * Support for Java enumerations.
             */
        if (type.getSuperclass() != null && type.getSuperclass().equals(metaAccess.lookupJavaType(Enum.class)) && svmHost.dynamicHub(type).getEnumConstantsShared() == null) {
            /*
                 * We want to retrieve the enum constant array that is maintained as a private
                 * static field in the enumeration class. We do not want a copy because that would
                 * mean we have the array twice in the native image: as the static field, and in the
                 * enumConstant field of DynamicHub. The only way to get the original value is via a
                 * reflective field access, and we even have to guess the field name.
                 */
            AnalysisField found = null;
            for (AnalysisField f : type.getStaticFields()) {
                if (f.getName().endsWith("$VALUES")) {
                    if (found != null) {
                        throw shouldNotReachHere("Enumeration has more than one static field with enumeration values: " + type);
                    }
                    found = f;
                }
            }
            if (found == null) {
                throw shouldNotReachHere("Enumeration does not have static field with enumeration values: " + type);
            }
            AnalysisField field = found;
            // field.registerAsRead(null);
            Enum<?>[] enumConstants = (Enum[]) SubstrateObjectConstant.asObject(getConstantReflectionProvider().readFieldValue(field, null));
            assert enumConstants != null;
            svmHost.dynamicHub(type).setEnumConstants(enumConstants);
        }
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) SVMHost(com.oracle.svm.hosted.SVMHost) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField)

Example 7 with AnalysisField

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

the class JNIAccessFeature method addField.

private static void addField(Field reflField, DuringAnalysisAccessImpl access) {
    BigBang bigBang = access.getBigBang();
    JNIAccessibleClass jniClass = addClass(reflField.getDeclaringClass(), access);
    jniClass.addFieldIfAbsent(reflField.getName(), n -> {
        AnalysisField field = access.getMetaAccess().lookupJavaField(reflField);
        field.registerAsAccessed();
        // Same as BigBang.addSystemField() and BigBang.addSystemStaticField():
        // create type flows for any subtype of the field's declared type
        TypeFlow<?> declaredTypeFlow = field.getType().getTypeFlow(bigBang, true);
        if (field.isStatic()) {
            declaredTypeFlow.addUse(bigBang, field.getStaticFieldFlow());
        } else {
            FieldTypeFlow instanceFieldFlow = field.getDeclaringClass().getContextInsensitiveAnalysisObject().getInstanceFieldFlow(bigBang, field, true);
            declaredTypeFlow.addUse(bigBang, instanceFieldFlow);
        }
        return new JNIAccessibleField(jniClass, reflField.getName(), field.getJavaKind(), field.getModifiers());
    });
}
Also used : FieldTypeFlow(com.oracle.graal.pointsto.flow.FieldTypeFlow) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) BigBang(com.oracle.graal.pointsto.BigBang)

Example 8 with AnalysisField

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

the class AnnotationSubstitutionProcessor method processComputedValueFields.

/**
 * Eagerly register all target fields of recomputed value fields as unsafe accessed.
 */
public void processComputedValueFields(BigBang bb) {
    for (ResolvedJavaField field : fieldSubstitutions.values()) {
        if (field instanceof ComputedValue) {
            ComputedValue cvField = (ComputedValue) field;
            switch(cvField.getRecomputeValueKind()) {
                case FieldOffset:
                    AnalysisField targetField = bb.getMetaAccess().lookupJavaField(cvField.getTargetField());
                    targetField.registerAsAccessed();
                    targetField.registerAsUnsafeAccessed();
                    break;
            }
        }
    }
}
Also used : AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 9 with AnalysisField

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

the class ComputedValueField method processAnalysis.

public void processAnalysis(AnalysisMetaAccess aMetaAccess) {
    switch(kind) {
        case FieldOffset:
            AnalysisField target = aMetaAccess.lookupJavaField(targetField);
            target.registerAsAccessed();
            break;
    }
}
Also used : AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField)

Example 10 with AnalysisField

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

the class UniverseBuilder method build.

/**
 * This step is single threaded, i.e., all the maps are modified only by a single thread, so no
 * synchronization is necessary. Accesses (the lookup methods) are multi-threaded.
 */
@SuppressWarnings("try")
public void build(DebugContext debug) {
    for (AnalysisField aField : aUniverse.getFields()) {
        if (aField.wrapped instanceof ComputedValueField) {
            ((ComputedValueField) aField.wrapped).processAnalysis(aMetaAccess);
        }
    }
    aUniverse.seal();
    try (Indent indent = debug.logAndIndent("build universe")) {
        for (AnalysisType aType : aUniverse.getTypes()) {
            makeType(aType);
        }
        for (AnalysisField aField : aUniverse.getFields()) {
            makeField(aField);
        }
        for (AnalysisMethod aMethod : aUniverse.getMethods()) {
            makeMethod(aMethod);
        }
        BigBang bb = staticAnalysisResultsBuilder.getBigBang();
        ForkJoinTask<?> profilingInformationBuildTask = ForkJoinTask.adapt(this::buildProfilingInformation).fork();
        buildSubTypes();
        buildOrderedTypes();
        buildTypeCheckIDs();
        collectDeclaredMethods();
        collectMonitorFieldInfo(bb);
        collectHashCodeFieldInfo(bb);
        layoutInstanceFields();
        layoutStaticFields();
        collectMethodImplementations();
        buildVTables();
        buildHubs();
        setConstantFieldValues();
        hUniverse.orderedMethods = new ArrayList<>(hUniverse.methods.values());
        Collections.sort(hUniverse.orderedMethods);
        hUniverse.orderedFields = new ArrayList<>(hUniverse.fields.values());
        Collections.sort(hUniverse.orderedFields);
        profilingInformationBuildTask.join();
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) Indent(org.graalvm.compiler.debug.Indent) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) ComputedValueField(com.oracle.svm.hosted.substitute.ComputedValueField) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) BigBang(com.oracle.graal.pointsto.BigBang)

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