Search in sources :

Example 1 with ImageHeapScanner

use of com.oracle.graal.pointsto.heap.ImageHeapScanner in project graal by oracle.

the class DynamicHubInitializer method fillGenericInfo.

private void fillGenericInfo(ImageHeapScanner heapScanner, AnalysisType type, DynamicHub hub) {
    Class<?> javaClass = type.getJavaClass();
    TypeVariable<?>[] typeParameters = javaClass.getTypeParameters();
    Type[] allGenericInterfaces;
    try {
        allGenericInterfaces = javaClass.getGenericInterfaces();
    } catch (MalformedParameterizedTypeException | TypeNotPresentException | LinkageError t) {
        /*
             * Loading generic interfaces can fail due to missing types. Ignore the exception and
             * return an empty array.
             */
        allGenericInterfaces = new Type[0];
    }
    Type[] genericInterfaces = Arrays.stream(allGenericInterfaces).filter(this::isTypeAllowed).toArray(Type[]::new);
    Type[] cachedGenericInterfaces;
    try {
        cachedGenericInterfaces = genericInterfacesMap.computeIfAbsent(new GenericInterfacesEncodingKey(genericInterfaces), k -> genericInterfaces);
    } catch (MalformedParameterizedTypeException | TypeNotPresentException | LinkageError t) {
        /*
             * Computing the hash code of generic interfaces can fail due to missing types. Ignore
             * the exception and proceed without caching. De-duplication of generic interfaces is an
             * optimization and not necessary for correctness.
             */
        cachedGenericInterfaces = genericInterfaces;
    }
    Type genericSuperClass;
    try {
        genericSuperClass = javaClass.getGenericSuperclass();
    } catch (MalformedParameterizedTypeException | TypeNotPresentException | LinkageError t) {
        /*
             * Loading the generic super class can fail due to missing types. Ignore the exception
             * and return null.
             */
        genericSuperClass = null;
    }
    if (!isTypeAllowed(genericSuperClass)) {
        genericSuperClass = null;
    }
    hub.setGenericInfo(GenericInfo.factory(typeParameters, cachedGenericInterfaces, genericSuperClass));
    heapScanner.rescanField(hub, dynamicHubGenericInfoField);
}
Also used : Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ReflectionUtil(com.oracle.svm.util.ReflectionUtil) DynamicHub(com.oracle.svm.core.hub.DynamicHub) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) SVMHost(com.oracle.svm.hosted.SVMHost) JavaKind(jdk.vm.ci.meta.JavaKind) Map(java.util.Map) BigBang(com.oracle.graal.pointsto.BigBang) GenericInfo(com.oracle.svm.core.hub.GenericInfo) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) ClassInitializationInfo(com.oracle.svm.core.classinitialization.ClassInitializationInfo) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) CompilationInfoSupport(com.oracle.svm.hosted.code.CompilationInfoSupport) ExceptionSynthesizer(com.oracle.svm.hosted.ExceptionSynthesizer) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) TypeVariable(java.lang.reflect.TypeVariable) MethodPointer(com.oracle.svm.core.meta.MethodPointer) AnnotatedType(java.lang.reflect.AnnotatedType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ImageHeapScanner(com.oracle.graal.pointsto.heap.ImageHeapScanner) Field(java.lang.reflect.Field) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) VMError(com.oracle.svm.core.util.VMError) OtherReason(com.oracle.graal.pointsto.ObjectScanner.OtherReason) Type(java.lang.reflect.Type) MalformedParameterizedTypeException(java.lang.reflect.MalformedParameterizedTypeException) UnsupportedFeatures(com.oracle.graal.pointsto.constraints.UnsupportedFeatures) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) AnnotatedSuperInfo(com.oracle.svm.core.hub.AnnotatedSuperInfo) BuildPhaseProvider(com.oracle.svm.core.BuildPhaseProvider) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AnnotatedType(java.lang.reflect.AnnotatedType) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) Type(java.lang.reflect.Type) MalformedParameterizedTypeException(java.lang.reflect.MalformedParameterizedTypeException) TypeVariable(java.lang.reflect.TypeVariable)

Example 2 with ImageHeapScanner

use of com.oracle.graal.pointsto.heap.ImageHeapScanner 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 ImageHeapScanner

use of com.oracle.graal.pointsto.heap.ImageHeapScanner in project graal by oracle.

the class DynamicHubInitializer method fillAnnotatedSuperInfo.

private void fillAnnotatedSuperInfo(ImageHeapScanner heapScanner, AnalysisType type, DynamicHub hub) {
    Class<?> javaClass = type.getJavaClass();
    AnnotatedType annotatedSuperclass;
    try {
        annotatedSuperclass = javaClass.getAnnotatedSuperclass();
    } catch (MalformedParameterizedTypeException | TypeNotPresentException | LinkageError t) {
        /*
             * Loading the annotated super class can fail due to missing types. Ignore the exception
             * and return null.
             */
        annotatedSuperclass = null;
    }
    if (annotatedSuperclass != null && !isTypeAllowed(annotatedSuperclass.getType())) {
        annotatedSuperclass = null;
    }
    AnnotatedType[] allAnnotatedInterfaces;
    try {
        allAnnotatedInterfaces = javaClass.getAnnotatedInterfaces();
    } catch (MalformedParameterizedTypeException | TypeNotPresentException | LinkageError t) {
        /*
             * Loading annotated interfaces can fail due to missing types. Ignore the exception and
             * return an empty array.
             */
        allAnnotatedInterfaces = new AnnotatedType[0];
    }
    AnnotatedType[] annotatedInterfaces = Arrays.stream(allAnnotatedInterfaces).filter(ai -> isTypeAllowed(ai.getType())).toArray(AnnotatedType[]::new);
    AnnotatedType[] cachedAnnotatedInterfaces = annotatedInterfacesMap.computeIfAbsent(new AnnotatedInterfacesEncodingKey(annotatedInterfaces), k -> annotatedInterfaces);
    hub.setAnnotatedSuperInfo(AnnotatedSuperInfo.factory(annotatedSuperclass, cachedAnnotatedInterfaces));
    heapScanner.rescanField(hub, dynamicHubAnnotatedSuperInfoField);
}
Also used : Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ReflectionUtil(com.oracle.svm.util.ReflectionUtil) DynamicHub(com.oracle.svm.core.hub.DynamicHub) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) SVMHost(com.oracle.svm.hosted.SVMHost) JavaKind(jdk.vm.ci.meta.JavaKind) Map(java.util.Map) BigBang(com.oracle.graal.pointsto.BigBang) GenericInfo(com.oracle.svm.core.hub.GenericInfo) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) ClassInitializationInfo(com.oracle.svm.core.classinitialization.ClassInitializationInfo) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) CompilationInfoSupport(com.oracle.svm.hosted.code.CompilationInfoSupport) ExceptionSynthesizer(com.oracle.svm.hosted.ExceptionSynthesizer) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) TypeVariable(java.lang.reflect.TypeVariable) MethodPointer(com.oracle.svm.core.meta.MethodPointer) AnnotatedType(java.lang.reflect.AnnotatedType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ImageHeapScanner(com.oracle.graal.pointsto.heap.ImageHeapScanner) Field(java.lang.reflect.Field) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) VMError(com.oracle.svm.core.util.VMError) OtherReason(com.oracle.graal.pointsto.ObjectScanner.OtherReason) Type(java.lang.reflect.Type) MalformedParameterizedTypeException(java.lang.reflect.MalformedParameterizedTypeException) UnsupportedFeatures(com.oracle.graal.pointsto.constraints.UnsupportedFeatures) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) AnnotatedSuperInfo(com.oracle.svm.core.hub.AnnotatedSuperInfo) BuildPhaseProvider(com.oracle.svm.core.BuildPhaseProvider) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) AnnotatedType(java.lang.reflect.AnnotatedType) MalformedParameterizedTypeException(java.lang.reflect.MalformedParameterizedTypeException)

Aggregations

ImageHeapScanner (com.oracle.graal.pointsto.heap.ImageHeapScanner)3 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)3 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)3 BigBang (com.oracle.graal.pointsto.BigBang)2 OtherReason (com.oracle.graal.pointsto.ObjectScanner.OtherReason)2 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)2 UnsupportedFeatures (com.oracle.graal.pointsto.constraints.UnsupportedFeatures)2 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)2 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)2 BuildPhaseProvider (com.oracle.svm.core.BuildPhaseProvider)2 ClassInitializationInfo (com.oracle.svm.core.classinitialization.ClassInitializationInfo)2 AnnotatedSuperInfo (com.oracle.svm.core.hub.AnnotatedSuperInfo)2 DynamicHub (com.oracle.svm.core.hub.DynamicHub)2 GenericInfo (com.oracle.svm.core.hub.GenericInfo)2 MethodPointer (com.oracle.svm.core.meta.MethodPointer)2 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)2 VMError (com.oracle.svm.core.util.VMError)2 ExceptionSynthesizer (com.oracle.svm.hosted.ExceptionSynthesizer)2 SVMHost (com.oracle.svm.hosted.SVMHost)2 CompilationInfoSupport (com.oracle.svm.hosted.code.CompilationInfoSupport)2