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

No classes have been predefined during the image build to load from bytecodes at runtime #1588

Closed
funky-eyes opened this issue Feb 6, 2024 · 9 comments
Assignees
Labels
Milestone

Comments

@funky-eyes
Copy link
Contributor

-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)

@raphw
Copy link
Owner

raphw commented Feb 6, 2024

Are the created classes really added? It seems like they are missing from the application.

@raphw raphw self-assigned this Feb 6, 2024
@raphw raphw added the question label Feb 6, 2024
@raphw raphw added this to the 1.14.11 milestone Feb 6, 2024
@funky-eyes
Copy link
Contributor Author

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.

@linghengqian
Copy link

@linghengqian
Copy link

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          ]

@raphw
Copy link
Owner

raphw commented Feb 19, 2024

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.

@linghengqian
Copy link

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
========================================================================================================================
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] ------------------------------------------------------------------------

@raphw
Copy link
Owner

raphw commented Feb 20, 2024

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.

@linghengqian
Copy link

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
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] ------------------------------------------------------------------------

@linghengqian
Copy link

Having said that, opening this issue does not really help. After all, seata has removed the call to bytebuddy, so it can now compile to graalvm native image normally.

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

No branches or pull requests

3 participants