From 903ad1d05e0edc14d8077ea3a89f237911bed668 Mon Sep 17 00:00:00 2001 From: Gwenneg Lepage Date: Thu, 5 Mar 2020 01:02:50 +0100 Subject: [PATCH] Initialize sun.nio.ch.Iocp at runtime on Windows with JDK 11 --- .../core/runtime/graal/JdkSubstitutions.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/graal/JdkSubstitutions.java b/extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/graal/JdkSubstitutions.java index 4e030b0393148..62fd2e6cb1667 100644 --- a/extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/graal/JdkSubstitutions.java +++ b/extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/graal/JdkSubstitutions.java @@ -2,9 +2,11 @@ import java.io.IOException; import java.net.URL; +import java.nio.channels.spi.AsynchronousChannelProvider; import java.util.function.Function; import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.InjectAccessors; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.jdk.JDK11OrLater; @@ -88,6 +90,47 @@ public String apply(TargetClass annotation) { } } +@Substitute +@TargetClass(className = "sun.nio.ch.WindowsAsynchronousFileChannelImpl", innerClass = "DefaultIocpHolder", onlyWith = JDK11OrLater.class) +final class Target_sun_nio_ch_WindowsAsynchronousFileChannelImpl_DefaultIocpHolder { + + @Alias + @InjectAccessors(DefaultIocpAccessor.class) + static Target_sun_nio_ch_Iocp defaultIocp; +} + +@TargetClass(className = "sun.nio.ch.Iocp", onlyWith = JDK11OrLater.class) +final class Target_sun_nio_ch_Iocp { + + @Alias + Target_sun_nio_ch_Iocp(AsynchronousChannelProvider provider, Target_sun_nio_ch_ThreadPool pool) throws IOException { + } + + @Alias + Target_sun_nio_ch_Iocp start() { + return null; + } +} + +@TargetClass(className = "sun.nio.ch.ThreadPool", onlyWith = JDK11OrLater.class) +final class Target_sun_nio_ch_ThreadPool { + + @Alias + static Target_sun_nio_ch_ThreadPool createDefault() { + return null; + } +} + +final class DefaultIocpAccessor { + static Target_sun_nio_ch_Iocp get() { + try { + return new Target_sun_nio_ch_Iocp(null, Target_sun_nio_ch_ThreadPool.createDefault()).start(); + } catch (IOException ioe) { + throw new InternalError(ioe); + } + } +} + class JdkSubstitutions { }