Skip to content

Commit

Permalink
svm: simplify JNIRegistrationJavaNet wrt JDK version and platfrom
Browse files Browse the repository at this point in the history
  • Loading branch information
zapster committed Sep 4, 2022
1 parent bf8f477 commit 1c96e4e
Showing 1 changed file with 23 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 1c96e4e

Please sign in to comment.