Search in sources :

Example 1 with AnalysisObjectScanningObserver

use of com.oracle.graal.pointsto.AnalysisObjectScanningObserver in project graal by oracle.

the class NativeImageGenerator method setupNativeImage.

@SuppressWarnings("try")
private void setupNativeImage(String imageName, OptionValues options, Map<Method, CEntryPointData> entryPoints, JavaMainSupport javaMainSupport, SubstitutionProcessor harnessSubstitutions, ForkJoinPool analysisExecutor, SnippetReflectionProvider originalSnippetReflection, DebugContext debug) {
    try (Indent ignored = debug.logAndIndent("setup native-image builder")) {
        try (StopTimer ignored1 = TimerCollection.createTimerAndStart(TimerCollection.Registry.SETUP)) {
            SubstrateTargetDescription target = createTarget(loader.platform);
            ImageSingletons.add(Platform.class, loader.platform);
            ImageSingletons.add(SubstrateTargetDescription.class, target);
            ImageSingletons.add(SubstrateOptions.ReportingSupport.class, new SubstrateOptions.ReportingSupport(DiagnosticsMode.getValue() ? DiagnosticsDir.getValue() : Paths.get("reports").toString()));
            if (javaMainSupport != null) {
                ImageSingletons.add(JavaMainSupport.class, javaMainSupport);
            }
            Providers originalProviders = GraalAccess.getOriginalProviders();
            MetaAccessProvider originalMetaAccess = originalProviders.getMetaAccess();
            ClassInitializationSupport classInitializationSupport = new ConfigurableClassInitialization(originalMetaAccess, loader);
            ImageSingletons.add(RuntimeClassInitializationSupport.class, classInitializationSupport);
            ClassInitializationFeature.processClassInitializationOptions(classInitializationSupport);
            if (ImageBuildStatistics.Options.CollectImageBuildStatistics.getValue(options)) {
                ImageSingletons.add(ImageBuildStatistics.class, new ImageBuildStatistics());
            }
            if (SubstrateOptions.useEconomyCompilerConfig()) {
                HostedConfiguration.setInstanceIfEmpty(new EconomyHostedConfiguration());
                GraalConfiguration.setHostedInstanceIfEmpty(new EconomyGraalConfiguration());
            }
            /* Init the BuildPhaseProvider before any features need it. */
            BuildPhaseProvider.init();
            featureHandler.registerFeatures(loader, debug);
            AfterRegistrationAccessImpl access = new AfterRegistrationAccessImpl(featureHandler, loader, originalMetaAccess, mainEntryPoint, debug);
            featureHandler.forEachFeature(feature -> feature.afterRegistration(access));
            setDefaultLibCIfMissing();
            if (!Pair.<Method, CEntryPointData>empty().equals(access.getMainEntryPoint())) {
                setAndVerifyMainEntryPoint(access, entryPoints);
            }
            registerEntryPoints(entryPoints);
            /*
                 * Check if any configuration factory class was registered. If not, register the
                 * basic one.
                 */
            HostedConfiguration.setDefaultIfEmpty();
            GraalConfiguration.setDefaultIfEmpty();
            AnnotationSubstitutionProcessor annotationSubstitutions = createAnnotationSubstitutionProcessor(originalMetaAccess, loader, classInitializationSupport);
            CEnumCallWrapperSubstitutionProcessor cEnumProcessor = new CEnumCallWrapperSubstitutionProcessor();
            aUniverse = createAnalysisUniverse(options, target, loader, originalMetaAccess, originalSnippetReflection, annotationSubstitutions, cEnumProcessor, classInitializationSupport, Collections.singletonList(harnessSubstitutions));
            AnalysisMetaAccess aMetaAccess = new SVMAnalysisMetaAccess(aUniverse, originalMetaAccess);
            AnalysisConstantReflectionProvider aConstantReflection = new AnalysisConstantReflectionProvider(aUniverse, aMetaAccess, originalProviders.getConstantReflection(), classInitializationSupport);
            WordTypes aWordTypes = new SubstrateWordTypes(aMetaAccess, FrameAccess.getWordKind());
            HostedSnippetReflectionProvider aSnippetReflection = new HostedSnippetReflectionProvider(aWordTypes);
            ForeignCallsProvider aForeignCalls = new SubstrateForeignCallsProvider(aMetaAccess, null);
            bb = createBigBang(options, target, aUniverse, analysisExecutor, watchdog::recordActivity, aMetaAccess, aConstantReflection, aWordTypes, aSnippetReflection, annotationSubstitutions, aForeignCalls, classInitializationSupport, originalProviders);
            aUniverse.setBigBang(bb);
            /* Create the HeapScanner and install it into the universe. */
            ImageHeap imageHeap = new ImageHeap();
            AnalysisObjectScanningObserver aScanningObserver = new AnalysisObjectScanningObserver(bb);
            ImageHeapScanner heapScanner = new SVMImageHeapScanner(imageHeap, loader, aMetaAccess, aSnippetReflection, aConstantReflection, aScanningObserver);
            aUniverse.setHeapScanner(heapScanner);
            HeapSnapshotVerifier heapVerifier = new SVMImageHeapVerifier(bb, imageHeap, heapScanner);
            aUniverse.setHeapVerifier(heapVerifier);
            /* Register already created types as assignable. */
            aUniverse.getTypes().forEach(t -> {
                t.registerAsAssignable(bb);
                if (t.isReachable()) {
                    bb.onTypeInitialized(t);
                }
            });
            boolean withoutCompilerInvoker = CAnnotationProcessorCache.Options.ExitAfterQueryCodeGeneration.getValue() || (NativeImageOptions.ExitAfterRelocatableImageWrite.getValue() && CAnnotationProcessorCache.Options.UseCAPCache.getValue());
            if (!withoutCompilerInvoker) {
                CCompilerInvoker compilerInvoker = CCompilerInvoker.create(ImageSingletons.lookup(TemporaryBuildDirectoryProvider.class).getTemporaryBuildDirectory());
                compilerInvoker.verifyCompiler();
                ImageSingletons.add(CCompilerInvoker.class, compilerInvoker);
            }
            nativeLibraries = setupNativeLibraries(imageName, aConstantReflection, aMetaAccess, aSnippetReflection, cEnumProcessor, classInitializationSupport, debug);
            try (Indent ignored2 = debug.logAndIndent("process startup initializers")) {
                FeatureImpl.DuringSetupAccessImpl config = new FeatureImpl.DuringSetupAccessImpl(featureHandler, loader, bb, debug);
                featureHandler.forEachFeature(feature -> feature.duringSetup(config));
            }
            initializeBigBang(bb, options, featureHandler, nativeLibraries, debug, aMetaAccess, aUniverse.getSubstitutions(), loader, true, new SubstrateClassInitializationPlugin((SVMHost) aUniverse.hostVM()));
            entryPoints.forEach((method, entryPointData) -> CEntryPointCallStubSupport.singleton().registerStubForMethod(method, () -> entryPointData));
        }
        ProgressReporter.singleton().printInitializeEnd(nativeLibraries.getLibraries());
    }
}
Also used : SubstrateForeignCallsProvider(com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider) ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) AnalysisConstantReflectionProvider(com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider) Indent(org.graalvm.compiler.debug.Indent) SubstrateWordTypes(com.oracle.svm.core.graal.word.SubstrateWordTypes) WordTypes(org.graalvm.compiler.word.WordTypes) SubstrateForeignCallsProvider(com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider) ImageBuildStatistics(com.oracle.svm.util.ImageBuildStatistics) Providers(org.graalvm.compiler.phases.util.Providers) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) ConfigurableClassInitialization(com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization) HostedSnippetReflectionProvider(com.oracle.svm.hosted.meta.HostedSnippetReflectionProvider) SVMImageHeapScanner(com.oracle.svm.hosted.heap.SVMImageHeapScanner) ImageHeapScanner(com.oracle.graal.pointsto.heap.ImageHeapScanner) SubstrateClassInitializationPlugin(com.oracle.svm.hosted.phases.SubstrateClassInitializationPlugin) SVMImageHeapVerifier(com.oracle.svm.hosted.heap.SVMImageHeapVerifier) SVMImageHeapScanner(com.oracle.svm.hosted.heap.SVMImageHeapScanner) CEntryPointData(com.oracle.svm.hosted.code.CEntryPointData) AnalysisObjectScanningObserver(com.oracle.graal.pointsto.AnalysisObjectScanningObserver) NativeImageHeap(com.oracle.svm.hosted.image.NativeImageHeap) ImageHeap(com.oracle.graal.pointsto.heap.ImageHeap) AfterRegistrationAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterRegistrationAccessImpl) CEnumCallWrapperSubstitutionProcessor(com.oracle.svm.hosted.cenum.CEnumCallWrapperSubstitutionProcessor) SubstrateOptions(com.oracle.svm.core.SubstrateOptions) AnnotationSubstitutionProcessor(com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor) HeapSnapshotVerifier(com.oracle.graal.pointsto.heap.HeapSnapshotVerifier) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) SVMAnalysisMetaAccess(com.oracle.svm.hosted.analysis.SVMAnalysisMetaAccess) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) Method(java.lang.reflect.Method) WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) PointsToAnalysisMethod(com.oracle.graal.pointsto.meta.PointsToAnalysisMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) SVMAnalysisMetaAccess(com.oracle.svm.hosted.analysis.SVMAnalysisMetaAccess) SubstrateWordTypes(com.oracle.svm.core.graal.word.SubstrateWordTypes) EconomyGraalConfiguration(com.oracle.svm.core.graal.EconomyGraalConfiguration) StopTimer(com.oracle.graal.pointsto.util.Timer.StopTimer) ClassInitializationSupport(com.oracle.svm.hosted.classinitialization.ClassInitializationSupport) RuntimeClassInitializationSupport(org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport) CCompilerInvoker(com.oracle.svm.hosted.c.codegen.CCompilerInvoker) SubstrateTargetDescription(com.oracle.svm.core.SubstrateTargetDescription) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Aggregations

AnalysisObjectScanningObserver (com.oracle.graal.pointsto.AnalysisObjectScanningObserver)1 HeapSnapshotVerifier (com.oracle.graal.pointsto.heap.HeapSnapshotVerifier)1 ImageHeap (com.oracle.graal.pointsto.heap.ImageHeap)1 ImageHeapScanner (com.oracle.graal.pointsto.heap.ImageHeapScanner)1 WrappedJavaMethod (com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod)1 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)1 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 PointsToAnalysisMethod (com.oracle.graal.pointsto.meta.PointsToAnalysisMethod)1 StopTimer (com.oracle.graal.pointsto.util.Timer.StopTimer)1 SubstrateOptions (com.oracle.svm.core.SubstrateOptions)1 SubstrateTargetDescription (com.oracle.svm.core.SubstrateTargetDescription)1 EconomyGraalConfiguration (com.oracle.svm.core.graal.EconomyGraalConfiguration)1 SubstrateForeignCallsProvider (com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider)1 SubstrateWordTypes (com.oracle.svm.core.graal.word.SubstrateWordTypes)1 AfterRegistrationAccessImpl (com.oracle.svm.hosted.FeatureImpl.AfterRegistrationAccessImpl)1 AnalysisConstantReflectionProvider (com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider)1 SVMAnalysisMetaAccess (com.oracle.svm.hosted.analysis.SVMAnalysisMetaAccess)1 CCompilerInvoker (com.oracle.svm.hosted.c.codegen.CCompilerInvoker)1 CEnumCallWrapperSubstitutionProcessor (com.oracle.svm.hosted.cenum.CEnumCallWrapperSubstitutionProcessor)1