Search in sources :

Example 6 with AnalysisType

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

the class ObjectTreePrinter method suppressType.

private boolean suppressType(AnalysisType type) {
    AnalysisType elementalType = (AnalysisType) type.getElementalType();
    String elementalTypeName = elementalType.toJavaName(true);
    if (expandTypeMatcher.matches(elementalTypeName)) {
        return false;
    }
    if (suppressTypeMatcher.matches(elementalTypeName)) {
        return true;
    }
    if (defaultSuppressTypeMatcher.matches(elementalTypeName)) {
        return true;
    }
    return false;
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType)

Example 7 with AnalysisType

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

the class PointsToStats method formatSource.

private static String formatSource(TypeFlow<?> flow) {
    Object source = flow.getSource();
    if (source instanceof ValueNode) {
        ValueNode node = (ValueNode) source;
        NodeSourcePosition nodeSource = node.getNodeSourcePosition();
        if (nodeSource != null) {
            return formatMethod(nodeSource.getMethod()) + ":" + nodeSource.getBCI();
        } else if (flow.graphRef() != null) {
            return formatMethod(flow.graphRef().getMethod());
        } else {
            return "<unknown-source>";
        }
    } else if (source instanceof AnalysisType) {
        return formatType((AnalysisType) source);
    } else if (source instanceof AnalysisField) {
        return formatField((AnalysisField) source);
    } else if (source == null) {
        return "<no-source>";
    } else {
        return source.getClass().getSimpleName();
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) ValueNode(org.graalvm.compiler.nodes.ValueNode) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Example 8 with AnalysisType

use of com.oracle.graal.pointsto.meta.AnalysisType 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 9 with AnalysisType

use of com.oracle.graal.pointsto.meta.AnalysisType 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 10 with AnalysisType

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

the class AnnotationTypeFeature method duringAnalysis.

@Override
public void duringAnalysis(DuringAnalysisAccess access) {
    DuringAnalysisAccessImpl accessImpl = (DuringAnalysisAccessImpl) access;
    AnalysisUniverse universe = accessImpl.getUniverse();
    /*
         * JDK implementation of repeatable annotations always instantiates an array of a requested
         * annotation. We need to mark arrays of all reachable annotations as in heap.
         */
    universe.getTypes().stream().filter(AnalysisType::isAnnotation).filter(AnalysisType::isInTypeCheck).map(type -> universe.lookup(type.getWrapped()).getArrayClass()).filter(annotationArray -> !annotationArray.isInstantiated()).forEach(annotationArray -> {
        accessImpl.registerAsInHeap(annotationArray);
        access.requireAnalysisIteration();
    });
    Stream<AnnotatedElement> allElements = Stream.concat(Stream.concat(universe.getFields().stream(), universe.getMethods().stream()), universe.getTypes().stream());
    Stream<AnnotatedElement> newElements = allElements.filter(visitedElements::add);
    newElements.forEach(this::reportAnnotation);
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) ImageSingletons(org.graalvm.nativeimage.ImageSingletons) Feature(org.graalvm.nativeimage.Feature) AutomaticFeature(com.oracle.svm.core.annotate.AutomaticFeature) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) DuringAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl) EconomicSet(org.graalvm.collections.EconomicSet) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) AnnotationTypeSupport(com.oracle.svm.core.hub.AnnotationTypeSupport) Objects(java.util.Objects) Stream(java.util.stream.Stream) Repeatable(java.lang.annotation.Repeatable) AfterRegistrationAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterRegistrationAccessImpl) Annotation(java.lang.annotation.Annotation) AnnotatedElement(java.lang.reflect.AnnotatedElement) AnnotatedElement(java.lang.reflect.AnnotatedElement) DuringAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse)

Aggregations

AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)38 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)10 TypeState (com.oracle.graal.pointsto.typestate.TypeState)7 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)6 AnalysisObject (com.oracle.graal.pointsto.flow.context.object.AnalysisObject)5 DynamicHub (com.oracle.svm.core.hub.DynamicHub)5 ArrayList (java.util.ArrayList)5 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)4 SVMHost (com.oracle.svm.hosted.SVMHost)4 JavaKind (jdk.vm.ci.meta.JavaKind)4 Indent (org.graalvm.compiler.debug.Indent)4 MethodTypeFlow (com.oracle.graal.pointsto.flow.MethodTypeFlow)3 BytecodeLocation (com.oracle.graal.pointsto.flow.context.BytecodeLocation)3 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)3 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)3 DuringAnalysisAccessImpl (com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl)3 HostedType (com.oracle.svm.hosted.meta.HostedType)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 BigBang (com.oracle.graal.pointsto.BigBang)2 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2