You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm testing some of my Groovy GraalVM examples, and I've found a weird issue I thought you might be interested in. I'm testing reflect-config.json file generation using native-image-agent. For a simple "Hello, World!" like Groovy application, it produces the following reflection configuration file. (It's 598 lines, so I'm pasting a Gist instead of the JSON file content.)
[hello:17248] classlist: 2,554.40 ms
[hello:17248] (cap): 815.35 ms
[hello:17248] setup: 1,895.03 ms
[hello:17248] analysis: 19,254.10 ms
Error: Field java.lang.reflect.Method.defaultValue is not present on type java.lang.reflect.Constructor. Error encountered while analysing java.lang.reflect.Method.getDefaultValue()
Parsing context:
parsing org.codehaus.groovy.vmplugin.v5.Java5.setMethodDefaultValue(Java5.java:355)
parsing org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:379)
parsing org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:280)
parsing org.codehaus.groovy.ast.ClassNode.getAnnotations(ClassNode.java:1456)
parsing org.codehaus.groovy.transform.trait.Traits.collectSelfTypes(Traits.java:330)
parsing org.codehaus.groovy.runtime.ProxyGeneratorAdapter.collectTraits(ProxyGeneratorAdapter.java:243)
parsing org.codehaus.groovy.runtime.ProxyGeneratorAdapter.adjustSuperClass(ProxyGeneratorAdapter.java:210)
parsing org.codehaus.groovy.runtime.ProxyGeneratorAdapter.<init>(ProxyGeneratorAdapter.java:160)
parsing groovy.util.ProxyGenerator.createAdapter(ProxyGenerator.java:230)
parsing groovy.util.ProxyGenerator.instantiateAggregate(ProxyGenerator.java:167)
parsing groovy.util.ProxyGenerator.instantiateAggregate(ProxyGenerator.java:158)
parsing groovy.util.ProxyGenerator.instantiateAggregate(ProxyGenerator.java:154)
parsing org.codehaus.groovy.reflection.stdclasses.CachedSAMClass.coerceToSAM(CachedSAMClass.java:80)
parsing org.codehaus.groovy.reflection.stdclasses.CachedSAMClass.coerceToSAM(CachedSAMClass.java:65)
parsing org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:364)
parsing org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:329)
parsing org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:243)
parsing org.codehaus.groovy.reflection.ParameterTypes.makeCommonArray(ParameterTypes.java:235)
parsing org.codehaus.groovy.reflection.ParameterTypes.fitToVargs(ParameterTypes.java:223)
parsing org.codehaus.groovy.reflection.ParameterTypes.correctArguments(ParameterTypes.java:173)
parsing org.codehaus.groovy.reflection.ParameterTypes.coerceArgumentsToClasses(ParameterTypes.java:145)
parsing groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:321)
parsing groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1217)
parsing groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)
parsing org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:1011)
parsing org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:994)
parsing org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:423)
parsing hello.main(hello.groovy)
parsing com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:153)
parsing com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0)
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1
I tracked down the problem and it turns out that this exception occurs only when reflect-config.json file contains reflection configuration for java.lang.reflect.Executable class.
If I only remove this single entry from the reflect-config.json file, the native image generation succeeds and the "Hello, World!" program compiles and executes without any issue.
I wonder if it is correct that the java.lang.reflect.Executable class gets discovered and added to the reflection configuration file in this case. Is there an option for the agent that allows to filter out specific classes from adding them to the reflection configuration class?
The Error: Field java.lang.reflect.Method.defaultValue is not present on type java.lang.reflect.Constructor issue was fixed by 1873d37 which didn't make it in the release. However, having a filtering mechanism for the generated reflection configuration would be useful.
As @cstancu says, broken reflective access to java.lang.reflect.Method is a bug that unfortunately wasn't fixed in time for the release.
Registering reflection classes themselves for reflective usage is a perfectly valid use case however. I ran your code and looked at the trace file and it is the Groovy class org.codehaus.groovy.reflection.stdclasses.CachedSAMClass that reflectively uses java.lang.reflect.Executable.
Environment:
I'm testing some of my Groovy GraalVM examples, and I've found a weird issue I thought you might be interested in. I'm testing
reflect-config.json
file generation usingnative-image-agent
. For a simple "Hello, World!" like Groovy application, it produces the following reflection configuration file. (It's 598 lines, so I'm pasting a Gist instead of the JSON file content.)https://gist.github.com/wololock/47b8ff2fd9f3a4e0a3fff85e6fe32f89
The agent creates empty
jni-config.json
andproxy-config.json
files. Theresource-config.json
file has the following content:When I try to create a native image using the following options:
native-image --allow-incomplete-classpath \ -H:+AllowVMInspection \ -H:+ReportUnsupportedElementsAtRuntime \ -H:ConfigurationFileDirectories=out/conf/ \ --initialize-at-build-time \ --initialize-at-run-time=org.codehaus.groovy.control.XStreamUtils,groovy.grape.GrapeIvy \ --no-fallback \ --no-server \ -cp ${CLASSPATH} \ hello
It fails with the following error:
I tracked down the problem and it turns out that this exception occurs only when
reflect-config.json
file contains reflection configuration forjava.lang.reflect.Executable
class.If I only remove this single entry from the
reflect-config.json
file, the native image generation succeeds and the "Hello, World!" program compiles and executes without any issue.I wonder if it is correct that the
java.lang.reflect.Executable
class gets discovered and added to the reflection configuration file in this case. Is there an option for the agent that allows to filter out specific classes from adding them to the reflection configuration class?All source codes from my "Hello, World!" Groovy example can be found here - https://github.com/wololock/graalvm-groovy-examples/tree/master/hello-world I "improved"
compile.sh
script file so right before runningnative-image
command it rewritesreflect-config.json
file and it removesjava.lang.reflect.Executable
entry from the list. You can turn it off by commenting out the following line in thecompile.sh
script - https://github.com/wololock/graalvm-groovy-examples/blob/master/hello-world/compile.sh#L26The text was updated successfully, but these errors were encountered: