From b35ae008f0e84585f37b80dd1861b208ed6fd79a Mon Sep 17 00:00:00 2001 From: Julien Ponge Date: Tue, 2 Apr 2024 12:39:32 +0200 Subject: [PATCH] Fix native compilation for Netty and Mutiny See #39819 and #39788 --- .../mutiny/deployment/MutinyProcessor.java | 10 ---------- extensions/mutiny/runtime/pom.xml | 7 ++++++- .../quarkus/mutiny/runtime/JCToolsSupport.java | 17 +++++++++++++++++ .../netty/deployment/NettyProcessor.java | 2 ++ 4 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 extensions/mutiny/runtime/src/main/java/io/quarkus/mutiny/runtime/JCToolsSupport.java diff --git a/extensions/mutiny/deployment/src/main/java/io/quarkus/mutiny/deployment/MutinyProcessor.java b/extensions/mutiny/deployment/src/main/java/io/quarkus/mutiny/deployment/MutinyProcessor.java index b31d195875253..0802ea01dc861 100644 --- a/extensions/mutiny/deployment/src/main/java/io/quarkus/mutiny/deployment/MutinyProcessor.java +++ b/extensions/mutiny/deployment/src/main/java/io/quarkus/mutiny/deployment/MutinyProcessor.java @@ -1,6 +1,5 @@ package io.quarkus.mutiny.deployment; -import java.util.List; import java.util.Optional; import org.jboss.threads.ContextHandler; @@ -11,7 +10,6 @@ import io.quarkus.deployment.builditem.ContextHandlerBuildItem; import io.quarkus.deployment.builditem.ExecutorBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; -import io.quarkus.deployment.builditem.nativeimage.UnsafeAccessedFieldBuildItem; import io.quarkus.mutiny.runtime.MutinyInfrastructure; public class MutinyProcessor { @@ -33,12 +31,4 @@ public void buildTimeInit(MutinyInfrastructure recorder) { recorder.configureThreadBlockingChecker(); recorder.configureOperatorLogger(); } - - @BuildStep - public List jctoolsUnsafeAccessedFields() { - return List.of( - new UnsafeAccessedFieldBuildItem( - "org.jctools.util.UnsafeRefArrayAccess", - "REF_ELEMENT_SHIFT")); - } } diff --git a/extensions/mutiny/runtime/pom.xml b/extensions/mutiny/runtime/pom.xml index 4d06ca741a099..b688947b2d296 100644 --- a/extensions/mutiny/runtime/pom.xml +++ b/extensions/mutiny/runtime/pom.xml @@ -31,12 +31,17 @@ io.smallrye.reactive mutiny-smallrye-context-propagation + + org.graalvm.sdk + nativeimage + provided + + io.quarkus quarkus-junit5-internal test - org.awaitility awaitility diff --git a/extensions/mutiny/runtime/src/main/java/io/quarkus/mutiny/runtime/JCToolsSupport.java b/extensions/mutiny/runtime/src/main/java/io/quarkus/mutiny/runtime/JCToolsSupport.java new file mode 100644 index 0000000000000..545ff4a017f2d --- /dev/null +++ b/extensions/mutiny/runtime/src/main/java/io/quarkus/mutiny/runtime/JCToolsSupport.java @@ -0,0 +1,17 @@ +package io.quarkus.mutiny.runtime; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.TargetClass; + +class JCToolsSupport { +} + +// Thanks to https://github.com/DataDog/dd-trace-java/pull/6020 +@TargetClass(className = "org.jctools.util.UnsafeRefArrayAccess") +final class Target_org_jctools_util_UnsafeRefArrayAccess { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayIndexShift, declClass = Object[].class) + public static int REF_ELEMENT_SHIFT; +} diff --git a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java index a7d5ae3e2c2a5..4c2741d2092ed 100644 --- a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java +++ b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java @@ -105,6 +105,8 @@ NativeImageConfigBuildItem build( .addRuntimeInitializedClass("io.netty.handler.ssl.ReferenceCountedOpenSslEngine") .addRuntimeInitializedClass("io.netty.handler.ssl.ReferenceCountedOpenSslContext") .addRuntimeInitializedClass("io.netty.handler.ssl.ReferenceCountedOpenSslClientContext") + .addRuntimeInitializedClass("io.netty.handler.ssl.JdkSslServerContext") + .addRuntimeInitializedClass("io.netty.handler.ssl.JdkSslClientContext") .addRuntimeInitializedClass("io.netty.handler.ssl.util.ThreadLocalInsecureRandom") .addRuntimeInitializedClass("io.netty.buffer.ByteBufUtil$HexUtil") .addRuntimeInitializedClass("io.netty.buffer.PooledByteBufAllocator")