Search in sources :

Example 1 with SubstrateTargetDescription

use of com.oracle.svm.core.SubstrateTargetDescription in project graal by oracle.

the class AArch64CalleeSavedRegisters method createAndRegister.

@Platforms(Platform.HOSTED_ONLY.class)
public static void createAndRegister() {
    SubstrateTargetDescription target = ConfigurationValues.getTarget();
    SubstrateRegisterConfig registerConfig = new SubstrateAArch64RegisterConfig(SubstrateRegisterConfig.ConfigKind.NORMAL, null, target, SubstrateOptions.PreserveFramePointer.getValue());
    Register frameRegister = registerConfig.getFrameRegister();
    List<Register> calleeSavedRegisters = new ArrayList<>(registerConfig.getAllocatableRegisters().asList());
    /*
         * Even though lr is an allocatable register, it is not possible for this register to be
         * callee saved, as AArch64 call instructions override this register.
         */
    calleeSavedRegisters.remove(AArch64.lr);
    /*
         * Reverse list so that CPU registers are spilled close to the beginning of the frame, i.e.,
         * with a closer-to-0 negative reference map index in the caller frame. That makes the
         * reference map encoding of the caller frame a bit smaller.
         */
    Collections.reverse(calleeSavedRegisters);
    int offset = 0;
    Map<Register, Integer> calleeSavedRegisterOffsets = new HashMap<>();
    for (Register register : calleeSavedRegisters) {
        int regByteSize = register.getRegisterCategory().equals(CPU) ? 8 : 16;
        /*
             * It is beneficial to have the offsets aligned to the respective register size so that
             * scaled addressing modes can be used.
             */
        offset += offset % regByteSize;
        calleeSavedRegisterOffsets.put(register, offset);
        offset += regByteSize;
    }
    int calleeSavedRegistersSizeInBytes = offset;
    int saveAreaOffsetInFrame = -(FrameAccess.returnAddressSize() + // slot is always reserved for frame pointer
    FrameAccess.wordSize() + calleeSavedRegistersSizeInBytes);
    ImageSingletons.add(CalleeSavedRegisters.class, new AArch64CalleeSavedRegisters(frameRegister, calleeSavedRegisters, calleeSavedRegisterOffsets, calleeSavedRegistersSizeInBytes, saveAreaOffsetInFrame));
}
Also used : Register(jdk.vm.ci.code.Register) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SubstrateRegisterConfig(com.oracle.svm.core.graal.meta.SubstrateRegisterConfig) SubstrateTargetDescription(com.oracle.svm.core.SubstrateTargetDescription) Platforms(org.graalvm.nativeimage.Platforms)

Example 2 with SubstrateTargetDescription

use of com.oracle.svm.core.SubstrateTargetDescription in project graal by oracle.

the class NativeImageGenerator method createTarget.

public static SubstrateTargetDescription createTarget(Platform platform) {
    if (includedIn(platform, Platform.AMD64.class)) {
        Architecture architecture;
        EnumSet<AMD64.CPUFeature> features = EnumSet.noneOf(AMD64.CPUFeature.class);
        if (NativeImageOptions.NativeArchitecture.getValue()) {
            features.addAll(((AMD64) GraalAccess.getOriginalTarget().arch).getFeatures());
        } else {
            // SSE and SSE2 are added by default as they are required by Graal
            features.add(AMD64.CPUFeature.SSE);
            features.add(AMD64.CPUFeature.SSE2);
            features.addAll(parseCSVtoEnum(AMD64.CPUFeature.class, NativeImageOptions.CPUFeatures.getValue().values(), AMD64.CPUFeature.values()));
        }
        // GR-33542 RTM is only intermittently detected and is not used by Graal
        features.remove(AMD64.CPUFeature.RTM);
        // set up the runtime checked cpu features
        EnumSet<AMD64.CPUFeature> runtimeCheckedFeatures = features.clone();
        if (NativeImageOptions.RuntimeCheckedCPUFeatures.hasBeenSet()) {
            runtimeCheckedFeatures.addAll(parseCSVtoEnum(AMD64.CPUFeature.class, NativeImageOptions.RuntimeCheckedCPUFeatures.getValue().values(), AMD64.CPUFeature.values()));
        } else {
            for (Enum<?> feature : RuntimeCPUFeatureCheck.getSupportedFeatures(GraalAccess.getOriginalTarget().arch)) {
                runtimeCheckedFeatures.add((AMD64.CPUFeature) feature);
            }
        }
        architecture = new AMD64(features, AMD64CPUFeatureAccess.allAMD64Flags());
        assert architecture instanceof AMD64 : "using AMD64 platform with a different architecture";
        // Space for two 64-bit registers: rax and xmm0
        int deoptScratchSpace = 2 * 8;
        return new SubstrateTargetDescription(architecture, true, 16, 0, deoptScratchSpace, runtimeCheckedFeatures);
    } else if (includedIn(platform, Platform.AARCH64.class)) {
        Architecture architecture;
        if (NativeImageOptions.NativeArchitecture.getValue()) {
            architecture = GraalAccess.getOriginalTarget().arch;
        } else {
            EnumSet<AArch64.CPUFeature> features = EnumSet.noneOf(AArch64.CPUFeature.class);
            /*
                 * FP is added by default, as floating-point operations are required by Graal.
                 */
            features.add(AArch64.CPUFeature.FP);
            /*
                 * ASIMD is added by default, as it is available in all AArch64 machines with
                 * floating-port support.
                 */
            features.add(AArch64.CPUFeature.ASIMD);
            features.addAll(parseCSVtoEnum(AArch64.CPUFeature.class, NativeImageOptions.CPUFeatures.getValue().values(), AArch64.CPUFeature.values()));
            architecture = new AArch64(features, AArch64CPUFeatureAccess.enabledAArch64Flags());
        }
        assert architecture instanceof AArch64 : "using AArch64 platform with a different architecture";
        // runtime checked features are the same as static features on AArch64 for now
        EnumSet<AArch64.CPUFeature> runtimeCheckedFeatures = ((AArch64) architecture).getFeatures().clone();
        // Space for two 64-bit registers: r0 and v0.
        int deoptScratchSpace = 2 * 8;
        return new SubstrateTargetDescription(architecture, true, 16, 0, deoptScratchSpace, runtimeCheckedFeatures);
    } else {
        throw UserError.abort("Architecture specified by platform is not supported: %s", platform.getClass().getTypeName());
    }
}
Also used : AArch64(jdk.vm.ci.aarch64.AArch64) AMD64(jdk.vm.ci.amd64.AMD64) Platform(org.graalvm.nativeimage.Platform) Architecture(jdk.vm.ci.code.Architecture) EnumSet(java.util.EnumSet) SubstrateTargetDescription(com.oracle.svm.core.SubstrateTargetDescription) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 3 with SubstrateTargetDescription

use of com.oracle.svm.core.SubstrateTargetDescription 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 4 with SubstrateTargetDescription

use of com.oracle.svm.core.SubstrateTargetDescription in project graal by oracle.

the class HostedConfiguration method createObjectLayout.

/**
 * Defines the layout of objects.
 *
 * The layout of instance objects is:
 * <ul>
 * <li>hub (reference)</li>
 * <li>identity hashcode (int)</li>
 * <li>instance fields (references, primitives)</li>
 * </ul>
 * The hashcode is appended after instance fields and is only present if the identity hashcode
 * is used for that type.
 *
 * The layout of array objects is:
 * <ul>
 * <li>hub (reference)</li>
 * <li>identity hashcode (int)</li>
 * <li>array length (int)</li>
 * <li>array elements (length * reference or primitive)</li>
 * </ul>
 * The hashcode is always present in arrays. Note that on 64-bit targets it does not impose any
 * size overhead for arrays with 64-bit aligned elements (e.g. arrays of objects).
 */
public static ObjectLayout createObjectLayout(JavaKind referenceKind) {
    SubstrateTargetDescription target = ConfigurationValues.getTarget();
    int referenceSize = target.arch.getPlatformKind(referenceKind).getSizeInBytes();
    int objectAlignment = 8;
    int hubOffset = 0;
    int identityHashCodeOffset = hubOffset + referenceSize;
    int firstFieldOffset = identityHashCodeOffset + target.arch.getPlatformKind(JavaKind.Int).getSizeInBytes();
    int arrayLengthOffset = firstFieldOffset;
    int arrayBaseOffset = arrayLengthOffset + target.arch.getPlatformKind(JavaKind.Int).getSizeInBytes();
    return new ObjectLayout(target, referenceSize, objectAlignment, hubOffset, firstFieldOffset, arrayLengthOffset, arrayBaseOffset, identityHashCodeOffset);
}
Also used : ObjectLayout(com.oracle.svm.core.config.ObjectLayout) SubstrateTargetDescription(com.oracle.svm.core.SubstrateTargetDescription)

Example 5 with SubstrateTargetDescription

use of com.oracle.svm.core.SubstrateTargetDescription in project graal by oracle.

the class AMD64CalleeSavedRegisters method emitRestore.

public void emitRestore(AMD64MacroAssembler asm, int frameSize, Register excludedRegister) {
    SubstrateTargetDescription target = ConfigurationValues.getTarget();
    AMD64 arch = (AMD64) target.arch;
    boolean hasAVX = arch.getFeatures().contains(AMD64.CPUFeature.AVX);
    boolean hasAVX512 = arch.getFeatures().contains(AMD64.CPUFeature.AVX512F);
    for (Register register : calleeSavedRegisters) {
        if (register.equals(excludedRegister)) {
            continue;
        }
        AMD64Address address = calleeSaveAddress(asm, frameSize, register);
        RegisterCategory category = register.getRegisterCategory();
        if (category.equals(AMD64.CPU)) {
            asm.movq(register, address);
        } else if (category.equals(AMD64.XMM)) {
            if (hasAVX512) {
                asm.evmovdqu64(register, address);
            } else if (hasAVX) {
                asm.vmovdqu(register, address);
            } else {
                asm.movdqu(register, address);
            }
        } else if (category.equals(AMD64.MASK)) {
            throw VMError.unimplemented();
        } else {
            throw VMError.shouldNotReachHere();
        }
    }
}
Also used : AMD64(jdk.vm.ci.amd64.AMD64) RegisterCategory(jdk.vm.ci.code.Register.RegisterCategory) Register(jdk.vm.ci.code.Register) SubstrateTargetDescription(com.oracle.svm.core.SubstrateTargetDescription) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Aggregations

SubstrateTargetDescription (com.oracle.svm.core.SubstrateTargetDescription)7 Register (jdk.vm.ci.code.Register)4 AMD64 (jdk.vm.ci.amd64.AMD64)3 SubstrateRegisterConfig (com.oracle.svm.core.graal.meta.SubstrateRegisterConfig)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RegisterCategory (jdk.vm.ci.code.Register.RegisterCategory)2 AMD64Address (org.graalvm.compiler.asm.amd64.AMD64Address)2 AnalysisObjectScanningObserver (com.oracle.graal.pointsto.AnalysisObjectScanningObserver)1 HeapSnapshotVerifier (com.oracle.graal.pointsto.heap.HeapSnapshotVerifier)1 ImageHeap (com.oracle.graal.pointsto.heap.ImageHeap)1 ImageHeapScanner (com.oracle.graal.pointsto.heap.ImageHeapScanner)1 WrappedJavaMethod (com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod)1 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)1 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 PointsToAnalysisMethod (com.oracle.graal.pointsto.meta.PointsToAnalysisMethod)1 StopTimer (com.oracle.graal.pointsto.util.Timer.StopTimer)1 SubstrateOptions (com.oracle.svm.core.SubstrateOptions)1 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)1