diff --git a/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcCommonProcessor.java b/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcCommonProcessor.java index 477ad5690a4a6..82d43e7c7919f 100644 --- a/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcCommonProcessor.java +++ b/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcCommonProcessor.java @@ -75,7 +75,8 @@ NativeImageConfigBuildItem nativeImageConfiguration() { .addRuntimeInitializedClass("io.grpc.netty.Utils") .addRuntimeInitializedClass("io.grpc.netty.NettyServerBuilder") .addRuntimeInitializedClass("io.grpc.netty.NettyChannelBuilder") - .addRuntimeInitializedClass("io.grpc.internal.RetriableStream"); + .addRuntimeInitializedClass("io.grpc.internal.RetriableStream") + .addRuntimeReinitializedClass("com.google.protobuf.UnsafeUtil"); return builder.build(); } diff --git a/extensions/grpc-common/runtime/pom.xml b/extensions/grpc-common/runtime/pom.xml index 540731e0cc3b0..6f988e789e581 100644 --- a/extensions/grpc-common/runtime/pom.xml +++ b/extensions/grpc-common/runtime/pom.xml @@ -99,9 +99,28 @@ io.quarkus quarkus-vertx + + io.grpc + grpc-core + + + com.google.code.findbugs + jsr305 + + + org.codehaus.mojo + animal-sniffer-annotations + + + com.google.android + annotations + + + org.graalvm.nativeimage svm + provided diff --git a/extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcSubstitutions.java b/extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcSubstitutions.java index 349eb09e264b8..1cdaed9d44fc5 100644 --- a/extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcSubstitutions.java +++ b/extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcSubstitutions.java @@ -2,6 +2,7 @@ import static io.grpc.InternalServiceProviders.getCandidatesViaHardCoded; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -12,6 +13,8 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import sun.misc.Unsafe; + @SuppressWarnings("unused") @TargetClass(className = "io.grpc.ServiceProviders") final class Target_io_grpc_ServiceProviders { // NOSONAR @@ -79,6 +82,20 @@ interface Target_io_grpc_ServiceProviders_PriorityAccessor { // NOSONAR int getPriority(T provider); } +@TargetClass(className = "com.google.protobuf.UnsafeUtil") +final class Target_com_google_protobuf_UnsafeUtil { + @Substitute + static sun.misc.Unsafe getUnsafe() { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(null); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} + @SuppressWarnings("unused") class GrpcSubstitutions { }