Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <code>java.util.prefs.Preferences#factory</code>.
*/
@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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,13 @@ public static void checkName(BigBang bb, AnalysisType type) {
checkName(bb, null, format);
}

private static final Set<String> 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<String> 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) {
/*
Expand All @@ -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.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down