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