From abe718f37c688e822325e3fffefd95f139352373 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 1 Feb 2023 14:58:36 -0500 Subject: [PATCH 1/2] fix(java): initialize netty-shaded at run-time and add reflection configurations for netty classes --- .../grpc/nativeimage/GrpcNettyFeature.java | 22 +++++++++++ .../gax-grpc/native-image.properties | 3 +- .../gax-grpc/reflect-config.json | 39 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java index 23db568b72..f6e1e904af 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java @@ -85,6 +85,28 @@ private static void loadGrpcNettyClasses(BeforeAnalysisAccess access) { registerClassForReflection(access, "io.grpc.netty.shaded.io.netty.channel.DefaultFileRegion"); registerClassForReflection( access, "io.grpc.netty.shaded.io.netty.channel.unix.PeerCredentials"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.grpc.netty.WriteBufferingAndExceptionHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.ProtocolNegotiators"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$TailContext"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$WaitUntilActiveHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$ClientTlsHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$GrpcNegotiationHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.ChannelHandlerMask"); // Epoll Libraries registerClassForReflection(access, "io.grpc.netty.shaded.io.netty.channel.epoll.Epoll"); diff --git a/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/native-image.properties b/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/native-image.properties index b66e70603f..262f5d17a2 100644 --- a/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/native-image.properties +++ b/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/native-image.properties @@ -9,7 +9,8 @@ Args=--add-opens=java.base/java.time=ALL-UNNAMED \ io.grpc.netty.shaded.io.netty.channel.epoll,\ io.grpc.netty.shaded.io.netty.channel.unix,\ io.grpc.netty.shaded.io.netty.handler.ssl,\ - io.grpc.internal.RetriableStream \ + io.grpc.internal.RetriableStream,\ + io.grpc.netty.shaded.io.netty \ --features=com.google.api.gax.grpc.nativeimage.ProtobufMessageFeature,\ com.google.api.gax.grpc.nativeimage.GrpcNettyFeature \ -H:-RunReachabilityHandlersConcurrently \ No newline at end of file diff --git a/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/reflect-config.json b/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/reflect-config.json index 69f24071df..463a4bb1d5 100644 --- a/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/reflect-config.json +++ b/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/reflect-config.json @@ -283,5 +283,44 @@ "name": "selectedKeys" } ] + }, + { + "name" : "com.google.auth.oauth2.ServiceAccountCredentials", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true, + "queryAllPublicConstructors" : true, + "queryAllDeclaredConstructors" : true, + "queryAllPublicMethods" : true, + "queryAllDeclaredMethods" : true + }, + { + "name" : "org.apache.commons.pool2.impl.DefaultEvictionPolicy", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true, + "queryAllPublicConstructors" : true, + "queryAllDeclaredConstructors" : true, + "queryAllPublicMethods" : true, + "queryAllDeclaredMethods" : true + }, + { + "name" : "java.nio.channels.spi.SelectorProvider", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true, + "queryAllPublicConstructors" : true, + "queryAllDeclaredConstructors" : true, + "queryAllPublicMethods" : true, + "queryAllDeclaredMethods" : true } ] From 30195f9f955164c17079ab6e3146c6b42285cbfb Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 1 Feb 2023 15:07:21 -0500 Subject: [PATCH 2/2] fix formatting --- .../grpc/nativeimage/GrpcNettyFeature.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java index f6e1e904af..bbd899b284 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java @@ -86,27 +86,25 @@ private static void loadGrpcNettyClasses(BeforeAnalysisAccess access) { registerClassForReflection( access, "io.grpc.netty.shaded.io.netty.channel.unix.PeerCredentials"); registerClassForReflection( - access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline"); + access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline"); registerClassForReflection( - access, "io.grpc.netty.shaded.io.grpc.netty.WriteBufferingAndExceptionHandler"); + access, "io.grpc.netty.shaded.io.grpc.netty.WriteBufferingAndExceptionHandler"); registerClassForReflection( - access, "io.grpc.netty.shaded.io.netty.channel.ProtocolNegotiators"); + access, "io.grpc.netty.shaded.io.netty.channel.ProtocolNegotiators"); + registerClassForReflection(access, "io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler"); + registerClassForReflection(access, "io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler"); registerClassForReflection( - access, "io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler"); + access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext"); registerClassForReflection( - access, "io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler"); + access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$TailContext"); registerClassForReflection( - access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext"); + access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$WaitUntilActiveHandler"); registerClassForReflection( - access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$TailContext"); + access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$ClientTlsHandler"); registerClassForReflection( - access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$WaitUntilActiveHandler"); + access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$GrpcNegotiationHandler"); registerClassForReflection( - access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$ClientTlsHandler"); - registerClassForReflection( - access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$GrpcNegotiationHandler"); - registerClassForReflection( - access, "io.grpc.netty.shaded.io.netty.channel.ChannelHandlerMask"); + access, "io.grpc.netty.shaded.io.netty.channel.ChannelHandlerMask"); // Epoll Libraries registerClassForReflection(access, "io.grpc.netty.shaded.io.netty.channel.epoll.Epoll");