Search in sources :

Example 1 with SVMHost

use of com.oracle.svm.hosted.SVMHost in project graal by oracle.

the class Inflation method fillGenericInfo.

private void fillGenericInfo(AnalysisType type) {
    SVMHost svmHost = (SVMHost) hostVM;
    DynamicHub hub = svmHost.dynamicHub(type);
    Class<?> javaClass = type.getJavaClass();
    TypeVariable<?>[] typeParameters = javaClass.getTypeParameters();
    /* The bounds are lazily initialized. Initialize them eagerly in the native image. */
    Arrays.stream(typeParameters).forEach(TypeVariable::getBounds);
    Type[] genericInterfaces = Arrays.stream(javaClass.getGenericInterfaces()).filter(this::filterGenericInterfaces).toArray(Type[]::new);
    Type[] cachedGenericInterfaces = genericInterfacesMap.computeIfAbsent(new GenericInterfacesEncodingKey(genericInterfaces), k -> genericInterfaces);
    Type genericSuperClass = javaClass.getGenericSuperclass();
    hub.setGenericInfo(GenericInfo.factory(typeParameters, cachedGenericInterfaces, genericSuperClass));
    AnnotatedType annotatedSuperclass = javaClass.getAnnotatedSuperclass();
    AnnotatedType[] annotatedInterfaces = Arrays.stream(javaClass.getAnnotatedInterfaces()).filter(ai -> filterGenericInterfaces(ai.getType())).toArray(AnnotatedType[]::new);
    AnnotatedType[] cachedAnnotatedInterfaces = annotatedInterfacesMap.computeIfAbsent(new AnnotatedInterfacesEncodingKey(annotatedInterfaces), k -> annotatedInterfaces);
    hub.setAnnotatedSuperInfo(AnnotatedSuperInfo.factory(annotatedSuperclass, cachedAnnotatedInterfaces));
}
Also used : HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) DynamicHub(com.oracle.svm.core.hub.DynamicHub) HashMap(java.util.HashMap) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SVMHost(com.oracle.svm.hosted.SVMHost) MethodTypeFlow(com.oracle.graal.pointsto.flow.MethodTypeFlow) JavaKind(jdk.vm.ci.meta.JavaKind) ObjectScanner(com.oracle.graal.pointsto.ObjectScanner) Map(java.util.Map) BigBang(com.oracle.graal.pointsto.BigBang) MethodTypeFlowBuilder(com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder) TypeNotFoundError(com.oracle.graal.pointsto.util.AnalysisError.TypeNotFoundError) GenericInfo(com.oracle.svm.core.hub.GenericInfo) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) UnknownPrimitiveField(com.oracle.svm.core.annotate.UnknownPrimitiveField) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition) OptionValues(org.graalvm.compiler.options.OptionValues) JVMCIError(jdk.vm.ci.common.JVMCIError) SVMMethodTypeFlowBuilder(com.oracle.svm.hosted.analysis.flow.SVMMethodTypeFlowBuilder) TypeVariable(java.lang.reflect.TypeVariable) AnnotatedType(java.lang.reflect.AnnotatedType) Set(java.util.Set) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) JavaConstant(jdk.vm.ci.meta.JavaConstant) List(java.util.List) Type(java.lang.reflect.Type) ForkJoinPool(java.util.concurrent.ForkJoinPool) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) TypeFlow(com.oracle.graal.pointsto.flow.TypeFlow) UnknownObjectField(com.oracle.svm.core.annotate.UnknownObjectField) AnnotatedSuperInfo(com.oracle.svm.core.hub.AnnotatedSuperInfo) JVMCIError.shouldNotReachHere(jdk.vm.ci.common.JVMCIError.shouldNotReachHere) Pattern(java.util.regex.Pattern) HostVM(com.oracle.graal.pointsto.api.HostVM) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) WordBase(org.graalvm.word.WordBase) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AnnotatedType(java.lang.reflect.AnnotatedType) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) Type(java.lang.reflect.Type) AnnotatedType(java.lang.reflect.AnnotatedType) TypeVariable(java.lang.reflect.TypeVariable) SVMHost(com.oracle.svm.hosted.SVMHost) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 2 with SVMHost

use of com.oracle.svm.hosted.SVMHost 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 3 with SVMHost

use of com.oracle.svm.hosted.SVMHost in project graal by oracle.

the class Inflation method scanHub.

private void scanHub(ObjectScanner objectScanner, AnalysisType type) {
    SVMHost svmHost = (SVMHost) hostVM;
    JavaConstant hubConstant = SubstrateObjectConstant.forObject(svmHost.dynamicHub(type));
    objectScanner.scanConstant(hubConstant, "Hub");
}
Also used : SVMHost(com.oracle.svm.hosted.SVMHost) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 4 with SVMHost

use of com.oracle.svm.hosted.SVMHost 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 5 with SVMHost

use of com.oracle.svm.hosted.SVMHost in project graal by oracle.

the class GraalObjectReplacer method createType.

public SubstrateType createType(JavaType original) {
    if (original == null) {
        return null;
    }
    AnalysisType aType;
    if (original instanceof AnalysisType) {
        aType = (AnalysisType) original;
    } else {
        aType = ((HostedType) original).getWrapped();
    }
    SubstrateType sType = types.get(aType);
    if (sType == null) {
        assert !(original instanceof HostedType) : "too late to create new type";
        DynamicHub hub = ((SVMHost) aUniverse.hostVM()).dynamicHub(aType);
        sType = new SubstrateType(aType.getJavaKind(), hub);
        types.put(aType, sType);
        hub.setMetaType(sType);
        sType.setInstanceFields(createFields(aType));
        createType(aType.getSuperclass());
        createType(aType.getComponentType());
        for (AnalysisType aInterface : aType.getInterfaces()) {
            createType(aInterface);
        }
    }
    return sType;
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) HostedType(com.oracle.svm.hosted.meta.HostedType) SVMHost(com.oracle.svm.hosted.SVMHost) DynamicHub(com.oracle.svm.core.hub.DynamicHub) SubstrateType(com.oracle.svm.graal.meta.SubstrateType)

Aggregations

SVMHost (com.oracle.svm.hosted.SVMHost)5 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)4 DynamicHub (com.oracle.svm.core.hub.DynamicHub)3 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)2 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 BigBang (com.oracle.graal.pointsto.BigBang)1 ObjectScanner (com.oracle.graal.pointsto.ObjectScanner)1 HostVM (com.oracle.graal.pointsto.api.HostVM)1 MethodTypeFlow (com.oracle.graal.pointsto.flow.MethodTypeFlow)1 MethodTypeFlowBuilder (com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder)1 TypeFlow (com.oracle.graal.pointsto.flow.TypeFlow)1 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)1 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)1 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 TypeNotFoundError (com.oracle.graal.pointsto.util.AnalysisError.TypeNotFoundError)1 UnknownObjectField (com.oracle.svm.core.annotate.UnknownObjectField)1 UnknownPrimitiveField (com.oracle.svm.core.annotate.UnknownPrimitiveField)1 AnnotatedSuperInfo (com.oracle.svm.core.hub.AnnotatedSuperInfo)1