Skip to content

Commit 3c1b66f

Browse files
committed
[GR-63031] Enable -H:Preserve=all for macOS.
PullRequest: graal/20533
2 parents 61327a4 + fd96780 commit 3c1b66f

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java

+27
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.graalvm.nativeimage.StackValue;
3636

3737
import com.oracle.svm.core.Uninterruptible;
38+
import com.oracle.svm.core.annotate.Delete;
3839
import com.oracle.svm.core.annotate.Substitute;
3940
import com.oracle.svm.core.annotate.TargetClass;
4041
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
@@ -117,6 +118,32 @@ long nanoTime() {
117118
}
118119
}
119120

121+
/**
122+
* Native functions don't exist on Darwin because this whole class is used, and should exist, only
123+
* on Linux. See <code>java.util.prefs.Preferences#factory</code>.
124+
*/
125+
@TargetClass(className = "java.util.prefs.FileSystemPreferences")
126+
final class Target_java_util_prefs_FileSystemPreferences {
127+
@Delete
128+
private static native int[] lockFile0(String fileName, int permission, boolean shared);
129+
130+
@Delete
131+
private static native int unlockFile0(int lockHandle);
132+
133+
@Delete
134+
private static native int chmod(String fileName, int permission);
135+
}
136+
137+
/**
138+
* Not used in native image and has linker errors with XCode 13. Can be removed in the future when
139+
* XCode 14 becomes omnipresent.
140+
*/
141+
@TargetClass(className = "sun.util.locale.provider.HostLocaleProviderAdapterImpl")
142+
final class Target_sun_util_locale_provider_HostLocaleProviderAdapterImpl {
143+
@Delete
144+
private static native String getDefaultLocale(int cat);
145+
}
146+
120147
/** Dummy class to have a class with the file's name. */
121148
public final class DarwinSubstitutions {
122149
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.function.BooleanSupplier;
4242
import java.util.stream.Stream;
4343

44+
import com.oracle.svm.core.util.BasedOnJDKFile;
4445
import org.graalvm.nativeimage.Platform;
4546
import org.graalvm.nativeimage.Platforms;
4647
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
@@ -355,6 +356,14 @@ final class Target_java_lang_System {
355356
@Alias private static PrintStream err;
356357
@Alias private static InputStream in;
357358

359+
/**
360+
* Pulls in a native library unnecessarily. All natives are already substituted.
361+
*/
362+
@Substitute
363+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/java.base/share/native/libjava/System.c#L39-L53")
364+
private static void registerNatives() {
365+
}
366+
358367
@Substitute
359368
private static void setIn(InputStream is) {
360369
in = is;

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaUtilSubstitutions.java

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import com.oracle.svm.core.SubstrateUtil;
3838
import com.oracle.svm.core.annotate.Alias;
39+
import com.oracle.svm.core.annotate.Delete;
3940
import com.oracle.svm.core.annotate.Inject;
4041
import com.oracle.svm.core.annotate.InjectAccessors;
4142
import com.oracle.svm.core.annotate.RecomputeFieldValue;
@@ -45,6 +46,8 @@
4546
import com.oracle.svm.core.util.VMError;
4647
import com.oracle.svm.util.ReflectionUtil;
4748

49+
import jdk.internal.util.SystemProps;
50+
4851
/*
4952
* Lazily initialized cache fields of collection classes need to be reset. They are not needed in
5053
* 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() {
361364
}
362365
}
363366

367+
/**
368+
* Currently unsupported in Native Image because our system-property support works completely
369+
* differently than the one in HotSpot.
370+
*/
371+
@TargetClass(value = SystemProps.Raw.class)
372+
final class Target_jdk_internal_util_SystemProps_Raw {
373+
@Delete
374+
private static native String[] vmProperties();
375+
376+
@Delete
377+
private static native String[] platformProperties();
378+
}
379+
364380
/** Dummy class to have a class with the file's name. */
365381
public final class JavaUtilSubstitutions {
366382
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,13 @@ public static void checkName(BigBang bb, AnalysisType type) {
17771777
checkName(bb, null, format);
17781778
}
17791779

1780-
private static final Set<String> CHECK_NAME_EXCEPTIONS = Set.of("java.awt.Cursor.DOT_HOTSPOT_SUFFIX");
1780+
/**
1781+
* These are legit elements from the JDK that have hotspot in their name.
1782+
*/
1783+
private static final Set<String> HOTSPOT_IN_NAME_EXCEPTIONS = Set.of(
1784+
"java.awt.Cursor.DOT_HOTSPOT_SUFFIX",
1785+
"sun.lwawt.macosx.CCustomCursor.fHotspot",
1786+
"sun.lwawt.macosx.CCustomCursor.getHotSpot()");
17811787

17821788
private static void checkName(BigBang bb, AnalysisMethod method, String format) {
17831789
/*
@@ -1790,8 +1796,11 @@ private static void checkName(BigBang bb, AnalysisMethod method, String format)
17901796
if (lformat.contains("hosted")) {
17911797
report(bb, format, method, "Hosted element used at run time: " + format + ".");
17921798
} else if (!lformat.startsWith("jdk.internal") && lformat.contains("hotspot")) {
1793-
if (!CHECK_NAME_EXCEPTIONS.contains(format)) {
1794-
report(bb, format, method, "HotSpot element used at run time: " + format + ".");
1799+
if (!HOTSPOT_IN_NAME_EXCEPTIONS.contains(format)) {
1800+
report(bb, format, method, "Element with HotSpot in its name used at run time: " + format + System.lineSeparator() +
1801+
"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" +
1802+
System.lineSeparator() +
1803+
"If this is HotSpot element that was accidentally included find a way to exclude it from the image.");
17951804
}
17961805
}
17971806
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationPrefs.java

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
7373
if (isDarwin()) {
7474
String darwinSpecificClass = "java.util.prefs.MacOSXPreferencesFile";
7575
initializeAtRunTime(access, darwinSpecificClass);
76+
/* present on Darwin in the JDK */
77+
initializeAtRunTime(access, "java.util.prefs.FileSystemPreferences");
7678
triggers.add(clazz(access, darwinSpecificClass));
7779
}
7880

0 commit comments

Comments
 (0)