byte-buddy
byte-buddy copied to clipboard
No classes have been predefined during the image build to load from bytecodes at runtime
-agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image I have used the tracing agent to generate all the required classes, but finally this exception is thrown when executing the executable file
{
"name":"org.apache.seata.config.Configuration",
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"addConfigListener","parameterTypes":["java.lang.String","org.apache.seata.config.ConfigurationChangeListener"] }, {"name":"getBoolean","parameterTypes":["java.lang.String"] }, {"name":"getBoolean","parameterTypes":["java.lang.String","boolean"] }, {"name":"getBoolean","parameterTypes":["java.lang.String","boolean","long"] }, {"name":"getConfig","parameterTypes":["java.lang.String"] }, {"name":"getConfig","parameterTypes":["java.lang.String","long"] }, {"name":"getConfig","parameterTypes":["java.lang.String","java.lang.String"] }, {"name":"getConfig","parameterTypes":["java.lang.String","java.lang.String","long"] }, {"name":"getConfigFromSys","parameterTypes":["java.lang.String"] }, {"name":"getConfigListeners","parameterTypes":["java.lang.String"] }, {"name":"getDuration","parameterTypes":["java.lang.String"] }, {"name":"getDuration","parameterTypes":["java.lang.String","java.time.Duration"] }, {"name":"getDuration","parameterTypes":["java.lang.String","java.time.Duration","long"] }, {"name":"getInt","parameterTypes":["java.lang.String"] }, {"name":"getInt","parameterTypes":["java.lang.String","int"] }, {"name":"getInt","parameterTypes":["java.lang.String","int","long"] }, {"name":"getLatestConfig","parameterTypes":["java.lang.String","java.lang.String","long"] }, {"name":"getLong","parameterTypes":["java.lang.String"] }, {"name":"getLong","parameterTypes":["java.lang.String","long"] }, {"name":"getLong","parameterTypes":["java.lang.String","long","long"] }, {"name":"getShort","parameterTypes":["java.lang.String"] }, {"name":"getShort","parameterTypes":["java.lang.String","short"] }, {"name":"getShort","parameterTypes":["java.lang.String","short","long"] }, {"name":"putConfig","parameterTypes":["java.lang.String","java.lang.String"] }, {"name":"putConfig","parameterTypes":["java.lang.String","java.lang.String","long"] }, {"name":"putConfigIfAbsent","parameterTypes":["java.lang.String","java.lang.String"] }, {"name":"putConfigIfAbsent","parameterTypes":["java.lang.String","java.lang.String","long"] }, {"name":"removeConfig","parameterTypes":["java.lang.String"] }, {"name":"removeConfig","parameterTypes":["java.lang.String","long"] }, {"name":"removeConfigListener","parameterTypes":["java.lang.String","org.apache.seata.config.ConfigurationChangeListener"] }]
},
{
"name":"org.apache.seata.config.Configuration$ByteBuddy$AJvD3TW8",
"fields":[{"name":"invocationHandler$ifs63q0"}],
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.apache.seata.config.file.SimpleFileConfig",
"methods":[{"name":"<init>","parameterTypes":["java.io.File","java.lang.String"] }]
}
Exception in thread "main" com.oracle.svm.core.jdk.UnsupportedFeatureError: No classes have been predefined during the image build to load from bytecodes at runtime.
at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:121)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.PredefinedClassesSupport.throwNoBytecodeClasses(PredefinedClassesSupport.java:76)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.PredefinedClassesSupport.loadClass(PredefinedClassesSupport.java:130)
at [email protected]/java.lang.ClassLoader.defineClass(ClassLoader.java:280)
at net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader.invoker(JavaDispatcher.java:1383)
at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:459)
at net.bytebuddy.utility.dispatcher.JavaDispatcher$InvokerCreationAction.run(JavaDispatcher.java:452)
at [email protected]/java.security.AccessController.executePrivileged(AccessController.java:129)
at [email protected]/java.security.AccessController.doPrivileged(AccessController.java:319)
at net.bytebuddy.utility.dispatcher.JavaDispatcher.doPrivileged(JavaDispatcher.java)
at net.bytebuddy.utility.dispatcher.JavaDispatcher.<clinit>(JavaDispatcher.java:87)
at net.bytebuddy.description.type.TypeDescription$ForLoadedType.<clinit>(TypeDescription.java:8534)
at net.bytebuddy.description.type.TypeDescription.<clinit>(TypeDescription.java:68)
at net.bytebuddy.matcher.ElementMatchers.isFinalizer(ElementMatchers.java:1623)
at net.bytebuddy.matcher.ElementMatchers.isDefaultFinalizer(ElementMatchers.java:1613)
at net.bytebuddy.ByteBuddy.<init>(ByteBuddy.java:311)
at net.bytebuddy.ByteBuddy.<init>(ByteBuddy.java:285)
at io.seata.config.ConfigurationCache.proxy(ConfigurationCache.java:104)
at io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:167)
at io.seata.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:112)
at io.seata.core.rpc.netty.NettyBaseConfig.<clinit>(NettyBaseConfig.java:54)
at [email protected]/java.lang.Class.ensureInitialized(DynamicHub.java:595)
at io.seata.core.rpc.netty.TmNettyRemotingClient.getInstance(TmNettyRemotingClient.java:130)
at io.seata.core.rpc.netty.TmNettyRemotingClient.getInstance(TmNettyRemotingClient.java:113)
at io.seata.tm.TMClient.init(TMClient.java:46)
at io.seata.tm.TMClient.init(TMClient.java:34)
at icu.funkye.ApplicationMain.init(ApplicationMain.java:87)
at icu.funkye.ApplicationMain.main(ApplicationMain.java:54)
at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Are the created classes really added? It seems like they are missing from the application.
Are the created classes really added? It seems like they are missing from the application.
According to my code and config file, it should be added, can you tell me which class information is missing? Theoretically the tracing agent should be able to catch it, I didn't manually intervene because it must have loaded the relevant class when it started, so it should be traced.
- I'm happy to assume this involves a bug on the GraalVM CE side, which I've opened https://github.com/oracle/graal/issues/8396.
- Discuss two situations,
- Carrying
experimental-class-define-support=truegenerates GraalVM Reachability Metadata inConditionalform, which will cause exceptions. - Carrying
experimental-class-define-support=truegenerates GraalVM Reachability Metadata inStandardform, which always works.
- Carrying
- So you can actually see the real Error Log at https://github.com/linghengqian/experimental-class-define-support-v2312-test . This simply requires changing
configuration->agent->defaultModefromConditionaltoStandard. The way the ByteBuddy API is used in Apache Seata breaks the closed world assumption of GraalVM Native Image.
Failures (1):
JUnit Jupiter:SeataTest:assertShardingInSeataTransactions()
MethodSource [className = 'com.lingh.SeataTest', methodName = 'assertShardingInSeataTransactions', methodParameterTypes = '']
=> com.oracle.svm.core.jdk.UnsupportedFeatureError: Defining a class from new bytecodes at run time is not supported. Class io.seata.config.Configuration$io$seata$config$ConfigurationCache$proxy$ByteBuddy with hash 0d95147338eda0009d73dad94a7c7818120e44e6bdb18007c807001b7adba0fb was not provided during the image build. Please see BuildConfiguration.md.
org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:121)
org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.PredefinedClassesSupport.loadClass(PredefinedClassesSupport.java:136)
[email protected]/java.lang.ClassLoader.defineClass(ClassLoader.java:280)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader.access$300(ByteArrayClassLoader.java:56)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader$ClassDefinitionAction.run(ByteArrayClassLoader.java:686)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader$ClassDefinitionAction.run(ByteArrayClassLoader.java:638)
[email protected]/java.security.AccessController.executePrivileged(AccessController.java:129)
[email protected]/java.security.AccessController.doPrivileged(AccessController.java:400)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader.doPrivileged(ByteArrayClassLoader.java)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader.findClass(ByteArrayClassLoader.java:405)
[...]
Test run finished after 5560 ms
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 1 tests found ]
[ 0 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 1 tests failed ]
Byte Buddy tries to provide different defaults when it detects Graal: GraalImageCode, but possibly those defaults are overridden. In this case you need to contact the library maintainers. Maybe you can initiate the Graal support explicitly, too.
- Okey, I assumed this was the missing statement involved in https://gist.github.com/raphw/e0f6864ddcad69630d839c2eebaad818 , I opened https://github.com/linghengqian/experimental-class-define-support-v2312-test/pull/1 to provide verification.
Args = -H:ClassInitialization=net.bytebuddy.ClassFileVersion:rerun \
-H:ClassInitialization=net.bytebuddy.utility.dispatcher.JavaDispatcher:rerun \
-H:ClassInitialization=net.bytebuddy.utility.Invoker$Dispatcher:rerun \
-H:ClassInitialization=net.bytebuddy.utility.GraalImageCode:rerun \
--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable \
--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$AbstractBase \
--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$ForLoadedType \
--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$ForLoadedMethod \
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic \
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$1 \
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$2 \
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Super$Instantiation$2 \
--initialize-at-build-time=net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader
- This will bring another error log. According to experiments, adding additional
--initialize-at-build-time=net.bytebuddy.utility.OpenedClassReaderhas no effect, but further breaks the build. What did I overlook? I assume I understand correctly JavaDoc for https://github.com/raphw/byte-buddy/blob/byte-buddy-1.14.12/byte-buddy-dep/src/main/java/net/bytebuddy/utility/GraalImageCode.java .
========================================================================================================================
GraalVM Native Image: Generating 'native-tests' (executable)...
========================================================================================================================
[1/8] Initializing... (7.1s @ 0.33GB)
Java version: 21.0.2+13, vendor version: GraalVM CE 21.0.2+13.1
Graal compiler: optimization level: b, target machine: x86-64-v3
C compiler: gcc (linux, x86_64, 11.4.0)
Garbage collector: Serial GC (max heap size: 80% of RAM)
2 user-specific feature(s):
- com.oracle.svm.thirdparty.gson.GsonFeature
- org.graalvm.junit.platform.JUnitPlatformFeature
------------------------------------------------------------------------------------------------------------------------
1 experimental option(s) unlocked:
- '-H:ClassInitialization' (alternative API option(s): --initialize-at-run-time=net.bytebuddy.ClassFileVersion:rerun, --initialize-at-run-time=net.bytebuddy.utility.dispatcher.JavaDispatcher:rerun, --initialize-at-run-time=net.bytebuddy.utility.Invoker$Dispatcher:rerun, --initialize-at-run-time=net.bytebuddy.utility.GraalImageCode:rerun, --initialize-at-run-time=net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable:build_time, --initialize-at-run-time=net.bytebuddy.description.type.TypeDescription$AbstractBase:build_time, --initialize-at-run-time=net.bytebuddy.description.type.TypeDescription$ForLoadedType:build_time, --initialize-at-run-time=net.bytebuddy.description.method.MethodDescription$ForLoadedMethod:build_time, --initialize-at-run-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic:build_time, --initialize-at-run-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$1:build_time, --initialize-at-run-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$2:build_time, --initialize-at-run-time=net.bytebuddy.implementation.bind.annotation.Super$Instantiation$2:build_time, --initialize-at-run-time=net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader:build_time, --initialize-at-run-time=net.bytebuddy.ClassFileVersion:rerun, --initialize-at-run-time=net.bytebuddy.utility.dispatcher.JavaDispatcher:rerun, --initialize-at-run-time=net.bytebuddy.utility.Invoker$Dispatcher:rerun, --initialize-at-run-time=net.bytebuddy.utility.GraalImageCode:rerun, --initialize-at-run-time=net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable:build_time, --initialize-at-run-time=net.bytebuddy.description.type.TypeDescription$AbstractBase:build_time, --initialize-at-run-time=net.bytebuddy.description.type.TypeDescription$ForLoadedType:build_time, --initialize-at-run-time=net.bytebuddy.description.method.MethodDescription$ForLoadedMethod:build_time, --initialize-at-run-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic:build_time, --initialize-at-run-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$1:build_time, --initialize-at-run-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$2:build_time, --initialize-at-run-time=net.bytebuddy.implementation.bind.annotation.Super$Instantiation$2:build_time, --initialize-at-run-time=net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader:build_time, --initialize-at-run-time=io.netty.handler.codec.compression.BrotliDecoder:run_time; origin(s): 'META-INF/native-image/net.bytebuddy/byte-buddy/1.14.12/native-image.properties' in 'file:///home/linghengqian/TwinklingLiftWorks/git/public/experimental-class-define-support-v2312-test/target/test-classes/', 'META-INF/native-image/net.bytebuddy/byte-buddy/1.14.12/native-image.properties' in 'file:///home/linghengqian/TwinklingLiftWorks/git/public/experimental-class-define-support-v2312-test/target/test-classes/', 'META-INF/native-image/net.bytebuddy/byte-buddy/1.14.12/native-image.properties' in 'file:///home/linghengqian/TwinklingLiftWorks/git/public/experimental-class-define-support-v2312-test/target/test-classes/', 'META-INF/native-image/net.bytebuddy/byte-buddy/1.14.12/native-image.properties' in 'file:///home/linghengqian/TwinklingLiftWorks/git/public/experimental-class-define-support-v2312-test/target/test-classes/', 'META-INF/native-image/net.bytebuddy/byte-buddy/1.14.12/native-image.properties' in 'file:///home/linghengqian/TwinklingLiftWorks/git/public/experimental-class-define-support-v2312-test/src/test/resources/', 'META-INF/native-image/net.bytebuddy/byte-buddy/1.14.12/native-image.properties' in 'file:///home/linghengqian/TwinklingLiftWorks/git/public/experimental-class-define-support-v2312-test/src/test/resources/', 'META-INF/native-image/net.bytebuddy/byte-buddy/1.14.12/native-image.properties' in 'file:///home/linghengqian/TwinklingLiftWorks/git/public/experimental-class-define-support-v2312-test/src/test/resources/', 'META-INF/native-image/net.bytebuddy/byte-buddy/1.14.12/native-image.properties' in 'file:///home/linghengqian/TwinklingLiftWorks/git/public/experimental-class-define-support-v2312-test/src/test/resources/')
------------------------------------------------------------------------------------------------------------------------
Build resources:
- 8.82GB of memory (45.1% of 19.54GB system memory, determined at start)
- 16 thread(s) (100.0% of 16 available processor(s), determined at start)
Skipped 221 predefined class(es) because the classpath already contains a class with the same name: io.seata.sqlparser.druid.polardbx.PolarDBXOperateRecognizerHolder, com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSQLStatement, com.alibaba.druid.sql.dialect.phoenix.parser.PhoenixExprParser, com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor, com.alibaba.druid.sql.ast.SQLPartitionByValue, com.alibaba.druid.sql.dialect.h2.visitor.H2ASTVisitor, com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement, com.alibaba.druid.sql.dialect.postgresql.parser.PGLexer, com.alibaba.druid.sql.ast.SQLIndex, com.alibaba.druid.sql.ast.SQLDataType, ...
[junit-platform-native] Running in 'test listener' mode using files matching pattern [junit-platform-unique-ids*] found in folder [/home/linghengqian/TwinklingLiftWorks/git/public/experimental-class-define-support-v2312-test/target/test-ids] and its subfolders.
[2/8] Performing analysis... [*] (27.5s @ 2.47GB)
20,712 reachable types (87.6% of 23,656 total)
34,579 reachable fields (60.1% of 57,511 total)
105,293 reachable methods (58.9% of 178,652 total)
6,881 types, 1,852 fields, and 7,013 methods registered for reflection
Error: Classes that should be initialized at run time got initialized during image building:
net.bytebuddy.utility.OpenedClassReader was unintentionally initialized at build time. To see why net.bytebuddy.utility.OpenedClassReader got initialized use --trace-class-initialization=net.bytebuddy.utility.OpenedClassReader
To see how the classes got initialized, use --trace-class-initialization=net.bytebuddy.utility.OpenedClassReader
------------------------------------------------------------------------------------------------------------------------
3.8s (10.5% of total time) in 51 GCs | Peak RSS: 5.44GB | CPU load: 9.66
========================================================================================================================
Finished generating 'native-tests' in 35.1s.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 48.480 s (Wall Clock)
[INFO] Finished at: 2024-02-19T22:19:35+08:00
[INFO] ------------------------------------------------------------------------
Maybe it's another -H:ClassInitialization that needs to be added? To be perfectly honest, I never fully understood what is going on with these options and just kept adding them until everything worked.
- If you are talking about the buildArg of
-H:ClassInitialization=net.bytebuddy.utility.OpenedClassReader:rerun, I continue at https://github.com/linghengqian/experimental-class-define-support-v2312-test/pull/1 to verify.
Args = -H:ClassInitialization=net.bytebuddy.ClassFileVersion:rerun \
-H:ClassInitialization=net.bytebuddy.utility.dispatcher.JavaDispatcher:rerun \
-H:ClassInitialization=net.bytebuddy.utility.Invoker$Dispatcher:rerun \
-H:ClassInitialization=net.bytebuddy.utility.GraalImageCode:rerun \
--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable \
--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$AbstractBase \
--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$ForLoadedType \
--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$ForLoadedMethod \
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic \
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$1 \
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$2 \
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Super$Instantiation$2 \
--initialize-at-build-time=net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader \
-H:ClassInitialization=net.bytebuddy.utility.OpenedClassReader:rerun
- This goes back to the previous topic, https://github.com/apache/incubator-seata/blob/5a84c42ba2be0db11228c00162a964e4c9ca9ea8/config/seata-config-core/src/main/java/org/apache/seata/config/ConfigurationCache.java using the ByteBuddy API breaks the closed world assumption, and using
java.lang.reflect.Proxycan temporarily avoid such problems.
Failures (1):
JUnit Jupiter:SeataTest:assertShardingInSeataTransactions()
MethodSource [className = 'com.lingh.SeataTest', methodName = 'assertShardingInSeataTransactions', methodParameterTypes = '']
=> com.oracle.svm.core.jdk.UnsupportedFeatureError: Defining a class from new bytecodes at run time is not supported. Class io.seata.config.Configuration$io$seata$config$ConfigurationCache$proxy$ByteBuddy with hash db8f83740bdb05f4253fbf0991a7136955934bc498167aebbe1869a3d170eb8f was not provided during the image build. Please see BuildConfiguration.md.
org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:121)
org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.PredefinedClassesSupport.loadClass(PredefinedClassesSupport.java:136)
[email protected]/java.lang.ClassLoader.defineClass(ClassLoader.java:280)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader.access$300(ByteArrayClassLoader.java:56)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader$ClassDefinitionAction.run(ByteArrayClassLoader.java:686)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader$ClassDefinitionAction.run(ByteArrayClassLoader.java:638)
[email protected]/java.security.AccessController.executePrivileged(AccessController.java:129)
[email protected]/java.security.AccessController.doPrivileged(AccessController.java:400)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader.doPrivileged(ByteArrayClassLoader.java)
net.bytebuddy.dynamic.loading.ByteArrayClassLoader.findClass(ByteArrayClassLoader.java:405)
[...]
Test run finished after 6586 ms
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 1 tests found ]
[ 0 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 1 tests failed ]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:35 min (Wall Clock)
[INFO] Finished at: 2024-02-20T16:34:23+08:00
[INFO] ------------------------------------------------------------------------