use of com.oracle.graal.pointsto.heap.HeapSnapshotVerifier 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());
}
}
Aggregations