diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java
index 1fad619e7211..fe753381be04 100644
--- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java
+++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java
@@ -35,6 +35,7 @@
import org.graalvm.nativeimage.StackValue;
import com.oracle.svm.core.Uninterruptible;
+import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
@@ -117,6 +118,32 @@ long nanoTime() {
}
}
+/**
+ * Native functions don't exist on Darwin because this whole class is used, and should exist, only
+ * on Linux. See java.util.prefs.Preferences#factory
.
+ */
+@TargetClass(className = "java.util.prefs.FileSystemPreferences")
+final class Target_java_util_prefs_FileSystemPreferences {
+ @Delete
+ private static native int[] lockFile0(String fileName, int permission, boolean shared);
+
+ @Delete
+ private static native int unlockFile0(int lockHandle);
+
+ @Delete
+ private static native int chmod(String fileName, int permission);
+}
+
+/**
+ * Not used in native image and has linker errors with XCode 13. Can be removed in the future when
+ * XCode 14 becomes omnipresent.
+ */
+@TargetClass(className = "sun.util.locale.provider.HostLocaleProviderAdapterImpl")
+final class Target_sun_util_locale_provider_HostLocaleProviderAdapterImpl {
+ @Delete
+ private static native String getDefaultLocale(int cat);
+}
+
/** Dummy class to have a class with the file's name. */
public final class DarwinSubstitutions {
}
diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java
index 6462c78135f9..def6b688c365 100644
--- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java
@@ -41,6 +41,7 @@
import java.util.function.BooleanSupplier;
import java.util.stream.Stream;
+import com.oracle.svm.core.util.BasedOnJDKFile;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
@@ -355,6 +356,14 @@ final class Target_java_lang_System {
@Alias private static PrintStream err;
@Alias private static InputStream in;
+ /**
+ * Pulls in a native library unnecessarily. All natives are already substituted.
+ */
+ @Substitute
+ @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/java.base/share/native/libjava/System.c#L39-L53")
+ private static void registerNatives() {
+ }
+
@Substitute
private static void setIn(InputStream is) {
in = is;
diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaUtilSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaUtilSubstitutions.java
index d85cd9cc1c51..c644eb42b1f3 100644
--- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaUtilSubstitutions.java
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaUtilSubstitutions.java
@@ -36,6 +36,7 @@
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.annotate.Alias;
+import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.Inject;
import com.oracle.svm.core.annotate.InjectAccessors;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
@@ -45,6 +46,8 @@
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.ReflectionUtil;
+import jdk.internal.util.SystemProps;
+
/*
* Lazily initialized cache fields of collection classes need to be reset. They are not needed in
* the image heap because they can always be recomputed. But more importantly, the fields can be
@@ -361,6 +364,19 @@ private static synchronized boolean initializeIsUniprocessor() {
}
}
+/**
+ * Currently unsupported in Native Image because our system-property support works completely
+ * differently than the one in HotSpot.
+ */
+@TargetClass(value = SystemProps.Raw.class)
+final class Target_jdk_internal_util_SystemProps_Raw {
+ @Delete
+ private static native String[] vmProperties();
+
+ @Delete
+ private static native String[] platformProperties();
+}
+
/** Dummy class to have a class with the file's name. */
public final class JavaUtilSubstitutions {
}
diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java
index 82ccffe0ac1f..76ca149fd867 100644
--- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java
+++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java
@@ -1777,7 +1777,13 @@ public static void checkName(BigBang bb, AnalysisType type) {
checkName(bb, null, format);
}
- private static final Set CHECK_NAME_EXCEPTIONS = Set.of("java.awt.Cursor.DOT_HOTSPOT_SUFFIX");
+ /**
+ * These are legit elements from the JDK that have hotspot in their name.
+ */
+ private static final Set HOTSPOT_IN_NAME_EXCEPTIONS = Set.of(
+ "java.awt.Cursor.DOT_HOTSPOT_SUFFIX",
+ "sun.lwawt.macosx.CCustomCursor.fHotspot",
+ "sun.lwawt.macosx.CCustomCursor.getHotSpot()");
private static void checkName(BigBang bb, AnalysisMethod method, String format) {
/*
@@ -1790,8 +1796,11 @@ private static void checkName(BigBang bb, AnalysisMethod method, String format)
if (lformat.contains("hosted")) {
report(bb, format, method, "Hosted element used at run time: " + format + ".");
} else if (!lformat.startsWith("jdk.internal") && lformat.contains("hotspot")) {
- if (!CHECK_NAME_EXCEPTIONS.contains(format)) {
- report(bb, format, method, "HotSpot element used at run time: " + format + ".");
+ if (!HOTSPOT_IN_NAME_EXCEPTIONS.contains(format)) {
+ report(bb, format, method, "Element with HotSpot in its name used at run time: " + format + System.lineSeparator() +
+ "If this is a regular JDK value, and not a HotSpot element that was accidentally included, you can add it to the NativeImageGenerator.HOTSPOT_IN_NAME_EXCEPTIONS" +
+ System.lineSeparator() +
+ "If this is HotSpot element that was accidentally included find a way to exclude it from the image.");
}
}
}
diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationPrefs.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationPrefs.java
index 3079bc3d6900..4fac0eeae654 100644
--- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationPrefs.java
+++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationPrefs.java
@@ -73,6 +73,8 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
if (isDarwin()) {
String darwinSpecificClass = "java.util.prefs.MacOSXPreferencesFile";
initializeAtRunTime(access, darwinSpecificClass);
+ /* present on Darwin in the JDK */
+ initializeAtRunTime(access, "java.util.prefs.FileSystemPreferences");
triggers.add(clazz(access, darwinSpecificClass));
}