Search in sources :

Example 1 with ClassInitializationSupport

use of com.oracle.svm.hosted.classinitialization.ClassInitializationSupport in project graal by oracle.

the class GraphPrepareMetaAccessExtensionProvider method beforeAnalysis.

@Override
public void beforeAnalysis(BeforeAnalysisAccess c) {
    DebugContext debug = DebugContext.forCurrentThread();
    // box lowering accesses the caches for those classes and thus needs reflective access
    for (JavaKind kind : new JavaKind[] { JavaKind.Boolean, JavaKind.Byte, JavaKind.Char, JavaKind.Double, JavaKind.Float, JavaKind.Int, JavaKind.Long, JavaKind.Short }) {
        RuntimeReflection.register(kind.toBoxedJavaClass());
        Class<?>[] innerClasses = kind.toBoxedJavaClass().getDeclaredClasses();
        if (innerClasses != null && innerClasses.length > 0) {
            RuntimeReflection.register(innerClasses[0]);
            try {
                RuntimeReflection.register(innerClasses[0].getDeclaredField("cache"));
            } catch (Throwable t) {
                throw debug.handle(t);
            }
        }
    }
    BeforeAnalysisAccessImpl config = (BeforeAnalysisAccessImpl) c;
    GraalSupport.allocatePhaseStatisticsCache();
    populateMatchRuleRegistry();
    Function<Providers, SubstrateBackend> backendProvider = GraalSupport.getRuntimeBackendProvider();
    ClassInitializationSupport classInitializationSupport = config.getHostVM().getClassInitializationSupport();
    Providers originalProviders = GraalAccess.getOriginalProviders();
    runtimeConfigBuilder = ImageSingletons.lookup(RuntimeGraalSetup.class).createRuntimeConfigurationBuilder(RuntimeOptionValues.singleton(), config.getHostVM(), config.getUniverse(), config.getMetaAccess(), originalProviders.getConstantReflection(), backendProvider, config.getNativeLibraries(), classInitializationSupport, originalProviders.getLoopsDataProvider()).build();
    RuntimeConfiguration runtimeConfig = runtimeConfigBuilder.getRuntimeConfig();
    Providers runtimeProviders = runtimeConfig.getProviders();
    WordTypes wordTypes = runtimeConfigBuilder.getWordTypes();
    hostedProviders = new HostedProviders(runtimeProviders.getMetaAccess(), runtimeProviders.getCodeCache(), runtimeProviders.getConstantReflection(), runtimeProviders.getConstantFieldProvider(), runtimeProviders.getForeignCalls(), runtimeProviders.getLowerer(), runtimeProviders.getReplacements(), runtimeProviders.getStampProvider(), runtimeConfig.getSnippetReflection(), wordTypes, runtimeProviders.getPlatformConfigurationProvider(), new GraphPrepareMetaAccessExtensionProvider(), runtimeProviders.getLoopsDataProvider());
    SubstrateGraalRuntime graalRuntime = new SubstrateGraalRuntime();
    objectReplacer.setGraalRuntime(graalRuntime);
    ImageSingletons.add(GraalRuntime.class, graalRuntime);
    RuntimeSupport.getRuntimeSupport().addShutdownHook(new GraalSupport.GraalShutdownHook());
    FeatureHandler featureHandler = config.getFeatureHandler();
    NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, runtimeConfig, hostedProviders, config.getMetaAccess(), config.getUniverse(), null, null, config.getNativeLibraries(), config.getImageClassLoader(), ParsingReason.JITCompilation, ((Inflation) config.getBigBang()).getAnnotationSubstitutionProcessor(), new SubstrateClassInitializationPlugin(config.getHostVM()), classInitializationSupport, ConfigurationValues.getTarget());
    NativeImageGenerator.registerReplacements(debug, featureHandler, runtimeConfig, runtimeConfig.getProviders(), false, true);
    featureHandler.forEachGraalFeature(feature -> feature.registerCodeObserver(runtimeConfig));
    Suites suites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
    LIRSuites lirSuites = NativeImageGenerator.createLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
    Suites firstTierSuites = NativeImageGenerator.createFirstTierSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
    LIRSuites firstTierLirSuites = NativeImageGenerator.createFirstTierLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
    GraalSupport.setRuntimeConfig(runtimeConfig, suites, lirSuites, firstTierSuites, firstTierLirSuites);
    NodeClass<?>[] snippetNodeClasses = ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetNodeClasses();
    for (NodeClass<?> nodeClass : snippetNodeClasses) {
        config.getMetaAccess().lookupJavaType(nodeClass.getClazz()).registerAsAllocated(null);
    }
    /* Initialize configuration with reasonable default values. */
    graphBuilderConfig = GraphBuilderConfiguration.getDefault(hostedProviders.getGraphBuilderPlugins()).withBytecodeExceptionMode(BytecodeExceptionMode.ExplicitOnly);
    includeCalleePredicate = GraalFeature::defaultIncludeCallee;
    optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
    methods = new LinkedHashMap<>();
    graphEncoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
    /*
         * Ensure that all snippet methods have their SubstrateMethod object created by the object
         * replacer, to avoid corner cases later when writing the native image.
         */
    for (ResolvedJavaMethod method : ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetMethods()) {
        objectReplacer.apply(method);
    }
}
Also used : SubstrateGraalRuntime(com.oracle.svm.graal.SubstrateGraalRuntime) WordTypes(org.graalvm.compiler.word.WordTypes) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Providers(org.graalvm.compiler.phases.util.Providers) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) SubstrateClassInitializationPlugin(com.oracle.svm.hosted.phases.SubstrateClassInitializationPlugin) NodeClass(org.graalvm.compiler.graph.NodeClass) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) JavaKind(jdk.vm.ci.meta.JavaKind) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites) BeforeAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl) GraalSupport(com.oracle.svm.graal.GraalSupport) DebugContext(org.graalvm.compiler.debug.DebugContext) SubstrateBackend(com.oracle.svm.core.graal.code.SubstrateBackend) RuntimeConfiguration(com.oracle.svm.core.graal.meta.RuntimeConfiguration) SubstrateReplacements(com.oracle.svm.core.graal.meta.SubstrateReplacements) FeatureHandler(com.oracle.svm.hosted.FeatureHandler) NodeClass(org.graalvm.compiler.graph.NodeClass) ClassInitializationSupport(com.oracle.svm.hosted.classinitialization.ClassInitializationSupport) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with ClassInitializationSupport

use of com.oracle.svm.hosted.classinitialization.ClassInitializationSupport 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)

Example 3 with ClassInitializationSupport

use of com.oracle.svm.hosted.classinitialization.ClassInitializationSupport in project graal by oracle.

the class NativeImageGenerator method doRun.

@SuppressWarnings("try")
private void doRun(Map<Method, CEntryPointData> entryPoints, JavaMainSupport javaMainSupport, String imageName, NativeImageKind k, SubstitutionProcessor harnessSubstitutions, ForkJoinPool compilationExecutor, ForkJoinPool analysisExecutor) {
    List<HostedMethod> hostedEntryPoints = new ArrayList<>();
    OptionValues options = HostedOptionValues.singleton();
    SnippetReflectionProvider originalSnippetReflection = GraalAccess.getOriginalSnippetReflection();
    try (DebugContext debug = new Builder(options, new GraalDebugHandlersFactory(originalSnippetReflection)).build();
        DebugCloseable featureCleanup = () -> featureHandler.forEachFeature(Feature::cleanup)) {
        setupNativeImage(imageName, options, entryPoints, javaMainSupport, harnessSubstitutions, analysisExecutor, originalSnippetReflection, debug);
        reporter.printFeatures(featureHandler.getUserFeatureNames());
        boolean returnAfterAnalysis = runPointsToAnalysis(imageName, options, debug);
        if (returnAfterAnalysis) {
            return;
        }
        NativeImageHeap heap;
        HostedMetaAccess hMetaAccess;
        SharedRuntimeConfigurationBuilder runtime;
        try (ReporterClosable c = reporter.printUniverse()) {
            bb.getHeartbeatCallback().run();
            hUniverse = new HostedUniverse(bb);
            hMetaAccess = new HostedMetaAccess(hUniverse, bb.getMetaAccess());
            ((SVMImageHeapScanner) aUniverse.getHeapScanner()).setHostedMetaAccess(hMetaAccess);
            BeforeUniverseBuildingAccessImpl beforeUniverseBuildingConfig = new BeforeUniverseBuildingAccessImpl(featureHandler, loader, debug, hMetaAccess);
            featureHandler.forEachFeature(feature -> feature.beforeUniverseBuilding(beforeUniverseBuildingConfig));
            new UniverseBuilder(aUniverse, bb.getMetaAccess(), hUniverse, hMetaAccess, HostedConfiguration.instance().createStaticAnalysisResultsBuilder(bb, hUniverse), bb.getUnsupportedFeatures()).build(debug);
            BuildPhaseProvider.markHostedUniverseBuilt();
            ClassInitializationSupport classInitializationSupport = bb.getHostVM().getClassInitializationSupport();
            runtime = new HostedRuntimeConfigurationBuilder(options, bb.getHostVM(), hUniverse, hMetaAccess, bb.getProviders(), nativeLibraries, classInitializationSupport, GraalAccess.getOriginalProviders().getLoopsDataProvider()).build();
            registerGraphBuilderPlugins(featureHandler, runtime.getRuntimeConfig(), (HostedProviders) runtime.getRuntimeConfig().getProviders(), bb.getMetaAccess(), aUniverse, hMetaAccess, hUniverse, nativeLibraries, loader, ParsingReason.AOTCompilation, bb.getAnnotationSubstitutionProcessor(), new SubstrateClassInitializationPlugin((SVMHost) aUniverse.hostVM()), classInitializationSupport, ConfigurationValues.getTarget());
            if (NativeImageOptions.PrintUniverse.getValue()) {
                printTypes();
            }
            /* Find the entry point methods in the hosted world. */
            for (AnalysisMethod m : aUniverse.getMethods()) {
                if (m.isEntryPoint()) {
                    HostedMethod found = hUniverse.lookup(m);
                    assert found != null;
                    hostedEntryPoints.add(found);
                }
            }
            if (hostedEntryPoints.size() == 0) {
                throw UserError.abort("Warning: no entry points found, i.e., no method annotated with @%s", CEntryPoint.class.getSimpleName());
            }
            bb.getUnsupportedFeatures().report(bb);
            recordRestrictHeapAccessCallees(aUniverse.getMethods());
            /*
                 * After this point, all TypeFlow (and therefore also TypeState) objects are
                 * unreachable and can be garbage collected. This is important to keep the overall
                 * memory footprint low. However, this also means we no longer have complete call
                 * chain information. Only the summarized information stored in the
                 * StaticAnalysisResult objects is available after this point.
                 */
            bb.cleanupAfterAnalysis();
        } catch (UnsupportedFeatureException ufe) {
            throw FallbackFeature.reportAsFallback(ufe);
        }
        heap = new NativeImageHeap(aUniverse, hUniverse, hMetaAccess, ImageSingletons.lookup(ImageHeapLayouter.class));
        BeforeCompilationAccessImpl beforeCompilationConfig = new BeforeCompilationAccessImpl(featureHandler, loader, aUniverse, hUniverse, heap, debug, runtime);
        featureHandler.forEachFeature(feature -> feature.beforeCompilation(beforeCompilationConfig));
        runtime.updateLazyState(hMetaAccess);
        NativeImageCodeCache codeCache;
        CompileQueue compileQueue;
        try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.COMPILE_TOTAL)) {
            compileQueue = HostedConfiguration.instance().createCompileQueue(debug, featureHandler, hUniverse, runtime, DeoptTester.enabled(), bb.getProviders().getSnippetReflection(), compilationExecutor);
            compileQueue.finish(debug);
            /* release memory taken by graphs for the image writing */
            hUniverse.getMethods().forEach(HostedMethod::clear);
            codeCache = NativeImageCodeCacheFactory.get().newCodeCache(compileQueue, heap, loader.platform, ImageSingletons.lookup(TemporaryBuildDirectoryProvider.class).getTemporaryBuildDirectory());
            codeCache.layoutConstants();
            codeCache.layoutMethods(debug, imageName, bb, compilationExecutor);
            AfterCompilationAccessImpl config = new AfterCompilationAccessImpl(featureHandler, loader, aUniverse, hUniverse, compileQueue.getCompilationTasks(), heap, debug, runtime);
            featureHandler.forEachFeature(feature -> feature.afterCompilation(config));
        }
        CodeCacheProvider codeCacheProvider = runtime.getRuntimeConfig().getBackendForNormalMethod().getProviders().getCodeCache();
        reporter.printCreationStart();
        try (Indent indent = debug.logAndIndent("create native image")) {
            try (DebugContext.Scope buildScope = debug.scope("CreateImage", codeCacheProvider)) {
                try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.IMAGE)) {
                    bb.getHeartbeatCallback().run();
                    // Start building the model of the native image heap.
                    heap.addInitialObjects();
                    // Then build the model of the code cache, which can
                    // add objects to the native image heap.
                    codeCache.addConstantsToHeap();
                    // Finish building the model of the native image heap.
                    heap.addTrailingObjects();
                    AfterHeapLayoutAccessImpl config = new AfterHeapLayoutAccessImpl(featureHandler, loader, heap, hMetaAccess, debug);
                    featureHandler.forEachFeature(feature -> feature.afterHeapLayout(config));
                    this.image = AbstractImage.create(k, hUniverse, hMetaAccess, nativeLibraries, heap, codeCache, hostedEntryPoints, loader.getClassLoader());
                    image.build(imageName, debug);
                    if (NativeImageOptions.PrintUniverse.getValue()) {
                        /*
                             * This debug output must be printed _after_ and not _during_ image
                             * building, because it adds some PrintStream objects to static fields,
                             * which disrupts the heap.
                             */
                        codeCache.printCompilationResults();
                    }
                }
            } catch (Throwable e) {
                throw VMError.shouldNotReachHere(e);
            }
        }
        try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.WRITE)) {
            bb.getHeartbeatCallback().run();
            BeforeImageWriteAccessImpl beforeConfig = new BeforeImageWriteAccessImpl(featureHandler, loader, imageName, image, runtime.getRuntimeConfig(), aUniverse, hUniverse, optionProvider, hMetaAccess, debug);
            featureHandler.forEachFeature(feature -> feature.beforeImageWrite(beforeConfig));
            /*
                 * This will write the debug info too -- i.e. we may be writing more than one file,
                 * if the debug info is in a separate file. We need to push writing the file to the
                 * image implementation, because whether the debug info and image share a file or
                 * not is an implementation detail of the image.
                 */
            Path tmpDir = ImageSingletons.lookup(TemporaryBuildDirectoryProvider.class).getTemporaryBuildDirectory();
            LinkerInvocation inv = image.write(debug, generatedFiles(HostedOptionValues.singleton()), tmpDir, imageName, beforeConfig);
            if (NativeImageOptions.ExitAfterRelocatableImageWrite.getValue()) {
                return;
            }
            AfterImageWriteAccessImpl afterConfig = new AfterImageWriteAccessImpl(featureHandler, loader, hUniverse, inv, tmpDir, image.getImageKind(), debug);
            featureHandler.forEachFeature(feature -> feature.afterImageWrite(afterConfig));
        }
        reporter.printCreationEnd(image.getImageSize(), bb.getUniverse(), heap.getObjectCount(), image.getImageHeapSize(), codeCache.getCodeCacheSize(), codeCache.getCompilations().size(), image.getDebugInfoSize());
        if (SubstrateOptions.BuildOutputBreakdowns.getValue()) {
            ProgressReporter.singleton().printBreakdowns(compileQueue.getCompilationTasks(), image.getHeap().getObjects());
        }
    }
}
Also used : Indent(org.graalvm.compiler.debug.Indent) HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) RuntimeOptionValues(com.oracle.svm.core.option.RuntimeOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) AfterCompilationAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterCompilationAccessImpl) AfterImageWriteAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterImageWriteAccessImpl) ReporterClosable(com.oracle.svm.hosted.ProgressReporter.ReporterClosable) HostedRuntimeConfigurationBuilder(com.oracle.svm.hosted.code.HostedRuntimeConfigurationBuilder) UniverseBuilder(com.oracle.svm.hosted.meta.UniverseBuilder) Builder(org.graalvm.compiler.debug.DebugContext.Builder) SharedRuntimeConfigurationBuilder(com.oracle.svm.hosted.code.SharedRuntimeConfigurationBuilder) BeforeImageWriteAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeImageWriteAccessImpl) ArrayList(java.util.ArrayList) LinkerInvocation(com.oracle.svm.core.LinkerInvocation) BeforeUniverseBuildingAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeUniverseBuildingAccessImpl) HostedRuntimeConfigurationBuilder(com.oracle.svm.hosted.code.HostedRuntimeConfigurationBuilder) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) LocalizationFeature(com.oracle.svm.hosted.jdk.localization.LocalizationFeature) ClassInitializationFeature(com.oracle.svm.hosted.classinitialization.ClassInitializationFeature) Feature(org.graalvm.nativeimage.hosted.Feature) SubstrateClassInitializationPlugin(com.oracle.svm.hosted.phases.SubstrateClassInitializationPlugin) SVMImageHeapScanner(com.oracle.svm.hosted.heap.SVMImageHeapScanner) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) HostedSnippetReflectionProvider(com.oracle.svm.hosted.meta.HostedSnippetReflectionProvider) SubstrateSnippetReflectionProvider(com.oracle.svm.core.graal.meta.SubstrateSnippetReflectionProvider) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) Path(java.nio.file.Path) CompileQueue(com.oracle.svm.hosted.code.CompileQueue) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) AfterHeapLayoutAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterHeapLayoutAccessImpl) NativeImageHeap(com.oracle.svm.hosted.image.NativeImageHeap) NativeImageCodeCache(com.oracle.svm.hosted.image.NativeImageCodeCache) DebugContext(org.graalvm.compiler.debug.DebugContext) HostedUniverse(com.oracle.svm.hosted.meta.HostedUniverse) HostedMetaAccess(com.oracle.svm.hosted.meta.HostedMetaAccess) SharedRuntimeConfigurationBuilder(com.oracle.svm.hosted.code.SharedRuntimeConfigurationBuilder) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) UniverseBuilder(com.oracle.svm.hosted.meta.UniverseBuilder) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) PointsToAnalysisMethod(com.oracle.graal.pointsto.meta.PointsToAnalysisMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) StopTimer(com.oracle.graal.pointsto.util.Timer.StopTimer) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) ClassInitializationSupport(com.oracle.svm.hosted.classinitialization.ClassInitializationSupport) RuntimeClassInitializationSupport(org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport) TemporaryBuildDirectoryProvider(com.oracle.svm.core.c.libc.TemporaryBuildDirectoryProvider) BeforeCompilationAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeCompilationAccessImpl)

Aggregations

ClassInitializationSupport (com.oracle.svm.hosted.classinitialization.ClassInitializationSupport)3 SubstrateClassInitializationPlugin (com.oracle.svm.hosted.phases.SubstrateClassInitializationPlugin)3 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)2 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 PointsToAnalysisMethod (com.oracle.graal.pointsto.meta.PointsToAnalysisMethod)2 StopTimer (com.oracle.graal.pointsto.util.Timer.StopTimer)2 SVMImageHeapScanner (com.oracle.svm.hosted.heap.SVMImageHeapScanner)2 NativeImageHeap (com.oracle.svm.hosted.image.NativeImageHeap)2 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)2 HostedSnippetReflectionProvider (com.oracle.svm.hosted.meta.HostedSnippetReflectionProvider)2 Indent (org.graalvm.compiler.debug.Indent)2 RuntimeClassInitializationSupport (org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport)2 AnalysisObjectScanningObserver (com.oracle.graal.pointsto.AnalysisObjectScanningObserver)1 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)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 LinkerInvocation (com.oracle.svm.core.LinkerInvocation)1