Search in sources :

Example 1 with OnAnalysisExitAccess

use of org.graalvm.nativeimage.hosted.Feature.OnAnalysisExitAccess in project graal by oracle.

the class NativeImageGenerator method runPointsToAnalysis.

@SuppressWarnings("try")
private boolean runPointsToAnalysis(String imageName, OptionValues options, DebugContext debug) {
    try (Indent ignored = debug.logAndIndent("run analysis")) {
        try (Indent ignored1 = debug.logAndIndent("process analysis initializers")) {
            BeforeAnalysisAccessImpl config = new BeforeAnalysisAccessImpl(featureHandler, loader, bb, nativeLibraries, debug);
            featureHandler.forEachFeature(feature -> feature.beforeAnalysis(config));
            bb.getHostVM().getClassInitializationSupport().setConfigurationSealed(true);
        }
        try (ReporterClosable c = ProgressReporter.singleton().printAnalysis(bb)) {
            DuringAnalysisAccessImpl config = new DuringAnalysisAccessImpl(featureHandler, loader, bb, nativeLibraries, debug);
            try {
                bb.runAnalysis(debug, (universe) -> {
                    try (StopTimer t2 = TimerCollection.createTimerAndStart(TimerCollection.Registry.FEATURES)) {
                        bb.getHostVM().notifyClassReachabilityListener(universe, config);
                        featureHandler.forEachFeature(feature -> feature.duringAnalysis(config));
                    }
                    return !config.getAndResetRequireAnalysisIteration();
                });
            } catch (AnalysisError e) {
                throw UserError.abort(e, "Analysis step failed. Reason: %s.", e.getMessage());
            }
            assert verifyAssignableTypes(imageName);
            /*
                 * Libraries defined via @CLibrary annotations are added at the end of the list of
                 * libraries so that the written object file AND the static JDK libraries can depend
                 * on them.
                 */
            nativeLibraries.processAnnotated();
            BuildPhaseProvider.markAnalysisFinished();
            AfterAnalysisAccessImpl postConfig = new AfterAnalysisAccessImpl(featureHandler, loader, bb, debug);
            featureHandler.forEachFeature(feature -> feature.afterAnalysis(postConfig));
            checkUniverse();
            bb.printTimers();
            /* report the unsupported features by throwing UnsupportedFeatureException */
            bb.getUnsupportedFeatures().report(bb);
            bb.checkUserLimitations();
        } catch (UnsupportedFeatureException ufe) {
            throw FallbackFeature.reportAsFallback(ufe);
        }
    } catch (InterruptedException ie) {
        throw new InterruptImageBuilding();
    } finally {
        OnAnalysisExitAccess onExitConfig = new OnAnalysisExitAccessImpl(featureHandler, loader, bb, debug);
        featureHandler.forEachFeature(feature -> feature.onAnalysisExit(onExitConfig));
        /*
             * Execute analysis reporting here. This code is executed even if unsupported features
             * are reported or the analysis fails due to any other reasons.
             */
        AnalysisReporter.printAnalysisReports(imageName, options, SubstrateOptions.reportsPath(), bb);
    }
    if (NativeImageOptions.ReturnAfterAnalysis.getValue()) {
        return true;
    }
    if (NativeImageOptions.ExitAfterAnalysis.getValue()) {
        throw new InterruptImageBuilding("Exiting image generation because of " + SubstrateOptionsParser.commandArgument(NativeImageOptions.ExitAfterAnalysis, "+"));
    }
    return false;
}
Also used : BeforeAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl) Indent(org.graalvm.compiler.debug.Indent) OnAnalysisExitAccessImpl(com.oracle.svm.hosted.FeatureImpl.OnAnalysisExitAccessImpl) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) ReporterClosable(com.oracle.svm.hosted.ProgressReporter.ReporterClosable) OnAnalysisExitAccess(org.graalvm.nativeimage.hosted.Feature.OnAnalysisExitAccess) AnalysisError(com.oracle.graal.pointsto.util.AnalysisError) AfterAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterAnalysisAccessImpl) StopTimer(com.oracle.graal.pointsto.util.Timer.StopTimer) DuringAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl) InterruptImageBuilding(com.oracle.svm.core.util.InterruptImageBuilding)

Aggregations

UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)1 AnalysisError (com.oracle.graal.pointsto.util.AnalysisError)1 StopTimer (com.oracle.graal.pointsto.util.Timer.StopTimer)1 InterruptImageBuilding (com.oracle.svm.core.util.InterruptImageBuilding)1 AfterAnalysisAccessImpl (com.oracle.svm.hosted.FeatureImpl.AfterAnalysisAccessImpl)1 BeforeAnalysisAccessImpl (com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl)1 DuringAnalysisAccessImpl (com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl)1 OnAnalysisExitAccessImpl (com.oracle.svm.hosted.FeatureImpl.OnAnalysisExitAccessImpl)1 ReporterClosable (com.oracle.svm.hosted.ProgressReporter.ReporterClosable)1 Indent (org.graalvm.compiler.debug.Indent)1 OnAnalysisExitAccess (org.graalvm.nativeimage.hosted.Feature.OnAnalysisExitAccess)1