Skip to content

Commit ab8c949

Browse files
committed
svm: simplify JNIRegistrationJavaNet wrt JDK version and platfrom
1 parent 23632eb commit ab8c949

File tree

1 file changed

+23
-62
lines changed

1 file changed

+23
-62
lines changed

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

Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -50,63 +50,40 @@
5050
@Platforms({InternalPlatform.PLATFORM_JNI.class})
5151
@AutomaticFeature
5252
class JNIRegistrationJavaNet extends JNIRegistrationUtil implements Feature {
53-
54-
private boolean hasExtendedOptionsImpl;
5553
private boolean hasPlatformSocketOptions;
5654

5755
@Override
5856
public void duringSetup(DuringSetupAccess a) {
59-
hasExtendedOptionsImpl = a.findClassByName("sun.net.ExtendedOptionsImpl") != null;
60-
hasPlatformSocketOptions = a.findClassByName("jdk.net.ExtendedSocketOptions$PlatformSocketOptions") != null;
61-
57+
/* jdk.net.ExtendedSocketOptions is only available if the jdk.net module is loaded. */
58+
this.hasPlatformSocketOptions = a.findClassByName("jdk.net.ExtendedSocketOptions$PlatformSocketOptions") != null;
6259
rerunClassInit(a, "java.net.DatagramPacket", "java.net.InetAddress", "java.net.NetworkInterface",
6360
/* Stores a default SSLContext in a static field. */
6461
"javax.net.ssl.SSLContext");
65-
if (JavaVersionUtil.JAVA_SPEC <= 17) {
62+
if (JavaVersionUtil.JAVA_SPEC < 19) {
6663
/* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */
6764
rerunClassInit(a, "java.net.SocketInputStream", "java.net.SocketOutputStream",
6865
/* Caches networking properties. */
6966
"java.net.DefaultDatagramSocketImplFactory");
70-
}
71-
if (isWindows() && JavaVersionUtil.JAVA_SPEC < 19) {
72-
/* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */
73-
/* Caches networking properties. */
74-
rerunClassInit(a, "java.net.PlainSocketImpl", "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl");
75-
} else {
76-
assert isPosix() || JavaVersionUtil.JAVA_SPEC >= 19;
77-
if (JavaVersionUtil.JAVA_SPEC <= 17) {
78-
/* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */
67+
if (isWindows()) {
68+
/* Caches networking properties. */
69+
rerunClassInit(a, "java.net.PlainSocketImpl", "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl");
70+
} else {
71+
assert isPosix();
7972
rerunClassInit(a, "java.net.PlainDatagramSocketImpl", "java.net.PlainSocketImpl");
80-
}
81-
if (hasExtendedOptionsImpl) {
82-
rerunClassInit(a, "sun.net.ExtendedOptionsImpl");
83-
}
84-
85-
if (JavaVersionUtil.JAVA_SPEC <= 17) {
86-
/* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */
8773
rerunClassInit(a, "java.net.AbstractPlainDatagramSocketImpl", "java.net.AbstractPlainSocketImpl");
8874
}
75+
}
8976

90-
if (hasPlatformSocketOptions) {
91-
/*
92-
* The libextnet was actually introduced in Java 9, but the support for Linux,
93-
* Darwin and Windows was added later in Java 10, Java 11 and Java 19 respectively.
94-
*/
95-
rerunClassInit(a, "jdk.net.ExtendedSocketOptions", "jdk.net.ExtendedSocketOptions$PlatformSocketOptions");
96-
/*
97-
* Different JDK versions are not consistent about the "ext" in the package name. We
98-
* need to support both variants.
99-
*/
100-
if (a.findClassByName("sun.net.ext.ExtendedSocketOptions") != null) {
101-
rerunClassInit(a, "sun.net.ext.ExtendedSocketOptions");
102-
} else {
103-
rerunClassInit(a, "sun.net.ExtendedSocketOptions");
104-
}
105-
}
106-
if (isDarwin()) {
107-
/* Caches the default interface. */
108-
rerunClassInit(a, "java.net.DefaultInterface");
109-
}
77+
if (this.hasPlatformSocketOptions && (isPosix() || JavaVersionUtil.JAVA_SPEC >= 19)) {
78+
/*
79+
* The libextnet was actually introduced in Java 9, but the support for Linux, Darwin
80+
* and Windows was added later in Java 10, Java 11 and Java 19 respectively.
81+
*/
82+
rerunClassInit(a, "jdk.net.ExtendedSocketOptions", "jdk.net.ExtendedSocketOptions$PlatformSocketOptions", "sun.net.ext.ExtendedSocketOptions");
83+
}
84+
if (isDarwin()) {
85+
/* Caches the default interface. */
86+
rerunClassInit(a, "java.net.DefaultInterface");
11087
}
11188
}
11289

@@ -181,18 +158,10 @@ public void beforeAnalysis(BeforeAnalysisAccess a) {
181158
method(a, "java.net.PlainSocketImpl", "localAddress", int.class, clazz(a, "java.net.InetAddressContainer")));
182159
}
183160
}
184-
if (isPosix()) {
185-
if (hasExtendedOptionsImpl) {
186-
a.registerReachabilityHandler(JNIRegistrationJavaNet::registerExtendedOptionsImplInit,
187-
method(a, "sun.net.ExtendedOptionsImpl", "init"));
188-
}
189-
}
190-
if (isPosix() || (isWindows() && JavaVersionUtil.JAVA_SPEC >= 19)) {
191-
if (hasPlatformSocketOptions) {
192-
/* Support for the libextnet. */
193-
a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlatformSocketOptionsCreate,
194-
method(a, "jdk.net.ExtendedSocketOptions$PlatformSocketOptions", "create"));
195-
}
161+
if (this.hasPlatformSocketOptions && (isPosix() || JavaVersionUtil.JAVA_SPEC >= 19)) {
162+
/* Support for the libextnet. */
163+
a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlatformSocketOptionsCreate,
164+
method(a, "jdk.net.ExtendedSocketOptions$PlatformSocketOptions", "create"));
196165
}
197166

198167
a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDefaultProxySelectorInit, method(a, "sun.net.spi.DefaultProxySelector", "init"));
@@ -309,14 +278,6 @@ private static void registerDualStackPlainSocketImplLocalAddress(DuringAnalysisA
309278
RuntimeJNIAccess.register(fields(a, "java.net.InetAddressContainer", "addr"));
310279
}
311280

312-
private static void registerExtendedOptionsImplInit(DuringAnalysisAccess a) {
313-
RuntimeJNIAccess.register(clazz(a, "jdk.net.SocketFlow"));
314-
RuntimeJNIAccess.register(fields(a, "jdk.net.SocketFlow", "status", "priority", "bandwidth"));
315-
316-
RuntimeJNIAccess.register(clazz(a, "jdk.net.SocketFlow$Status"));
317-
RuntimeJNIAccess.register(fields(a, "jdk.net.SocketFlow$Status", "NO_STATUS", "OK", "NO_PERMISSION", "NOT_CONNECTED", "NOT_SUPPORTED", "ALREADY_CREATED", "IN_PROGRESS", "OTHER"));
318-
}
319-
320281
private static void registerPlatformSocketOptionsCreate(DuringAnalysisAccess a) {
321282
String implClassName;
322283
if (isLinux()) {

0 commit comments

Comments
 (0)