Skip to content

Commit

Permalink
Merge pull request quarkusio#36642 from cescoffier/reinitialize-grpc-…
Browse files Browse the repository at this point in the history
…unsafe

Reinitialize the com.google.protobuf.UnsafeUtil class at runtime
  • Loading branch information
cescoffier authored Oct 25, 2023
2 parents f606af6 + 03857b4 commit 7a3fd94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -79,6 +82,20 @@ interface Target_io_grpc_ServiceProviders_PriorityAccessor<T> { // 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 {
}

0 comments on commit 7a3fd94

Please sign in to comment.