From 1709fc6c9db0f2ddf17da0dd857fff2f22902640 Mon Sep 17 00:00:00 2001 From: Danilo Ansaloni Date: Thu, 18 Aug 2022 11:04:25 +0200 Subject: [PATCH 1/8] DualStackPlainDatagramSocketImpl removed in JDK 19 for Windows [JDK-8253119]. --- .../src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java index 876fdcd559a5..69127313c2d8 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java @@ -69,11 +69,10 @@ public void duringSetup(DuringSetupAccess a) { "java.net.DefaultDatagramSocketImplFactory"); } if (isWindows()) { - rerunClassInit(a, "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl"); if (JavaVersionUtil.JAVA_SPEC <= 17) { /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ /* Caches networking properties. */ - rerunClassInit(a, "java.net.PlainSocketImpl"); + rerunClassInit(a, "java.net.PlainSocketImpl", "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl"); } } else { assert isPosix(); From 12b01d02a8904ee85121227f03260f62a588e464 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 16 Aug 2022 13:29:15 +0200 Subject: [PATCH 2/8] svm: reset LambdaForm#transformCache --- .../Target_java_lang_invoke_LambdaForm.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_LambdaForm.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_LambdaForm.java index d012c7162e89..a1869fdff60a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_LambdaForm.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_LambdaForm.java @@ -24,11 +24,16 @@ */ package com.oracle.svm.core.methodhandles; +import org.graalvm.nativeimage.hosted.FieldValueTransformer; + import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.invoke.Target_java_lang_invoke_MemberName; +import com.oracle.svm.core.jdk.JDK19OrLater; +import com.oracle.svm.util.ReflectionUtil; @TargetClass(className = "java.lang.invoke.LambdaForm") public final class Target_java_lang_invoke_LambdaForm { @@ -36,6 +41,10 @@ public final class Target_java_lang_invoke_LambdaForm { @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// Target_java_lang_invoke_MemberName vmentry; + @TargetElement(onlyWith = JDK19OrLater.class)// + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = LambdaFormCacheTransformer.class)// + volatile Object transformCache; + @Alias native String lambdaName(); @@ -64,6 +73,19 @@ private boolean forceInterpretation() { native Object interpretWithArguments(Object... argumentValues) throws Throwable; } +final class LambdaFormCacheTransformer implements FieldValueTransformer { + + @Override + public Object transform(Object receiver, Object originalValue) { + Class lambdaFormClass = ReflectionUtil.lookupClass(false, "java.lang.invoke.LambdaForm"); + if (lambdaFormClass.isInstance(originalValue)) { + // Stores the original LambdaForm for a customized one. + return originalValue; + } + return null; + } +} + @TargetClass(className = "java.lang.invoke.LambdaForm", innerClass = "NamedFunction") final class Target_java_lang_invoke_LambdaForm_NamedFunction { @Alias From 97203ef59e58af8434c7b92adf30378d46b9c758 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 22 Aug 2022 16:07:01 +0200 Subject: [PATCH 3/8] svm: should not reach Continuation.pin/unpin if Loom is not enabled --- .../thread/Target_jdk_internal_vm_Continuation.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java index 573dc95e5f6a..4544b4936635 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java @@ -55,6 +55,16 @@ final class Target_jdk_internal_vm_Continuation__WithoutLoom { static boolean yield(Target_jdk_internal_vm_ContinuationScope scope) { throw VMError.shouldNotReachHere(); } + + @Substitute + static void pin() { + throw VMError.shouldNotReachHere(); + } + + @Substitute + static void unpin() { + throw VMError.shouldNotReachHere(); + } } @TargetClass(className = "Continuation", classNameProvider = Package_jdk_internal_vm_helper.class, onlyWith = LoomJDK.class) From e14beb4fac8e80370be244f33e0942ceec085b3b Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 17 Aug 2022 10:28:43 +0000 Subject: [PATCH 4/8] svm: reset LambdaForm#transformCache on all JDK versions --- .../core/methodhandles/Target_java_lang_invoke_LambdaForm.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_LambdaForm.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_LambdaForm.java index a1869fdff60a..aa5a47e7fae2 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_LambdaForm.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_LambdaForm.java @@ -30,9 +30,7 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.invoke.Target_java_lang_invoke_MemberName; -import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.util.ReflectionUtil; @TargetClass(className = "java.lang.invoke.LambdaForm") @@ -41,7 +39,6 @@ public final class Target_java_lang_invoke_LambdaForm { @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// Target_java_lang_invoke_MemberName vmentry; - @TargetElement(onlyWith = JDK19OrLater.class)// @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = LambdaFormCacheTransformer.class)// volatile Object transformCache; From 4b0375327481581a666ff8caaa563feee31ffc93 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 19 Aug 2022 11:12:15 +0200 Subject: [PATCH 5/8] svm: only register valid services [GR-40544] --- .../oracle/svm/hosted/SecurityServicesFeature.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java index c4312bf066b2..b318f3d8dfa6 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java @@ -612,12 +612,23 @@ private static Map> computeAvailableServices() { Map> availableServices = new HashMap<>(); for (Provider provider : Security.getProviders()) { for (Service s : provider.getServices()) { - availableServices.computeIfAbsent(s.getType(), t -> new HashSet<>()).add(s); + if (isValid(s)) { + availableServices.computeIfAbsent(s.getType(), t -> new HashSet<>()).add(s); + } } } return availableServices; } + /** + * Check is service is valid. See {@code java.security.Provider.Service#isValid()}. + * + * Presumably, this is only needed due to an upstream bug introduced in JDK 19 [GR-40544]. + */ + private static boolean isValid(Service s) { + return (s.getType() != null) && (s.getAlgorithm() != null) && (s.getClassName() != null); + } + /** * Return a Function which given the serviceType as a String will return the corresponding * constructor parameter Class, or null. From 69eb739ccb3aea2a1d3d7bd3af27b96a69f554be Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 22 Aug 2022 16:24:32 +0200 Subject: [PATCH 6/8] svm: CKeyStore#loadKeysOrCertificateChains signature changed in JDK 19 --- .../com/oracle/svm/hosted/SecurityServicesFeature.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java index c4312bf066b2..cb7f49f478c9 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java @@ -462,8 +462,13 @@ private static void registerSunMSCAPIConfig(BeforeAnalysisAccess a) { "java.security.KeyException", "java.security.KeyStoreException", "java.security.ProviderException", "java.security.SignatureException", "java.lang.OutOfMemoryError"); - a.registerReachabilityHandler(SecurityServicesFeature::registerLoadKeysOrCertificateChains, - method(a, "sun.security.mscapi.CKeyStore", "loadKeysOrCertificateChains", String.class)); + if (JavaVersionUtil.JAVA_SPEC >= 19) { + a.registerReachabilityHandler(SecurityServicesFeature::registerLoadKeysOrCertificateChains, + method(a, "sun.security.mscapi.CKeyStore", "loadKeysOrCertificateChains", String.class, int.class)); + } else { + a.registerReachabilityHandler(SecurityServicesFeature::registerLoadKeysOrCertificateChains, + method(a, "sun.security.mscapi.CKeyStore", "loadKeysOrCertificateChains", String.class)); + } a.registerReachabilityHandler(SecurityServicesFeature::registerGenerateCKeyPair, method(a, "sun.security.mscapi.CKeyPairGenerator$RSA", "generateCKeyPair", String.class, int.class, String.class)); a.registerReachabilityHandler(SecurityServicesFeature::registerCPrivateKeyOf, From bf8f477861fb68b3e71dc218feec5607fa1d75c7 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 22 Aug 2022 16:47:08 +0200 Subject: [PATCH 7/8] svm: libextnet available on Windows on JDK 19 --- .../windows/WindowsNativeLibrarySupport.java | 20 +++++++++++++++++- .../svm/core/jni/JNILibraryInitializer.java | 6 ++++++ .../hosted/jdk/JNIRegistrationJavaNet.java | 21 ++++++++++--------- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsNativeLibrarySupport.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsNativeLibrarySupport.java index 992fbd8bb3a6..0e751c203d73 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsNativeLibrarySupport.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsNativeLibrarySupport.java @@ -26,6 +26,7 @@ import java.io.FileDescriptor; +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.type.CCharPointer; @@ -37,17 +38,30 @@ import com.oracle.svm.core.Isolates; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; +import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton; +import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.jdk.JNIPlatformNativeLibrarySupport; import com.oracle.svm.core.jdk.Jvm; import com.oracle.svm.core.jdk.NativeLibrarySupport; import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport; import com.oracle.svm.core.log.Log; -import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton; import com.oracle.svm.core.windows.headers.FileAPI; import com.oracle.svm.core.windows.headers.LibLoaderAPI; import com.oracle.svm.core.windows.headers.WinBase.HMODULE; import com.oracle.svm.core.windows.headers.WinSock; +@AutomaticallyRegisteredFeature +@Platforms(Platform.WINDOWS.class) +class WindowsNativeLibraryFeature implements InternalFeature { + @Override + public void duringSetup(DuringSetupAccess access) { + if (JavaVersionUtil.JAVA_SPEC >= 19) { + NativeLibrarySupport.singleton().preregisterUninitializedBuiltinLibrary("extnet"); + } + } +} + @AutomaticallyRegisteredImageSingleton(PlatformNativeLibrarySupport.class) class WindowsNativeLibrarySupport extends JNIPlatformNativeLibrarySupport { @@ -86,6 +100,10 @@ private static void loadNetLibrary() { } else { NativeLibrarySupport.singleton().registerInitializedBuiltinLibrary("net"); } + if (JavaVersionUtil.JAVA_SPEC >= 19) { + NativeLibrarySupport.singleton().registerInitializedBuiltinLibrary("extnet"); + System.loadLibrary("extnet"); + } } @Override diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNILibraryInitializer.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNILibraryInitializer.java index c94186ca8579..fbb4915d69b4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNILibraryInitializer.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNILibraryInitializer.java @@ -31,6 +31,8 @@ import org.graalvm.collections.EconomicMap; import org.graalvm.collections.Equivalence; +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; +import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.c.function.CFunctionPointer; import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer; import org.graalvm.nativeimage.c.type.VoidPointer; @@ -85,6 +87,10 @@ public boolean fillCGlobalDataMap(Collection staticLibNames) { // TODO: This check should be removed when all static libs will have JNI_OnLoad function ArrayList localStaticLibNames = new ArrayList<>(staticLibNames); localStaticLibNames.retainAll(libsWithOnLoad); + if (JavaVersionUtil.JAVA_SPEC >= 19 && Platform.includedIn(Platform.WINDOWS.class)) { + /* libextnet on Windows (introduced in Java 19) does not contain an OnLoad method. */ + localStaticLibNames.remove("extnet"); + } boolean mapIsChanged = false; for (String libName : localStaticLibNames) { if (!onLoadCGlobalDataMap.containsKey(libName)) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java index 69127313c2d8..8bb4c668979b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java @@ -68,14 +68,12 @@ public void duringSetup(DuringSetupAccess a) { /* Caches networking properties. */ "java.net.DefaultDatagramSocketImplFactory"); } - if (isWindows()) { - if (JavaVersionUtil.JAVA_SPEC <= 17) { - /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ - /* Caches networking properties. */ - rerunClassInit(a, "java.net.PlainSocketImpl", "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl"); - } + if (isWindows() && JavaVersionUtil.JAVA_SPEC < 19) { + /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ + /* Caches networking properties. */ + rerunClassInit(a, "java.net.PlainSocketImpl", "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl"); } else { - assert isPosix(); + assert isPosix() || JavaVersionUtil.JAVA_SPEC >= 19; if (JavaVersionUtil.JAVA_SPEC <= 17) { /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ rerunClassInit(a, "java.net.PlainDatagramSocketImpl", "java.net.PlainSocketImpl"); @@ -91,8 +89,8 @@ public void duringSetup(DuringSetupAccess a) { if (hasPlatformSocketOptions) { /* - * The libextnet was actually introduced in Java 9, but the support for Linux and - * Darwin was added later in Java 10 and Java 11 respectively. + * The libextnet was actually introduced in Java 9, but the support for Linux, + * Darwin and Windows was added later in Java 10, Java 11 and Java 19 respectively. */ rerunClassInit(a, "jdk.net.ExtendedSocketOptions", "jdk.net.ExtendedSocketOptions$PlatformSocketOptions"); /* @@ -188,6 +186,8 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { a.registerReachabilityHandler(JNIRegistrationJavaNet::registerExtendedOptionsImplInit, method(a, "sun.net.ExtendedOptionsImpl", "init")); } + } + if (isPosix() || (isWindows() && JavaVersionUtil.JAVA_SPEC >= 19)) { if (hasPlatformSocketOptions) { /* Support for the libextnet. */ a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlatformSocketOptionsCreate, @@ -324,7 +324,8 @@ private static void registerPlatformSocketOptionsCreate(DuringAnalysisAccess a) } else if (isDarwin()) { implClassName = "jdk.net.MacOSXSocketOptions"; } else { - throw VMError.shouldNotReachHere("Unexpected platform"); + VMError.guarantee(isWindows(), "Unexpected platform"); + implClassName = "jdk.net.WindowsSocketOptions"; } RuntimeReflection.register(clazz(a, implClassName)); RuntimeReflection.register(constructor(a, implClassName)); From 1c96e4eb15690e4cefb8a0d3928e8db5820d7b71 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 24 Aug 2022 16:34:55 +0200 Subject: [PATCH 8/8] svm: simplify JNIRegistrationJavaNet wrt JDK version and platfrom --- .../hosted/jdk/JNIRegistrationJavaNet.java | 85 +++++-------------- 1 file changed, 23 insertions(+), 62 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java index 8bb4c668979b..24ea9c561fdf 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java @@ -50,63 +50,40 @@ @Platforms({InternalPlatform.PLATFORM_JNI.class}) @AutomaticallyRegisteredFeature class JNIRegistrationJavaNet extends JNIRegistrationUtil implements InternalFeature { - - private boolean hasExtendedOptionsImpl; private boolean hasPlatformSocketOptions; @Override public void duringSetup(DuringSetupAccess a) { - hasExtendedOptionsImpl = a.findClassByName("sun.net.ExtendedOptionsImpl") != null; - hasPlatformSocketOptions = a.findClassByName("jdk.net.ExtendedSocketOptions$PlatformSocketOptions") != null; - + /* jdk.net.ExtendedSocketOptions is only available if the jdk.net module is loaded. */ + this.hasPlatformSocketOptions = a.findClassByName("jdk.net.ExtendedSocketOptions$PlatformSocketOptions") != null; rerunClassInit(a, "java.net.DatagramPacket", "java.net.InetAddress", "java.net.NetworkInterface", /* Stores a default SSLContext in a static field. */ "javax.net.ssl.SSLContext"); - if (JavaVersionUtil.JAVA_SPEC <= 17) { + if (JavaVersionUtil.JAVA_SPEC < 19) { /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ rerunClassInit(a, "java.net.SocketInputStream", "java.net.SocketOutputStream", /* Caches networking properties. */ "java.net.DefaultDatagramSocketImplFactory"); - } - if (isWindows() && JavaVersionUtil.JAVA_SPEC < 19) { - /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ - /* Caches networking properties. */ - rerunClassInit(a, "java.net.PlainSocketImpl", "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl"); - } else { - assert isPosix() || JavaVersionUtil.JAVA_SPEC >= 19; - if (JavaVersionUtil.JAVA_SPEC <= 17) { - /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ + if (isWindows()) { + /* Caches networking properties. */ + rerunClassInit(a, "java.net.PlainSocketImpl", "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl"); + } else { + assert isPosix(); rerunClassInit(a, "java.net.PlainDatagramSocketImpl", "java.net.PlainSocketImpl"); - } - if (hasExtendedOptionsImpl) { - rerunClassInit(a, "sun.net.ExtendedOptionsImpl"); - } - - if (JavaVersionUtil.JAVA_SPEC <= 17) { - /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ rerunClassInit(a, "java.net.AbstractPlainDatagramSocketImpl", "java.net.AbstractPlainSocketImpl"); } + } - if (hasPlatformSocketOptions) { - /* - * The libextnet was actually introduced in Java 9, but the support for Linux, - * Darwin and Windows was added later in Java 10, Java 11 and Java 19 respectively. - */ - rerunClassInit(a, "jdk.net.ExtendedSocketOptions", "jdk.net.ExtendedSocketOptions$PlatformSocketOptions"); - /* - * Different JDK versions are not consistent about the "ext" in the package name. We - * need to support both variants. - */ - if (a.findClassByName("sun.net.ext.ExtendedSocketOptions") != null) { - rerunClassInit(a, "sun.net.ext.ExtendedSocketOptions"); - } else { - rerunClassInit(a, "sun.net.ExtendedSocketOptions"); - } - } - if (isDarwin()) { - /* Caches the default interface. */ - rerunClassInit(a, "java.net.DefaultInterface"); - } + if (this.hasPlatformSocketOptions && (isPosix() || JavaVersionUtil.JAVA_SPEC >= 19)) { + /* + * The libextnet was actually introduced in Java 9, but the support for Linux, Darwin + * and Windows was added later in Java 10, Java 11 and Java 19 respectively. + */ + rerunClassInit(a, "jdk.net.ExtendedSocketOptions", "jdk.net.ExtendedSocketOptions$PlatformSocketOptions", "sun.net.ext.ExtendedSocketOptions"); + } + if (isDarwin()) { + /* Caches the default interface. */ + rerunClassInit(a, "java.net.DefaultInterface"); } } @@ -181,18 +158,10 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { method(a, "java.net.PlainSocketImpl", "localAddress", int.class, clazz(a, "java.net.InetAddressContainer"))); } } - if (isPosix()) { - if (hasExtendedOptionsImpl) { - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerExtendedOptionsImplInit, - method(a, "sun.net.ExtendedOptionsImpl", "init")); - } - } - if (isPosix() || (isWindows() && JavaVersionUtil.JAVA_SPEC >= 19)) { - if (hasPlatformSocketOptions) { - /* Support for the libextnet. */ - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlatformSocketOptionsCreate, - method(a, "jdk.net.ExtendedSocketOptions$PlatformSocketOptions", "create")); - } + if (this.hasPlatformSocketOptions && (isPosix() || JavaVersionUtil.JAVA_SPEC >= 19)) { + /* Support for the libextnet. */ + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlatformSocketOptionsCreate, + method(a, "jdk.net.ExtendedSocketOptions$PlatformSocketOptions", "create")); } a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDefaultProxySelectorInit, method(a, "sun.net.spi.DefaultProxySelector", "init")); @@ -309,14 +278,6 @@ private static void registerDualStackPlainSocketImplLocalAddress(DuringAnalysisA RuntimeJNIAccess.register(fields(a, "java.net.InetAddressContainer", "addr")); } - private static void registerExtendedOptionsImplInit(DuringAnalysisAccess a) { - RuntimeJNIAccess.register(clazz(a, "jdk.net.SocketFlow")); - RuntimeJNIAccess.register(fields(a, "jdk.net.SocketFlow", "status", "priority", "bandwidth")); - - RuntimeJNIAccess.register(clazz(a, "jdk.net.SocketFlow$Status")); - RuntimeJNIAccess.register(fields(a, "jdk.net.SocketFlow$Status", "NO_STATUS", "OK", "NO_PERMISSION", "NOT_CONNECTED", "NOT_SUPPORTED", "ALREADY_CREATED", "IN_PROGRESS", "OTHER")); - } - private static void registerPlatformSocketOptionsCreate(DuringAnalysisAccess a) { String implClassName; if (isLinux()) {