Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native image with Netty 4.1.44.Final #2050

Closed
tovbinm opened this issue Jan 3, 2020 · 9 comments
Closed

Native image with Netty 4.1.44.Final #2050

tovbinm opened this issue Jan 3, 2020 · 9 comments
Assignees

Comments

@tovbinm
Copy link

tovbinm commented Jan 3, 2020

Howdy,

When I am trying to generate a native image on a project with Netty dependency I get the following error:

Error: Classes that should be initialized at run time got initialized during image building:
 io.netty.channel.DefaultFileRegion the class was requested to be initialized at build time (subtype of io.netty.util.AbstractReferenceCounted and from the command line). io.netty.channel.DefaultFileRegion has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.channel.DefaultFileRegion
io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted
com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 io.netty.channel.DefaultFileRegion the class was requested to be initialized at build time (subtype of io.netty.util.AbstractReferenceCounted and from the command line). io.netty.channel.DefaultFileRegion has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.channel.DefaultFileRegion
io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted
	at com.oracle.svm.core.util.UserError.abort(UserError.java:65)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:510)
	at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:187)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$8(NativeImageGenerator.java:710)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:710)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:530)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
	at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1482)
	at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1260)
	at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1222)
	at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1181)

Are there any recommendations on how to troubleshoot this and find the offending class?

Additional info

  • GraalVM 19.3.0.2
  • Netty 4.1.44.Final
@eginez
Copy link
Contributor

eginez commented Jan 6, 2020

HI @tovbinm I was able to verify creating and running an application using netty 4.1.44Final without a problem. I used the latest version of micronaut and overrode the netty dependency version to point to the one you are having problems with. That worked fine. One thing I can think of is that somewhere in your code you might be initializing a class that has been marked as runtime by netty.

The micronaut project has a number of property files that are worth reviewing when using netty with native-image, for example https://github.com/micronaut-projects/micronaut-core/blob/master/http-netty/src/main/resources/META-INF/native-image/io.micronaut/netty/native-image.properties

@eginez eginez closed this as completed Jan 6, 2020
@tovbinm
Copy link
Author

tovbinm commented Jan 7, 2020

@eginez thank you for looking into this. I will try debugging it further.

The most confusing part for me is that the error does not provide any additional information which part of my code (or code of one of my dependencies) initializes the classes DefaultFileRegion and AbstractReferenceCounted. Is there a way you would suggest to troubleshoot this?

@ghost
Copy link

ghost commented Mar 4, 2020

This exact issue still occurs in the below version when running native-image.

openjdk 11.0.6 2020-01-14
OpenJDK Runtime Environment GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02)
OpenJDK 64-Bit Server VM GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02, mixed mode, sharing)

Both of the Below Commands Have Been Tried To Build a Native Image of Waterfall For Minecraft

native-image -jar Waterfall.jar -H:+TraceClassInitialization --initialize-at-build-time=org.apache.logging.log4j,org.apache.logging.slf4j,org.slf4j,org.jline,net.minecrell,com.lmax.disruptor

native-image -jar Waterfall.jar -H:+TraceClassInitialization --initialize-at-build-time=org.apache.logging.log4j,org.apache.logging.slf4j,org.slf4j,org.jline,net.minecrell,com.lmax.disruptor --initialize-at-run-time=io.netty.util.AbstractReferenceCounted

Running just native-image -jar Waterfall.jar still causes the netty initialization issue.

The error message for the netty issue is:

Error: Classes that should be initialized at run time got initialized during image building:
 io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted

Using native-image -jar Waterfall.jar -H:+TraceClassInitialization -H:+ReportExceptionStackTraces --initialize-at-build-time=org.apache.logging.log4j,org.apache.logging.slf4j,org.slf4j,org.jline,net.minecrell,com.lmax.disruptor --initialize-at-run-time=io.netty.util.AbstractReferenceCounted

I get the errors

Error: Classes that should be initialized at run time got initialized during image building:
 io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted

com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted

The full error message is located at this gist.

Edit: I posted this as I have found no way to debug an image build given the options I have tried. I am not sure how to solve the issue and not handling the tracing of the initialization well is not what I believe to be intended design.

@floating-cat
Copy link

floating-cat commented May 20, 2020

I experienced the same exception when I use EpollEventLoopGroup in my method (not in the static initialization block).

I tried to use the "Tracing Agent“ feature (https://www.graalvm.org/docs/reference-manual/native-image/). It helps in my case, though I see another problem after it (not sure whether it is related).
To someone who has this issue too, please try to use "Tracing Agent“. It might help with your case.
edit: Seems the "Tracing Agent“ would generate incorrect files and cause the another problem before the native-images see this problem. So my idea would not work here.

@perezd
Copy link

perezd commented Sep 27, 2020

I'm seeing the same thing with a basic hello world netty app using epoll native transport.

@jamesward
Copy link

Ran into this too and had to add:

  --initialize-at-run-time=io.netty.channel.epoll.Epoll
  --initialize-at-run-time=io.netty.channel.epoll.Native
  --initialize-at-run-time=io.netty.channel.epoll.EpollEventLoop
  --initialize-at-run-time=io.netty.channel.epoll.EpollEventArray
  --initialize-at-run-time=io.netty.channel.DefaultFileRegion
  --initialize-at-run-time=io.netty.channel.kqueue.KQueueEventArray
  --initialize-at-run-time=io.netty.channel.kqueue.KQueueEventLoop
  --initialize-at-run-time=io.netty.channel.kqueue.Native
  --initialize-at-run-time=io.netty.channel.unix.Errors
  --initialize-at-run-time=io.netty.channel.unix.IovArray
  --initialize-at-run-time=io.netty.channel.unix.Limits
  --initialize-at-run-time=io.netty.util.internal.logging.Log4JLogger

@EstebanMarin
Copy link

@jamesward thanks!

@jamesward
Copy link

BTW, I was able to get this working on Netty 4.1.70 by adding (in addition to the ones above):

--initialize-at-run-time=io.netty.channel.kqueue.KQueue

@paddy0615
Copy link

Error: Method 'io.netty.util.AbstractReferenceCounted.main' is declared as the main entry point but it can not be found. Make sure that class 'io.netty.util.AbstractReferenceCounted' is on the classpath and that method 'main(String[])' exists in that class.
com.oracle.svm.core.util.UserError$UserException: Method 'io.netty.util.AbstractReferenceCounted.main' is declared as the main entry point but it can not be found. Make sure that class 'io.netty.util.AbstractReferenceCounted' is on the classpath and that method 'main(String[])' exists in that class.
at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:85)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:365)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
Caused by: java.lang.NoSuchMethodException: io.netty.util.AbstractReferenceCounted.main([Ljava.lang.String;)
at java.base/java.lang.Class.getDeclaredMethod(Class.java:2475)
at org.graalvm.nativeimage.base/com.oracle.svm.util.ReflectionUtil.lookupMethod(ReflectionUtil.java:74)
at org.graalvm.nativeimage.base/com.oracle.svm.util.ReflectionUtil.lookupMethod(ReflectionUtil.java:69)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:363)
... 2 more
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1730)
at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.build(NativeImage.java:1427)
at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1387)
at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.main(NativeImage.java:1374)

求救

guizmaii added a commit to guizmaii/zio-quickstart-https that referenced this issue Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants