Search in sources :

Example 11 with HostedField

use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.

the class NativeImageGenerator method printTypes.

private void printTypes() {
    for (HostedType type : hUniverse.getTypes()) {
        System.out.format("%8d %s  ", type.getTypeID(), type.toJavaName(true));
        if (type.getSuperclass() != null) {
            System.out.format("extends %d %s  ", type.getSuperclass().getTypeID(), type.getSuperclass().toJavaName(false));
        }
        if (type.getInterfaces().length > 0) {
            System.out.print("implements ");
            String sep = "";
            for (HostedInterface interf : type.getInterfaces()) {
                System.out.format("%s%d %s", sep, interf.getTypeID(), interf.toJavaName(false));
                sep = ", ";
            }
            System.out.print("  ");
        }
        if (type.getWrapped().isInstantiated()) {
            System.out.print("instantiated  ");
        }
        if (type.getWrapped().isInTypeCheck()) {
            System.out.print("inTypeCheck  ");
        }
        System.out.format("assignableFrom %s  ", matchesToString(type.getAssignableFromMatches()));
        System.out.format("instanceOf typeID %d, # %d  ", type.getInstanceOfFromTypeID(), type.getInstanceOfNumTypeIDs());
        // if (type.findLeafConcreteSubtype() != null) {
        // System.out.format("unique %d %s ", type.findLeafConcreteSubtype().getTypeID(),
        // type.findLeafConcreteSubtype().toJavaName(false));
        // }
        int le = type.getHub().getLayoutEncoding();
        if (LayoutEncoding.isPrimitive(le)) {
            System.out.print("primitive  ");
        } else if (LayoutEncoding.isInterface(le)) {
            System.out.print("interface  ");
        } else if (LayoutEncoding.isAbstract(le)) {
            System.out.print("abstract  ");
        } else if (LayoutEncoding.isInstance(le)) {
            System.out.format("instance size %d  ", LayoutEncoding.getInstanceSize(le).rawValue());
        } else if (LayoutEncoding.isObjectArray(le)) {
            System.out.format("object array base %d shift %d scale %d  ", LayoutEncoding.getArrayBaseOffset(le).rawValue(), LayoutEncoding.getArrayIndexShift(le), LayoutEncoding.getArrayIndexScale(le));
        } else if (LayoutEncoding.isPrimitiveArray(le)) {
            System.out.format("primitive array base %d shift %d scale %d  ", LayoutEncoding.getArrayBaseOffset(le).rawValue(), LayoutEncoding.getArrayIndexShift(le), LayoutEncoding.getArrayIndexScale(le));
        } else {
            throw VMError.shouldNotReachHere();
        }
        System.out.println();
        for (HostedType sub : type.getSubTypes()) {
            System.out.format("               s %d %s\n", sub.getTypeID(), sub.toJavaName(false));
        }
        if (type.isInterface()) {
            for (HostedMethod method : hUniverse.getMethods()) {
                if (method.getDeclaringClass() == type) {
                    printMethod(method, -1);
                }
            }
        } else if (type.isInstanceClass()) {
            HostedField[] fields = type.getInstanceFields(false);
            fields = Arrays.copyOf(fields, fields.length);
            Arrays.sort(fields, Comparator.comparing(HostedField::toString));
            for (HostedField field : fields) {
                System.out.println("               f " + field.getLocation() + ": " + field.format("%T %n"));
            }
            HostedMethod[] vtable = type.getVTable();
            for (int i = 0; i < vtable.length; i++) {
                if (vtable[i] != null) {
                    printMethod(vtable[i], i);
                }
            }
            for (HostedMethod method : hUniverse.getMethods()) {
                if (method.getDeclaringClass() == type && !method.hasVTableIndex()) {
                    printMethod(method, -1);
                }
            }
        }
    }
}
Also used : HostedType(com.oracle.svm.hosted.meta.HostedType) HostedField(com.oracle.svm.hosted.meta.HostedField) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) HostedInterface(com.oracle.svm.hosted.meta.HostedInterface)

Example 12 with HostedField

use of com.oracle.svm.hosted.meta.HostedField 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 13 with HostedField

use of com.oracle.svm.hosted.meta.HostedField 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

HostedField (com.oracle.svm.hosted.meta.HostedField)13 HostedType (com.oracle.svm.hosted.meta.HostedType)4 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)3 JavaKind (jdk.vm.ci.meta.JavaKind)3 DynamicHub (com.oracle.svm.core.hub.DynamicHub)2 SubstrateField (com.oracle.svm.graal.meta.SubstrateField)2 HostedArrayClass (com.oracle.svm.hosted.meta.HostedArrayClass)2 HostedInstanceClass (com.oracle.svm.hosted.meta.HostedInstanceClass)2 Field (java.lang.reflect.Field)2 BitSet (java.util.BitSet)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)1 NativeImageInfo (com.oracle.svm.core.heap.NativeImageInfo)1 StringInternSupport (com.oracle.svm.core.jdk.StringInternSupport)1 ReadableJavaField (com.oracle.svm.core.meta.ReadableJavaField)1 SubstrateType (com.oracle.svm.graal.meta.SubstrateType)1 HybridLayout (com.oracle.svm.hosted.config.HybridLayout)1 HostedClass (com.oracle.svm.hosted.meta.HostedClass)1 HostedInterface (com.oracle.svm.hosted.meta.HostedInterface)1