I get "a fatal error has been detected by the Java Runtime Environment" while building a native image with GraalVM 1.0.0-rc11 (rc10 too)
. It is a grpc java server (netty based) embedded into a Micronaut 1.0.3 based app. If i add the following content to the reflection.json
json
{
"name" : "io.grpc.netty.shaded.io.netty.channel.socket.nio.NioServerSocketChannel",
"allDeclaredConstructors" : true
}
i get the following error
````
[test-micronaut-grpc-graalvm:2378] classlist: 3,953.07 ms
[test-micronaut-grpc-graalvm:2378] (cap): 780.70 ms
[test-micronaut-grpc-graalvm:2378] setup: 1,839.72 ms
Warning: RecomputeFieldValue.ArrayIndexScale automatic substitution failed. The automatic substitution registration was attempted because a call to sun.misc.Unsafe.arrayIndexScale(Class) was detected in the static initializer of io.micronaut.caffeine.cache.UnsafeRefArrayAccess. Detailed failure reason(s): Could not determine the field where the value produced by the call to sun.misc.Unsafe.arrayIndexScale(Class) for the array index scale computation is stored. The call is not directly followed by a field store or by a sign extend node followed directly by a field store.
Warning: RecomputeFieldValue.ArrayIndexScale automatic substitution failed. The automatic substitution registration was attempted because a call to sun.misc.Unsafe.arrayIndexScale(Class) was detected in the static initializer of io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0. Detailed failure reason(s): The field java.lang.Long.value, where the value produced by the array index scale computation is stored, is not static.
Warning: RecomputeFieldValue.FieldOffset automatic substitution failed. The automatic substitution registration was attempted because a call to sun.misc.Unsafe.objectFieldOffset(Field) was detected in the static initializer of io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0. Add a RecomputeFieldValue.FieldOffset manual substitution for io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0.ADDRESS_FIELD_OFFSET. Detailed failure reason(s): The argument of Unsafe.objectFieldOffset(Field) is not a constant field.
Warning: RecomputeFieldValue.ArrayIndexScale automatic substitution failed. The automatic substitution registration was attempted because a call to sun.misc.Unsafe.arrayIndexScale(Class) was detected in the static initializer of io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.util.UnsafeRefArrayAccess. Detailed failure reason(s): Could not determine the field where the value produced by the call to sun.misc.Unsafe.arrayIndexScale(Class) for the array index scale computation is stored. The call is not directly followed by a field store or by a sign extend node followed directly by a field store.
Warning: RecomputeFieldValue.FieldOffset automatic substitution failed. The automatic substitution registration was attempted because a call to sun.misc.Unsafe.objectFieldOffset(Field) was detected in the static initializer of com.google.protobuf.UnsafeUtil. Detailed failure reason(s): The argument of Unsafe.objectFieldOffset(Field) is not a constant field., Could not determine the field where the value produced by the call to sun.misc.Unsafe.objectFieldOffset(Field) for the field offset computation is stored. The call is not directly followed by a field store or by a sign extend node followed directly by a field store.
Warning: class initialization of class io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslEngine failed with exception java.lang.UnsatisfiedLinkError: io.grpc.netty.shaded.io.netty.internal.tcnative.NativeStaticallyReferencedJniMethods.sslOpCipherServerPreference()I. This class will be initialized at run time because either option --report-unsupported-elements-at-runtime or option --allow-incomplete-classpath is used for image building. Use the option --delay-class-initialization-to-runtime=io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslEngine to explicitly request delayed initialization of this class.
#
#
#
#
#
#
#
Error: Image building with exit status 134
````
It looks like the initialization of io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl crashes the JVM. We run the <clinit> of that class at image build time. This is the relevant part of the trace:
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j io.grpc.netty.shaded.io.netty.internal.tcnative.Library.aprMajorVersion()I+0
j io.grpc.netty.shaded.io.netty.internal.tcnative.Library.initialize(Ljava/lang/String;Ljava/lang/String;)Z+31
j io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl.initializeTcNative(Ljava/lang/String;)Z+3
j io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl.<clinit>()V+240
v ~StubRoutines::call_stub
J 2201 sun.misc.Unsafe.ensureClassInitialized(Ljava/lang/Class;)V (0 bytes) @ 0x00007fca65727d6c [0x00007fca65727d20+0x4c]
You can try delaying the initialization of that class by adding --delay-class-initialization-to-runtime=io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl to the native-image command. You can read more about class initialization in the context of native-image in this blog article.
Building native images of netty based apps usually requires some preparation. Take a look at this article for details.
Thanks for the help. I was able to fix this issue.
Thanks for the help. I was able to fix this issue.
@schneidersteve - Sorry to bother, I am actually encountering the same problem and wanted to view the solution you posted, but it looks like the links are dead - any chance you remember what you did?
Most helpful comment
@schneidersteve - Sorry to bother, I am actually encountering the same problem and wanted to view the solution you posted, but it looks like the links are dead - any chance you remember what you did?