From 33909612394de38d753094ca6a1c1758be241294 Mon Sep 17 00:00:00 2001 From: Tom Shull Date: Mon, 3 Jan 2022 15:33:23 +0100 Subject: [PATCH] Make distinction between IOS, DARWIN, and MACOS platforms. --- .../org.graalvm.nativeimage/snapshot.sigtest | 55 ++++++--- .../services/org.graalvm.nativeimage.Platform | 4 +- .../src/org/graalvm/nativeimage/Platform.java | 104 ++++++++++++------ .../SubstrateAArch64RegisterConfig.java | 3 +- .../amd64/SubstrateAMD64RegisterConfig.java | 9 +- .../AArch64DarwinUContextRegisterDumper.java | 2 +- .../AArch64LinuxUContextRegisterDumper.java | 2 +- .../oracle/svm/core/posix/headers/Signal.java | 10 +- .../com/oracle/svm/core/SubstrateOptions.java | 15 ++- .../oracle/svm/driver/MacroOptionHandler.java | 2 +- .../hosted/NativeImageGeneratorRunner.java | 5 +- .../oracle/svm/hosted/c/NativeLibraries.java | 14 ++- .../svm/hosted/image/NativeImageViaCC.java | 10 +- .../com/oracle/svm/hosted/jfr/JfrFeature.java | 6 +- .../SubstrateGraphBuilderPlugins.java | 2 +- .../jni/hosted/JNIJavaCallWrapperMethod.java | 5 +- 16 files changed, 166 insertions(+), 82 deletions(-) diff --git a/sdk/src/org.graalvm.nativeimage/snapshot.sigtest b/sdk/src/org.graalvm.nativeimage/snapshot.sigtest index 2083fb7967bf..f56d7c28d39e 100644 --- a/sdk/src/org.graalvm.nativeimage/snapshot.sigtest +++ b/sdk/src/org.graalvm.nativeimage/snapshot.sigtest @@ -217,16 +217,21 @@ innr public abstract interface static AARCH64 innr public abstract interface static AMD64 innr public abstract interface static ANDROID innr public abstract interface static DARWIN +innr public abstract interface static DARWIN_AARCH64 +innr public abstract interface static DARWIN_AMD64 innr public abstract interface static IOS innr public abstract interface static LINUX +innr public abstract interface static LINUX_AARCH64_BASE +innr public abstract interface static LINUX_AMD64_BASE +innr public abstract interface static MACOS innr public abstract interface static WINDOWS innr public final static ANDROID_AARCH64 -innr public final static DARWIN_AARCH64 -innr public final static DARWIN_AMD64 innr public final static HOSTED_ONLY innr public final static IOS_AARCH64 innr public final static IOS_AMD64 innr public final static LINUX_AARCH64 +innr public final static MACOS_AARCH64 +innr public final static MACOS_AMD64 innr public final static WINDOWS_AARCH64 innr public final static WINDOWS_AMD64 innr public static LINUX_AMD64 @@ -252,28 +257,23 @@ meth public java.lang.String getOS() CLSS public final static org.graalvm.nativeimage.Platform$ANDROID_AARCH64 outer org.graalvm.nativeimage.Platform cons public init() -intf org.graalvm.nativeimage.Platform$AARCH64 intf org.graalvm.nativeimage.Platform$ANDROID +intf org.graalvm.nativeimage.Platform$LINUX_AARCH64_BASE supr java.lang.Object CLSS public abstract interface static org.graalvm.nativeimage.Platform$DARWIN outer org.graalvm.nativeimage.Platform intf org.graalvm.nativeimage.impl.InternalPlatform$PLATFORM_JNI -meth public java.lang.String getOS() -CLSS public final static org.graalvm.nativeimage.Platform$DARWIN_AARCH64 +CLSS public abstract interface static org.graalvm.nativeimage.Platform$DARWIN_AARCH64 outer org.graalvm.nativeimage.Platform -cons public init() intf org.graalvm.nativeimage.Platform$AARCH64 intf org.graalvm.nativeimage.Platform$DARWIN -supr java.lang.Object -CLSS public final static org.graalvm.nativeimage.Platform$DARWIN_AMD64 +CLSS public abstract interface static org.graalvm.nativeimage.Platform$DARWIN_AMD64 outer org.graalvm.nativeimage.Platform -cons public init() intf org.graalvm.nativeimage.Platform$AMD64 intf org.graalvm.nativeimage.Platform$DARWIN -supr java.lang.Object CLSS public final static org.graalvm.nativeimage.Platform$HOSTED_ONLY outer org.graalvm.nativeimage.Platform @@ -288,14 +288,14 @@ meth public java.lang.String getOS() CLSS public final static org.graalvm.nativeimage.Platform$IOS_AARCH64 outer org.graalvm.nativeimage.Platform cons public init() -intf org.graalvm.nativeimage.Platform$AARCH64 +intf org.graalvm.nativeimage.Platform$DARWIN_AARCH64 intf org.graalvm.nativeimage.Platform$IOS supr java.lang.Object CLSS public final static org.graalvm.nativeimage.Platform$IOS_AMD64 outer org.graalvm.nativeimage.Platform cons public init() -intf org.graalvm.nativeimage.Platform$AMD64 +intf org.graalvm.nativeimage.Platform$DARWIN_AMD64 intf org.graalvm.nativeimage.Platform$IOS supr java.lang.Object @@ -307,15 +307,44 @@ meth public java.lang.String getOS() CLSS public final static org.graalvm.nativeimage.Platform$LINUX_AARCH64 outer org.graalvm.nativeimage.Platform cons public init() -intf org.graalvm.nativeimage.Platform$AARCH64 intf org.graalvm.nativeimage.Platform$LINUX +intf org.graalvm.nativeimage.Platform$LINUX_AARCH64_BASE supr java.lang.Object +CLSS public abstract interface static org.graalvm.nativeimage.Platform$LINUX_AARCH64_BASE + outer org.graalvm.nativeimage.Platform +intf org.graalvm.nativeimage.Platform$AARCH64 +intf org.graalvm.nativeimage.Platform$LINUX + CLSS public static org.graalvm.nativeimage.Platform$LINUX_AMD64 outer org.graalvm.nativeimage.Platform cons public init() +intf org.graalvm.nativeimage.Platform$LINUX +intf org.graalvm.nativeimage.Platform$LINUX_AMD64_BASE +supr java.lang.Object + +CLSS public abstract interface static org.graalvm.nativeimage.Platform$LINUX_AMD64_BASE + outer org.graalvm.nativeimage.Platform intf org.graalvm.nativeimage.Platform$AMD64 intf org.graalvm.nativeimage.Platform$LINUX + +CLSS public abstract interface static org.graalvm.nativeimage.Platform$MACOS + outer org.graalvm.nativeimage.Platform +intf org.graalvm.nativeimage.Platform$DARWIN +meth public java.lang.String getOS() + +CLSS public final static org.graalvm.nativeimage.Platform$MACOS_AARCH64 + outer org.graalvm.nativeimage.Platform +cons public init() +intf org.graalvm.nativeimage.Platform$DARWIN_AARCH64 +intf org.graalvm.nativeimage.Platform$MACOS +supr java.lang.Object + +CLSS public final static org.graalvm.nativeimage.Platform$MACOS_AMD64 + outer org.graalvm.nativeimage.Platform +cons public init() +intf org.graalvm.nativeimage.Platform$DARWIN_AMD64 +intf org.graalvm.nativeimage.Platform$MACOS supr java.lang.Object CLSS public abstract interface static org.graalvm.nativeimage.Platform$WINDOWS diff --git a/sdk/src/org.graalvm.nativeimage/src/META-INF/services/org.graalvm.nativeimage.Platform b/sdk/src/org.graalvm.nativeimage/src/META-INF/services/org.graalvm.nativeimage.Platform index 035172aa9f70..31f89e6b5f11 100644 --- a/sdk/src/org.graalvm.nativeimage/src/META-INF/services/org.graalvm.nativeimage.Platform +++ b/sdk/src/org.graalvm.nativeimage/src/META-INF/services/org.graalvm.nativeimage.Platform @@ -1,9 +1,9 @@ org.graalvm.nativeimage.Platform$LINUX_AMD64 org.graalvm.nativeimage.Platform$LINUX_AARCH64 org.graalvm.nativeimage.Platform$ANDROID_AARCH64 -org.graalvm.nativeimage.Platform$DARWIN_AMD64 -org.graalvm.nativeimage.Platform$DARWIN_AARCH64 org.graalvm.nativeimage.Platform$IOS_AMD64 org.graalvm.nativeimage.Platform$IOS_AARCH64 +org.graalvm.nativeimage.Platform$MACOS_AMD64 +org.graalvm.nativeimage.Platform$MACOS_AARCH64 org.graalvm.nativeimage.Platform$WINDOWS_AMD64 org.graalvm.nativeimage.Platform$WINDOWS_AARCH64 diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/Platform.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/Platform.java index b96a1e0d1488..1be4d7be49a0 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/Platform.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/Platform.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -184,36 +184,44 @@ default String getOS() { } /** - * Supported operating system: Darwin (MacOS). + * Basis for all Apple operating systems (MacOS and iOS). * * @since 19.0 */ interface DARWIN extends InternalPlatform.PLATFORM_JNI { + } + + /** + * Supported operating system: iOS. + * + * @since 21.0 + */ + interface IOS extends DARWIN { /** - * Returns string representing DARWIN OS. + * Returns string representing iOS OS. * * @since 21.0 */ default String getOS() { - return DARWIN.class.getSimpleName().toLowerCase(); + return IOS.class.getSimpleName().toLowerCase(); } } /** - * Supported operating system: iOS. + * Supported operating system: MacOS. * - * @since 21.0 + * @since 22.1 */ - interface IOS extends DARWIN { + interface MACOS extends DARWIN { /** - * Returns string representing IOS OS. + * Returns string representing MACOS OS. * * @since 21.0 */ default String getOS() { - return IOS.class.getSimpleName().toLowerCase(); + return "darwin"; } } @@ -234,6 +242,38 @@ default String getOS() { } } + /** + * Basis for all Linux operating systems on AMD64 (LINUX_AMD64). + * + * @since 22.1 + */ + interface LINUX_AMD64_BASE extends LINUX, AMD64 { + } + + /** + * Basis for all Linux operating systems on AARCH64 (LINUX_AARCH64 & ANDROID_AARCH64). + * + * @since 22.1 + */ + interface LINUX_AARCH64_BASE extends LINUX, AARCH64 { + } + + /** + * Basis for all Apple operating systems on AMD64 (MACOS_AMD64 & IOS_AMD64). + * + * @since 22.1 + */ + interface DARWIN_AMD64 extends DARWIN, AMD64 { + } + + /** + * Basis for all Apple operating systems on AMD64 (MACOS_AMD64 & IOS_AMD64). + * + * @since 22.1 + */ + interface DARWIN_AARCH64 extends DARWIN, AARCH64 { + } + /* * The standard leaf platforms, i.e., OS-architecture combinations that we support. */ @@ -242,7 +282,7 @@ default String getOS() { * * @since 19.0 */ - class LINUX_AMD64 implements LINUX, AMD64 { + class LINUX_AMD64 implements LINUX, LINUX_AMD64_BASE { /** * Instantiates a marker instance of this platform. @@ -259,7 +299,7 @@ public LINUX_AMD64() { * * @since 19.0 */ - final class LINUX_AARCH64 implements LINUX, AARCH64 { + final class LINUX_AARCH64 implements LINUX, LINUX_AARCH64_BASE { /** * Instantiates a marker instance of this platform. @@ -276,7 +316,7 @@ public LINUX_AARCH64() { * * @since 21.0 */ - final class ANDROID_AARCH64 implements ANDROID, AARCH64 { + final class ANDROID_AARCH64 implements ANDROID, LINUX_AARCH64_BASE { /** * Instantiates a marker instance of this platform. @@ -289,66 +329,66 @@ public ANDROID_AARCH64() { } /** - * Supported leaf platform: Darwin (MacOS) on x86 64-bit. + * Supported leaf platform: iOS on x86 64-bit. * - * @since 19.0 + * @since 21.3 */ - final class DARWIN_AMD64 implements DARWIN, AMD64 { + final class IOS_AMD64 implements IOS, DARWIN_AMD64 { /** * Instantiates a marker instance of this platform. * - * @since 19.0 + * @since 21.3 */ - public DARWIN_AMD64() { + public IOS_AMD64() { } } /** - * Supported leaf platform: Darwin (MacOS) on AArch 64-bit. + * Supported leaf platform: iOS on AArch 64-bit. * - * @since 2.0 + * @since 21.0 */ - final class DARWIN_AARCH64 implements DARWIN, AARCH64 { + final class IOS_AARCH64 implements IOS, DARWIN_AARCH64 { /** * Instantiates a marker instance of this platform. * - * @since 2.0 + * @since 21.0 */ - public DARWIN_AARCH64() { + public IOS_AARCH64() { } } /** - * Supported leaf platform: iOS on AArch 64-bit. + * Supported leaf platform: MacOS on x86 64-bit. * - * @since 21.0 + * @since 22.1 */ - final class IOS_AARCH64 implements IOS, AARCH64 { + final class MACOS_AMD64 implements MACOS, DARWIN_AMD64 { /** * Instantiates a marker instance of this platform. * - * @since 21.0 + * @since 22.1 */ - public IOS_AARCH64() { + public MACOS_AMD64() { } } /** - * Supported leaf platform: iOS on x86 64-bit. + * Supported leaf platform: MacOS on AArch 64-bit. * - * @since 21.3 + * @since 22.1 */ - final class IOS_AMD64 implements IOS, AMD64 { + final class MACOS_AARCH64 implements MACOS, DARWIN_AARCH64 { /** * Instantiates a marker instance of this platform. * - * @since 21.3 + * @since 22.1 */ - public IOS_AMD64() { + public MACOS_AARCH64() { } } diff --git a/substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64RegisterConfig.java b/substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64RegisterConfig.java index 95aefcdb8e67..10b42a0143f8 100755 --- a/substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64RegisterConfig.java +++ b/substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64RegisterConfig.java @@ -72,7 +72,6 @@ import org.graalvm.compiler.core.common.NumUtil; import org.graalvm.nativeimage.Platform; -import com.oracle.svm.core.OS; import com.oracle.svm.core.ReservedRegisters; import com.oracle.svm.core.config.ObjectLayout; import com.oracle.svm.core.graal.code.SubstrateCallingConvention; @@ -157,7 +156,7 @@ public SubstrateAArch64RegisterConfig(ConfigKind config, MetaAccessProvider meta * * https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions */ - if (OS.DARWIN.isCurrent() || OS.WINDOWS.isCurrent()) { + if (Platform.includedIn(Platform.DARWIN.class) || Platform.includedIn(Platform.WINDOWS.class)) { regs.remove(r18); } allocatableRegs = new RegisterArray(regs); diff --git a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64RegisterConfig.java b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64RegisterConfig.java index 05752dc791b2..dddb355605f5 100644 --- a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64RegisterConfig.java +++ b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64RegisterConfig.java @@ -57,7 +57,8 @@ import java.util.ArrayList; -import com.oracle.svm.core.OS; +import org.graalvm.nativeimage.Platform; + import com.oracle.svm.core.ReservedRegisters; import com.oracle.svm.core.config.ObjectLayout; import com.oracle.svm.core.graal.code.SubstrateCallingConvention; @@ -102,7 +103,7 @@ public SubstrateAMD64RegisterConfig(ConfigKind config, MetaAccessProvider metaAc this.metaAccess = metaAccess; this.useBasePointer = useBasePointer; - if (OS.getCurrent() == OS.WINDOWS) { + if (Platform.includedIn(Platform.WINDOWS.class)) { // This is the Windows 64-bit ABI for parameters. // Note that float parameters also "consume" a general register and vice versa. nativeGeneralParameterRegs = new RegisterArray(rcx, rdx, r8, r9); @@ -147,7 +148,7 @@ public SubstrateAMD64RegisterConfig(ConfigKind config, MetaAccessProvider metaAc * rbp must be last in the list, so that it gets the location closest to the saved * return address. */ - if (OS.getCurrent() == OS.WINDOWS) { + if (Platform.includedIn(Platform.WINDOWS.class)) { calleeSaveRegisters = new RegisterArray(rbx, rdi, rsi, r12, r13, r14, r15, rbp, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15); } else { @@ -238,7 +239,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) parameterTypes[i], metaAccess, target); kinds[i] = kind; - if (type.nativeABI() && OS.getCurrent() == OS.WINDOWS) { + if (type.nativeABI() && Platform.includedIn(Platform.WINDOWS.class)) { // Strictly positional: float parameters consume a general register and vice versa currentGeneral = i; currentXMM = i; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64DarwinUContextRegisterDumper.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64DarwinUContextRegisterDumper.java index 5339e5ad84ec..7ad6e84bb096 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64DarwinUContextRegisterDumper.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64DarwinUContextRegisterDumper.java @@ -44,7 +44,7 @@ import jdk.vm.ci.aarch64.AArch64; -@Platforms({Platform.DARWIN_AARCH64.class, Platform.IOS_AARCH64.class}) +@Platforms({Platform.DARWIN_AARCH64.class}) @AutomaticFeature class AArch64DarwinUContextRegisterDumperFeature implements Feature { @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64LinuxUContextRegisterDumper.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64LinuxUContextRegisterDumper.java index 235d1e157234..45041ee59103 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64LinuxUContextRegisterDumper.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64LinuxUContextRegisterDumper.java @@ -46,7 +46,7 @@ import jdk.vm.ci.aarch64.AArch64; -@Platforms({Platform.LINUX_AARCH64.class, Platform.ANDROID_AARCH64.class}) +@Platforms({Platform.LINUX_AARCH64_BASE.class}) @AutomaticFeature class AArch64LinuxUContextRegisterDumperFeature implements Feature { @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Signal.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Signal.java index c469a16d391a..2156a277536c 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Signal.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Signal.java @@ -110,7 +110,7 @@ public interface siginfo_t extends PointerBase { VoidPointer si_addr(); } - @Platforms({Platform.LINUX.class, Platform.DARWIN_AARCH64.class, Platform.IOS_AARCH64.class}) + @Platforms({Platform.LINUX.class, Platform.DARWIN_AARCH64.class}) @CPointerTo(nameOfCType = "long long int") public interface GregsPointer extends PointerBase { long read(int index); @@ -123,7 +123,7 @@ public interface ucontext_t extends RegisterDumper.Context { GregsPointer uc_mcontext_linux_amd64_gregs(); @CFieldAddress("uc_mcontext") - @Platforms({Platform.LINUX_AARCH64.class, Platform.ANDROID_AARCH64.class}) + @Platforms({Platform.LINUX_AARCH64_BASE.class}) mcontext_linux_aarch64_t uc_mcontext_linux_aarch64(); @CField("uc_mcontext") @@ -131,7 +131,7 @@ public interface ucontext_t extends RegisterDumper.Context { AMD64DarwinMContext64 uc_mcontext_darwin_amd64(); @CField("uc_mcontext") - @Platforms({Platform.DARWIN_AARCH64.class, Platform.IOS_AARCH64.class}) + @Platforms({Platform.DARWIN_AARCH64.class}) AArch64DarwinMContext64 uc_mcontext_darwin_aarch64(); } @@ -328,7 +328,7 @@ public static final class GregEnumLinuxAMD64 { * https://github.com/torvalds/linux/blob/9e1ff307c779ce1f0f810c7ecce3d95bbae40896/arch/arm64/include/uapi/asm/sigcontext.h#L28 */ @CStruct(value = "mcontext_t") - @Platforms({Platform.LINUX_AARCH64.class, Platform.ANDROID_AARCH64.class}) + @Platforms({Platform.LINUX_AARCH64_BASE.class}) public interface mcontext_linux_aarch64_t extends PointerBase { @CField long fault_address(); @@ -418,7 +418,7 @@ public interface AMD64DarwinMContext64 extends PointerBase { * Information about _STRUCT_ARM_THREAD_STATE64 can be found at * https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/arm/_structs.h#L102 */ - @Platforms({Platform.DARWIN_AARCH64.class, Platform.IOS_AARCH64.class}) + @Platforms({Platform.DARWIN_AARCH64.class}) @CStruct(value = "__darwin_mcontext64", addStructKeyword = true) public interface AArch64DarwinMContext64 extends PointerBase { @CFieldAddress("__ss.__x") diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index 497f13a1d3c0..a50e999fda29 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -95,7 +95,20 @@ public static boolean parseOnce() { @APIOption(name = "target")// @Option(help = "Selects native-image compilation target (in - format). Defaults to host's OS-architecture pair.")// - public static final HostedOptionKey TargetPlatform = new HostedOptionKey<>(""); + public static final HostedOptionKey TargetPlatform = new HostedOptionKey<>("") { + @Override + protected void onValueUpdate(EconomicMap, Object> values, String oldValue, String newValue) { + String updatedNewValue; + // both darwin and macos refer to Platform.MacOS + if (newValue.equals("macos")) { + updatedNewValue = "darwin"; + } else { + updatedNewValue = newValue; + } + super.onValueUpdate(values, oldValue, updatedNewValue); + + } + }; @Option(help = "Builds a statically linked executable with libc dynamically linked", type = Expert, stability = OptionStability.EXPERIMENTAL)// public static final HostedOptionKey StaticExecutableWithDynamicLibC = new HostedOptionKey<>(false) { diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MacroOptionHandler.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MacroOptionHandler.java index f53010eba43c..7be4b92c6627 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MacroOptionHandler.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MacroOptionHandler.java @@ -66,7 +66,7 @@ public boolean consume(ArgumentQueue args) { private static final String PATH_SEPARATOR_REGEX; static { - if (OS.getCurrent().equals(OS.WINDOWS)) { + if (OS.WINDOWS.isCurrent()) { PATH_SEPARATOR_REGEX = ":|;"; } else { PATH_SEPARATOR_REGEX = File.pathSeparator; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java index 60b3199a7299..d0699c951eb8 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java @@ -272,8 +272,7 @@ private static boolean isValidArchitecture() { } private static boolean isValidOperatingSystem() { - final OS currentOs = OS.getCurrent(); - return currentOs == OS.LINUX || currentOs == OS.DARWIN || currentOs == OS.WINDOWS; + return OS.LINUX.isCurrent() || OS.DARWIN.isCurrent() || OS.WINDOWS.isCurrent(); } @SuppressWarnings("try") @@ -487,7 +486,7 @@ private int buildImage(ImageClassLoader classLoader) { public static boolean verifyValidJavaVersionAndPlatform() { if (!isValidArchitecture()) { - reportToolUserError("runs only on architecture AMD64. Detected architecture: " + ClassUtil.getUnqualifiedName(GraalAccess.getOriginalTarget().arch.getClass())); + reportToolUserError("runs on AMD64 and AArch64 only. Detected architecture: " + ClassUtil.getUnqualifiedName(GraalAccess.getOriginalTarget().arch.getClass())); } if (!isValidOperatingSystem()) { reportToolUserError("runs on Linux, Mac OS X and Windows only. Detected OS: " + System.getProperty("os.name")); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/NativeLibraries.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/NativeLibraries.java index 1de44f7e4a12..cc7bc3335cca 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/NativeLibraries.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/NativeLibraries.java @@ -74,7 +74,6 @@ import com.oracle.graal.pointsto.infrastructure.WrappedElement; import com.oracle.graal.pointsto.meta.AnalysisType; -import com.oracle.svm.core.OS; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.c.libc.LibCBase; import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport; @@ -285,8 +284,12 @@ public TargetDescription getTarget() { return target; } - private static final String libPrefix = OS.getCurrent() == OS.WINDOWS ? "" : "lib"; - private static final String libSuffix = OS.getCurrent() == OS.WINDOWS ? ".lib" : ".a"; + private static String getStaticLibraryName(String libraryName) { + boolean targetWindows = Platform.includedIn(Platform.WINDOWS.class); + String prefix = targetWindows ? "" : "lib"; + String suffix = targetWindows ? ".lib" : ".a"; + return prefix + libraryName + suffix; + } private static Path getPlatformDependentJDKStaticLibraryPath() throws IOException { Path baseSearchPath = Paths.get(System.getProperty("java.home")).resolve("lib").toRealPath(); @@ -317,7 +320,7 @@ private static LinkedHashSet initCLibraryPath() { Path jdkLibDir = getPlatformDependentJDKStaticLibraryPath(); List defaultBuiltInLibraries = Arrays.asList(PlatformNativeLibrarySupport.defaultBuiltInLibraries); - Predicate hasStaticLibrary = s -> Files.isRegularFile(jdkLibDir.resolve(libPrefix + s + libSuffix)); + Predicate hasStaticLibrary = s -> Files.isRegularFile(jdkLibDir.resolve(getStaticLibraryName(s))); if (defaultBuiltInLibraries.stream().allMatch(hasStaticLibrary)) { staticLibsDir = jdkLibDir; } else { @@ -457,11 +460,12 @@ public Path getStaticLibraryPath(String staticLibraryName) { } private static Path getStaticLibraryPath(Map allStaticLibs, String staticLibraryName) { - return allStaticLibs.get(Paths.get(libPrefix + staticLibraryName + libSuffix)); + return allStaticLibs.get(Paths.get(getStaticLibraryName(staticLibraryName))); } private Map getAllStaticLibs() { Map allStaticLibs = new LinkedHashMap<>(); + String libSuffix = Platform.includedIn(Platform.WINDOWS.class) ? ".lib" : ".a"; for (String libraryPath : getLibraryPaths()) { try (Stream paths = Files.list(Paths.get(libraryPath))) { paths.filter(Files::isRegularFile) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java index 577e4e06f338..b30f1f078662 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java @@ -399,9 +399,9 @@ private static List diagnoseLinkerFailure(String linkerOutput) { Pattern p = Pattern.compile(".*cannot find -l([^\\s]+)\\s.*", Pattern.DOTALL); Matcher m = p.matcher(linkerOutput); if (m.matches()) { - OS os = OS.getCurrent(); - String libPrefix = os == OS.WINDOWS ? "" : "lib"; - String libSuffix = os == OS.WINDOWS ? ".lib" : ".a"; + boolean targetWindows = Platform.includedIn(Platform.WINDOWS.class); + String libPrefix = targetWindows ? "" : "lib"; + String libSuffix = targetWindows ? ".lib" : ".a"; potentialCauses.add(String.format("It appears as though %s%s%s is missing. Please install it.", libPrefix, m.group(1), libSuffix)); } return potentialCauses; @@ -455,7 +455,7 @@ public LinkerInvocation write(DebugContext debug, Path outputDirectory, Path tem Path imagePath = inv.getOutputFile(); BuildArtifacts.singleton().add(imageKind.isExecutable ? ArtifactType.EXECUTABLE : ArtifactType.SHARED_LIB, imagePath); - if (OS.getCurrent() == OS.WINDOWS && !imageKind.isExecutable) { + if (Platform.includedIn(Platform.WINDOWS.class) && !imageKind.isExecutable) { /* Provide an import library for the built shared library. */ String importLib = imageName + ".lib"; Path importLibPath = imagePath.resolveSibling(importLib); @@ -465,7 +465,7 @@ public LinkerInvocation write(DebugContext debug, Path outputDirectory, Path tem if (SubstrateOptions.GenerateDebugInfo.getValue() > 0) { BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, SubstrateOptions.getDebugInfoSourceCacheRoot()); - if (OS.getCurrent() == OS.WINDOWS) { + if (Platform.includedIn(Platform.WINDOWS.class)) { BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, imagePath.resolveSibling(imageName + ".pdb")); } else { BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, imagePath); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrFeature.java index 6b5896910a6a..8f4379cf8892 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrFeature.java @@ -31,12 +31,12 @@ import java.util.Set; import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.hosted.RuntimeClassInitialization; import org.graalvm.nativeimage.hosted.RuntimeReflection; import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport; -import com.oracle.svm.core.OS; import com.oracle.svm.core.VMInspectionOptions; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.annotate.Uninterruptible; @@ -78,7 +78,7 @@ /** * Provides basic JFR support. As this support is both platform-dependent and JDK-specific, the - * current support is limited to JDK 11 on Linux/MacOS. + * current support is limited to Linux & MacOS. * * There are two different kinds of JFR events: *
    @@ -141,7 +141,7 @@ public boolean isInConfiguration(IsInConfigurationAccess access) { } private static boolean osSupported() { - return OS.getCurrent() == OS.LINUX || OS.getCurrent() == OS.DARWIN; + return Platform.includedIn(Platform.LINUX.class) || Platform.includedIn(Platform.DARWIN.class); } /** diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java index 14d76ac1dba5..aab5670bc6ad 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java @@ -1005,7 +1005,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec * mode, we eliminate native methods that depend on 'awt_xawt' library in the call-tree. */ private static void registerAWTPlugins(InvocationPlugins plugins) { - if (OS.getCurrent() == OS.LINUX) { + if (Platform.includedIn(Platform.LINUX.class)) { Registration r = new Registration(plugins, GraphicsEnvironment.class); r.register0("isHeadless", new InvocationPlugin() { @SuppressWarnings("unchecked") diff --git a/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/hosted/JNIJavaCallWrapperMethod.java b/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/hosted/JNIJavaCallWrapperMethod.java index 461bde2ff962..e0d895837741 100644 --- a/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/hosted/JNIJavaCallWrapperMethod.java +++ b/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/hosted/JNIJavaCallWrapperMethod.java @@ -71,7 +71,6 @@ import com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess; import com.oracle.graal.pointsto.meta.HostedProviders; -import com.oracle.svm.core.OS; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.graal.nodes.CEntryPointEnterNode; import com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode; @@ -419,8 +418,8 @@ private List> loadAndUnboxArguments(JNIGraphKi int count = invokeSignature.getParameterCount(false); // Windows and iOS CallVariant.VA_LIST is identical to CallVariant.ARRAY // iOS CallVariant.VARARGS stores values as an array on the stack - if ((OS.getCurrent() == OS.DARWIN && Platform.includedIn(Platform.AARCH64.class) && (callVariant == CallVariant.VARARGS || callVariant == CallVariant.VA_LIST)) || - (OS.getCurrent() == OS.WINDOWS && callVariant == CallVariant.VA_LIST) || callVariant == CallVariant.ARRAY) { + if ((Platform.includedIn(Platform.DARWIN_AARCH64.class) && (callVariant == CallVariant.VARARGS || callVariant == CallVariant.VA_LIST)) || + (Platform.includedIn(Platform.WINDOWS.class) && callVariant == CallVariant.VA_LIST) || callVariant == CallVariant.ARRAY) { ResolvedJavaType elementType = metaAccess.lookupJavaType(JNIValue.class); int elementSize = SizeOf.get(JNIValue.class); ValueNode array;