Skip to content

Commit b555b1f

Browse files
committed
-H:Preserve=all for MacOS
1 parent 9da64df commit b555b1f

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
import static com.oracle.svm.core.posix.headers.darwin.DarwinTime.NoTransitions.mach_timebase_info;
2929

3030
import java.util.Objects;
31+
import java.util.prefs.Preferences;
3132

3233
import org.graalvm.nativeimage.ImageSingletons;
3334
import org.graalvm.nativeimage.Platform;
3435
import org.graalvm.nativeimage.Platforms;
3536
import org.graalvm.nativeimage.StackValue;
3637

3738
import com.oracle.svm.core.Uninterruptible;
39+
import com.oracle.svm.core.annotate.Delete;
3840
import com.oracle.svm.core.annotate.Substitute;
3941
import com.oracle.svm.core.annotate.TargetClass;
4042
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
@@ -117,6 +119,34 @@ long nanoTime() {
117119
}
118120
}
119121

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

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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 15 additions & 0 deletions
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,18 @@ private static synchronized boolean initializeIsUniprocessor() {
361364
}
362365
}
363366

367+
/**
368+
* Currently unsupported in Native Image.
369+
*/
370+
@TargetClass(value = SystemProps.Raw.class)
371+
final class Target_jdk_internal_util_SystemProps_Raw {
372+
@Delete
373+
private static native String[] vmProperties();
374+
375+
@Delete
376+
private static native String[] platformProperties();
377+
}
378+
364379
/** Dummy class to have a class with the file's name. */
365380
public final class JavaUtilSubstitutions {
366381
}

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

Lines changed: 12 additions & 3 deletions
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

Lines changed: 2 additions & 0 deletions
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)