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;
}
Aggregations