Closed jamesward closed 10 months ago
Hi, Thank you for reporting this, is it possible to share a small reproducer to illustrate the issue?
Example reproduction follows. @jamesward The --trace-class-initialization seems to take a comma separated list of classes, otherwise it picks the last one.
But besides this ergonomics problem, there is a more important problem that it offers no insight in my case, even when I correctly add the comma separated list of classes. I'm left with the initialized without the native-image initialization instrumentation
with, it is true, a helpful message to add --initialize-at-build-time
arguments. But In my case I know the two classes in questions cannot be initialized at build time, and I actually want to know what tried to initialize them, to assist in fixing the problem upstream.
What does initialized without the native-image initialization instrumentation
mean, and how do I get more info about the cause of the class initialization. I did a verbose:gc, and could not figure out a pattern to the order in which classes were loaded.
plugins {
id("my.kotlin-library-conventions")
id("org.graalvm.buildtools.native")
}
dependencies {
implementation("software.amazon.cryptools:AmazonCorrettoCryptoProvider:1.+:linux-x86_64")
}
tasks.jar {
println("stripping aws crypto jar of signatures and ServiceLoader information")
from(configurations.compileClasspath.get().map {
if (it.name.contains("kotlin") || it.name.contains("annotations")) {
// exclude all the kotlin crap that gets imported because of our use of kotlin-library-conventions plugin.
// https://github.com/kixi-io/Ki.KD-JVM/blob/a037772bb8339a6ba74065125028661fa10cae32/build.gradle.kts
println("ignoring: ${it.name}")
null
} else if (it.isDirectory) {
println("adding directory: ${it.name}")
it
} else {
println("adding zip: ${it.name}")
zipTree(it)
}
}) {
exclude("META-INF/*.SF")
exclude("META-INF/*.DSA")
exclude("META-INF/*.RSA")
exclude("META-INF/module-info.class")
exclude("META-INF/services/*")
}
}
graalvmNative {
binaries {
named("main") {
sharedLibrary.set(false)
mainClass.set("repro.InstallKt")
buildArgs(
"--no-fallback",
"--allow-incomplete-classpath",
"-H:+ReportExceptionStackTraces",
"-H:+ReportUnsupportedElementsAtRuntime",
)
}
}
}
package repro
import com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider
fun main() {
AmazonCorrettoCryptoProvider.install()
AmazonCorrettoCryptoProvider.INSTANCE.assertHealthy()
}
ARG GRAALVM_VERSION=22.0.0.2
FROM ghcr.io/graalvm/native-image:ol8-java11-$GRAALVM_VERSION
RUN microdnf install findutils less
ADD https://raw.githubusercontent.com/corretto/amazon-corretto-crypto-provider/master/etc/amazon-corretto-crypto-provider.security \
/usr/lib64/graalvm/graalvm22-ce-java11/conf/security/java.security
RUN useradd --create-home --home-dir /user -u 1000 --user-group user
USER user
WORKDIR /project
ENTRYPOINT ["/usr/bin/env", "bash"]
built using:
docker build -t graalvm-ce2 - < dockerfiles/Dockerfile.graalvm-ce2
docker run -it --rm --dns 8.8.8.8 --volume=$HOME/.m2:/user/.m2 --volume=$GRADLE_USER_HOME:/user/.gradle --volume=$(pwd):/project graalvm-ce2 ./gradlew :awssdkclient-cryptoprovider:nativeRun
com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
com.amazon.corretto.crypto.provider.Loader was unintentionally initialized at build time. To see why com.amazon.corretto.crypto.provider.Loader got initialized use --trace-class-initialization=com.amazon.corretto.crypto.provider.Loader
com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider was unintentionally initialized at build time. To see why com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider got initialized use --trace-class-initialization=com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider
at com.oracle.svm.core.util.UserError.abort(UserError.java:73)
at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:555)
at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:167)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$10(NativeImageGenerator.java:704)
at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:74)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$11(NativeImageGenerator.java:704)
at com.oracle.graal.pointsto.PointsToAnalysis.runAnalysis(PointsToAnalysis.java:755)
at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:702)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:537)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:494)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:426)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:587)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:126)
--trace-class-initialization=com.amazon.corretto.crypto.provider.Loader
com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider was unintentionally initialized at build time. To see why com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider got initialized use --trace-class-initialization=com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider
com.amazon.corretto.crypto.provider.Loader was unintentionally initialized at build time. com.amazon.corretto.crypto.provider.Loader has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=com.amazon.corretto.crypto.provider.Loader
--trace-class-initialization=com.amazon.corretto.crypto.provider.Loader
and --trace-class-initialization=com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider
com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
com.amazon.corretto.crypto.provider.Loader was unintentionally initialized at build time. To see why com.amazon.corretto.crypto.provider.Loader got initialized use --trace-class-initialization=com.amazon.corretto.crypto.provider.Loader
com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider was unintentionally initialized at build time. com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider
--trace-class-initialization=com.amazon.corretto.crypto.provider.Loader,com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider
(comma separated)com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider was unintentionally initialized at build time. com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider
com.amazon.corretto.crypto.provider.Loader was unintentionally initialized at build time. com.amazon.corretto.crypto.provider.Loader has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=com.amazon.corretto.crypto.provider.Loader
If this issue is still relevant in the latest GraalVM versions, please create a new issue for it and follow the template provided. Thank you
While trying to debug native image with Netty (4.1.70), I ran into:
I'm using
graalvm-ce-java11-21.3.0
and this seems to happen when I specify multiple--trace-class-initialization
flags, like:With only 1
--trace-class-initialization
specified, I seem to be able to get it to provide the stack trace.