Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Native image generation fails #8

Open
sdelamo opened this issue Dec 12, 2019 · 1 comment
Open

Native image generation fails #8

sdelamo opened this issue Dec 12, 2019 · 1 comment

Comments

@sdelamo
Copy link
Contributor

sdelamo commented Dec 12, 2019

Steps to reproduce.

Clone graalvm branch.

$ sdk use java 19.3.0.r8-grl 
$ ./gradlew clean :complete:assemble
$ % native-image --no-server -cp build/libs/complete-0.1-all.jar
[micronautguide:41646]    classlist:   8,984.31 ms
[micronautguide:41646]        (cap):   2,011.06 ms
[micronautguide:41646]        setup:   3,022.24 ms
ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider com.oracle.truffle.js.scriptengine.GraalJSEngineFactory could not be instantiated
ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider com.oracle.truffle.js.scriptengine.GraalJSEngineFactory could not be instantiated
[micronautguide:41646]   (typeflow):  26,810.31 ms
[micronautguide:41646]    (objects):  41,522.68 ms
[micronautguide:41646]   (features):   3,182.03 ms
[micronautguide:41646]     analysis:  76,773.19 ms
[micronautguide:41646]     (clinit):   2,761.01 ms
[micronautguide:41646]     universe:   4,791.47 ms
Fatal error: java.lang.NoClassDefFoundError
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
	at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:462)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:315)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:454)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:115)
Caused by: java.lang.NoClassDefFoundError: Lorg/apache/logging/log4j/spi/LoggerContext;
	at java.lang.Class.getDeclaredFields0(Native Method)
	at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
	at java.lang.Class.getDeclaredField(Class.java:2068)
	at com.oracle.graal.pointsto.infrastructure.OriginalFieldProvider.getJavaField(OriginalFieldProvider.java:43)
	at com.oracle.graal.pointsto.meta.AnalysisField.getJavaField(AnalysisField.java:420)
	at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readUninitializedStaticValue(AnalysisConstantReflectionProvider.java:136)
	at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readValue(AnalysisConstantReflectionProvider.java:87)
	at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readFieldValue(AnalysisConstantReflectionProvider.java:77)
	at com.oracle.svm.hosted.meta.HostedField.readValue(HostedField.java:156)
	at com.oracle.svm.hosted.thread.VMThreadLocalCollector.sortThreadLocals(VMThreadLocalCollector.java:110)
	at com.oracle.svm.hosted.thread.VMThreadMTFeature.beforeCompilation(VMThreadMTFeature.java:267)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$2(NativeImageGenerator.java:570)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:570)
	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)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.spi.LoggerContext
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 20 more

Notes:

I generated a src/main/graal/reflect.json with h2 entries obtained with the tracing agent.

I initialized org.h2.Driver at build time to get rid of

$ native-image --no-server -cp build/libs/complete-0.1-all.jar
[micronautguide:19479]    classlist:   9,201.94 ms
[micronautguide:19479]        (cap):   1,934.47 ms
[micronautguide:19479]        setup:   2,968.63 ms
[micronautguide:19479]     analysis:  32,824.55 ms
Error: Classes that should be initialized at run time got initialized during image building:
 org.h2.Driver was unintentionally initialized at build time. To see why org.h2.Driver got initialized use -H:+TraceClassInitialization
org.springframework.jdbc.datasource.ConnectionProxy was unintentionally initialized at build time. To see why org.springframework.jdbc.datasource.ConnectionProxy got initialized use -H:+TraceClassInitialization
Error: Use -H:+ReportExceptionStackTraces to

I initialized org.springframework.jdbc.datasource.ConnectionProxy at build time to get rid of

% native-image --no-server -cp build/libs/complete-0.1-all.jar
[micronautguide:41050]    classlist:   8,726.02 ms
[micronautguide:41050]        (cap):   2,046.28 ms
[micronautguide:41050]        setup:   3,040.42 ms
[micronautguide:41050]     analysis:  34,659.05 ms
Error: Classes that should be initialized at run time got initialized during image building:
 org.springframework.jdbc.datasource.ConnectionProxy was unintentionally initialized at build time. To see why org.springframework.jdbc.datasource.ConnectionProxy got initialized use -H:+TraceClassInitialization

Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1

My native-image.properties files look like:

src/main/resources/META-INF/native-image/example.micronaut/micronautguide/native-image.properties

Args = -H:IncludeResources=logback.xml|application.yml \
       -H:Name=micronautguide \
       -H:Class=example.micronaut.Application \
       --initialize-at-build-time=org.h2.Driver,org.springframework.jdbc.datasource.ConnectionProxy

I tried adding allow-incomplete-classpath

--allow-incomplete-classpath allows image building with an incomplete class path and reports type resolution errors at run time when they are accessed the first time, instead of during image building

but same error happens.

@sdelamo
Copy link
Contributor Author

sdelamo commented Dec 12, 2019

I posted this in the GraalVM issue tracker:

oracle/graal#1979

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant