use of com.oracle.svm.hosted.ProgressReporter.ReporterClosable 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;
}
use of com.oracle.svm.hosted.ProgressReporter.ReporterClosable 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());
}
}
}
Aggregations