Search in sources :

Example 1 with NativeImagePointsToAnalysis

use of com.oracle.svm.hosted.analysis.NativeImagePointsToAnalysis in project graal by oracle.

the class NativeImageGenerator method createBigBang.

public static Inflation createBigBang(OptionValues options, TargetDescription target, AnalysisUniverse aUniverse, ForkJoinPool analysisExecutor, Runnable heartbeatCallback, AnalysisMetaAccess aMetaAccess, AnalysisConstantReflectionProvider aConstantReflection, WordTypes aWordTypes, SnippetReflectionProvider aSnippetReflection, AnnotationSubstitutionProcessor annotationSubstitutionProcessor, ForeignCallsProvider aForeignCalls, ClassInitializationSupport classInitializationSupport, Providers originalProviders) {
    assert aUniverse != null : "Analysis universe must be initialized.";
    aMetaAccess.lookupJavaType(String.class).registerAsReachable();
    AnalysisConstantFieldProvider aConstantFieldProvider = new AnalysisConstantFieldProvider(aUniverse, aMetaAccess, aConstantReflection, classInitializationSupport);
    /*
         * Install all snippets so that the types, methods, and fields used in the snippets get
         * added to the universe.
         */
    aMetaAccess.lookupJavaType(Reference.class).registerAsReachable();
    BarrierSet barrierSet = ImageSingletons.lookup(Heap.class).createBarrierSet(aMetaAccess);
    SubstratePlatformConfigurationProvider platformConfig = new SubstratePlatformConfigurationProvider(barrierSet);
    AnalysisMetaAccessExtensionProvider aMetaAccessExtensionProvider = new AnalysisMetaAccessExtensionProvider();
    LoweringProvider aLoweringProvider = SubstrateLoweringProvider.createForHosted(aMetaAccess, null, platformConfig, aMetaAccessExtensionProvider);
    StampProvider aStampProvider = new SubstrateStampProvider(aMetaAccess);
    HostedProviders aProviders = new HostedProviders(aMetaAccess, null, aConstantReflection, aConstantFieldProvider, aForeignCalls, aLoweringProvider, null, aStampProvider, aSnippetReflection, aWordTypes, platformConfig, aMetaAccessExtensionProvider, originalProviders.getLoopsDataProvider());
    BytecodeProvider bytecodeProvider = new ResolvedJavaMethodBytecodeProvider();
    SubstrateReplacements aReplacments = new SubstrateReplacements(aProviders, aSnippetReflection, bytecodeProvider, target, aWordTypes, new SubstrateGraphMakerFactory(aWordTypes));
    aProviders = new HostedProviders(aMetaAccess, null, aConstantReflection, aConstantFieldProvider, aForeignCalls, aLoweringProvider, aReplacments, aStampProvider, aSnippetReflection, aWordTypes, platformConfig, aMetaAccessExtensionProvider, originalProviders.getLoopsDataProvider());
    return new NativeImagePointsToAnalysis(options, aUniverse, aProviders, annotationSubstitutionProcessor, analysisExecutor, heartbeatCallback, new SubstrateUnsupportedFeatures(), ImageSingletons.lookup(TimerCollection.class));
}
Also used : SubstratePlatformConfigurationProvider(com.oracle.svm.core.graal.code.SubstratePlatformConfigurationProvider) AnalysisConstantFieldProvider(com.oracle.svm.hosted.ameta.AnalysisConstantFieldProvider) SubstrateStampProvider(com.oracle.svm.core.graal.meta.SubstrateStampProvider) StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) Reference(java.lang.ref.Reference) AnalysisMetaAccessExtensionProvider(com.oracle.graal.pointsto.meta.AnalysisMetaAccessExtensionProvider) BytecodeProvider(org.graalvm.compiler.bytecode.BytecodeProvider) ResolvedJavaMethodBytecodeProvider(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecodeProvider) SubstrateLoweringProvider(com.oracle.svm.core.graal.meta.SubstrateLoweringProvider) NodeLoweringProvider(com.oracle.svm.core.graal.snippets.NodeLoweringProvider) LoweringProvider(org.graalvm.compiler.nodes.spi.LoweringProvider) SubstrateGraphMakerFactory(com.oracle.svm.hosted.code.SubstrateGraphMakerFactory) NativeImageHeap(com.oracle.svm.hosted.image.NativeImageHeap) ImageHeap(com.oracle.graal.pointsto.heap.ImageHeap) Heap(com.oracle.svm.core.heap.Heap) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) BarrierSet(org.graalvm.compiler.nodes.gc.BarrierSet) SubstrateUnsupportedFeatures(com.oracle.svm.hosted.analysis.SubstrateUnsupportedFeatures) SubstrateReplacements(com.oracle.svm.core.graal.meta.SubstrateReplacements) TimerCollection(com.oracle.graal.pointsto.util.TimerCollection) SubstrateStampProvider(com.oracle.svm.core.graal.meta.SubstrateStampProvider) NativeImagePointsToAnalysis(com.oracle.svm.hosted.analysis.NativeImagePointsToAnalysis) ResolvedJavaMethodBytecodeProvider(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecodeProvider)

Example 2 with NativeImagePointsToAnalysis

use of com.oracle.svm.hosted.analysis.NativeImagePointsToAnalysis in project graal by oracle.

the class NativeImageGenerator method checkUniverse.

private void checkUniverse() {
    if (bb instanceof NativeImagePointsToAnalysis) {
        NativeImagePointsToAnalysis bigbang = (NativeImagePointsToAnalysis) this.bb;
        /*
             * Check that the type states for method parameters and fields are compatible with the
             * declared type. This is required for interface types because interfaces are not
             * trusted according to the Java language specification, but we trust all interface
             * types (see HostedType.isTrustedInterfaceType)
             *
             * TODO Enable checks for non-interface types too.
             */
        for (AnalysisMethod m : aUniverse.getMethods()) {
            PointsToAnalysisMethod method = PointsToAnalysis.assertPointsToAnalysisMethod(m);
            for (int i = 0; i < method.getTypeFlow().getOriginalMethodFlows().getParameters().length; i++) {
                TypeState parameterState = method.getTypeFlow().getParameterTypeState(bigbang, i);
                if (parameterState != null) {
                    AnalysisType declaredType = method.getTypeFlow().getOriginalMethodFlows().getParameter(i).getDeclaredType();
                    if (declaredType.isInterface()) {
                        TypeState declaredTypeState = declaredType.getAssignableTypes(true);
                        parameterState = TypeState.forSubtraction(bigbang, parameterState, declaredTypeState);
                        if (!parameterState.isEmpty()) {
                            String methodKey = method.format("%H.%n(%p)");
                            bigbang.getUnsupportedFeatures().addMessage(methodKey, method, "Parameter " + i + " of " + methodKey + " has declared type " + declaredType.toJavaName(true) + ", with assignable types: " + format(bb, declaredTypeState) + ", which is incompatible with analysis inferred types: " + format(bb, parameterState) + ".");
                        }
                    }
                }
            }
        }
        for (AnalysisField field : aUniverse.getFields()) {
            TypeState state = field.getTypeState();
            if (state != null) {
                AnalysisType declaredType = field.getType();
                if (declaredType.isInterface()) {
                    TypeState declaredTypeState = declaredType.getAssignableTypes(true);
                    state = TypeState.forSubtraction(bigbang, state, declaredTypeState);
                    if (!state.isEmpty()) {
                        String fieldKey = field.format("%H.%n");
                        bigbang.getUnsupportedFeatures().addMessage(fieldKey, null, "Field " + fieldKey + " has declared type " + declaredType.toJavaName(true) + ", with assignable types: " + format(bb, declaredTypeState) + ", which is incompatible with analysis inferred types: " + format(bb, state) + ".");
                    }
                }
            }
        }
    }
    if (SubstrateOptions.VerifyNamingConventions.getValue()) {
        for (AnalysisMethod method : aUniverse.getMethods()) {
            if ((method.isInvoked() || method.isReachable()) && method.getAnnotation(Fold.class) == null) {
                checkName(method.format("%H.%n(%p)"), method, bb);
            }
        }
        for (AnalysisField field : aUniverse.getFields()) {
            if (field.isAccessed()) {
                checkName(field.format("%H.%n"), null, bb);
            }
        }
        for (AnalysisType type : aUniverse.getTypes()) {
            if (type.isReachable()) {
                checkName(type.toJavaName(true), null, bb);
            }
        }
    }
    /*
         * Entry points use a different calling convention (the native C ABI calling convention), so
         * they must not be called from other Java methods.
         */
    for (AnalysisMethod method : aUniverse.getMethods()) {
        if (method.isEntryPoint()) {
            Set<AnalysisMethod> invocations = method.getCallers();
            if (invocations.size() > 0) {
                String name = method.format("%H.%n(%p)");
                StringBuilder msg = new StringBuilder("Native entry point is also called from within Java. Invocations: ");
                String sep = "";
                for (AnalysisMethod invocation : invocations) {
                    msg.append(sep).append(invocation.format("%H.%n(%p)"));
                    sep = ", ";
                }
                bb.getUnsupportedFeatures().addMessage(name, method, msg.toString());
            }
        }
    }
// the unsupported features are reported after checkUniverse is invoked
}
Also used : PointsToAnalysisMethod(com.oracle.graal.pointsto.meta.PointsToAnalysisMethod) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) PointsToAnalysisMethod(com.oracle.graal.pointsto.meta.PointsToAnalysisMethod) TypeState(com.oracle.graal.pointsto.typestate.TypeState) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) NativeImagePointsToAnalysis(com.oracle.svm.hosted.analysis.NativeImagePointsToAnalysis) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Aggregations

NativeImagePointsToAnalysis (com.oracle.svm.hosted.analysis.NativeImagePointsToAnalysis)2 ImageHeap (com.oracle.graal.pointsto.heap.ImageHeap)1 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)1 AnalysisMetaAccessExtensionProvider (com.oracle.graal.pointsto.meta.AnalysisMetaAccessExtensionProvider)1 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 PointsToAnalysisMethod (com.oracle.graal.pointsto.meta.PointsToAnalysisMethod)1 TypeState (com.oracle.graal.pointsto.typestate.TypeState)1 TimerCollection (com.oracle.graal.pointsto.util.TimerCollection)1 SubstratePlatformConfigurationProvider (com.oracle.svm.core.graal.code.SubstratePlatformConfigurationProvider)1 SubstrateLoweringProvider (com.oracle.svm.core.graal.meta.SubstrateLoweringProvider)1 SubstrateReplacements (com.oracle.svm.core.graal.meta.SubstrateReplacements)1 SubstrateStampProvider (com.oracle.svm.core.graal.meta.SubstrateStampProvider)1 NodeLoweringProvider (com.oracle.svm.core.graal.snippets.NodeLoweringProvider)1 Heap (com.oracle.svm.core.heap.Heap)1 AnalysisConstantFieldProvider (com.oracle.svm.hosted.ameta.AnalysisConstantFieldProvider)1 SubstrateUnsupportedFeatures (com.oracle.svm.hosted.analysis.SubstrateUnsupportedFeatures)1 SubstrateGraphMakerFactory (com.oracle.svm.hosted.code.SubstrateGraphMakerFactory)1 NativeImageHeap (com.oracle.svm.hosted.image.NativeImageHeap)1