powsybl / powsybl-core

A framework to build power system oriented software
https://www.powsybl.org
Mozilla Public License 2.0
126 stars 41 forks source link

Support graalvm native-image #1561

Closed yichen88 closed 1 year ago

yichen88 commented 3 years ago

Feature

Currently, I successfully created an itools native-image which could run loadflow command in graalvm. But after i created another image with action-simulator command(with 4 new config files), there is an issue about groovy dsl and graalvm AOT at runtime. I am not sure it could be done or not. Here is the error at image runtime:

[tangyic@mars distribution-core]$ ./Itools action-simulator --case-file=/home/tangyic/data/e.xiidm --dsl-file=/home/tangyic/data/a.groovy
[main] INFO  c.p.c.DefaultComputationManagerConfig - DefaultComputationManagerConfig(shortTimeExecutionComputationManagerFactoryClass=com.powsybl.computation.local.LocalComputationManagerFactory, longTimeExecutionComputationManagerFactoryClass=com.powsybl.computation.local.LocalComputationManagerFactory)
Loading network '/home/tangyic/data/e.xiidm'
Exception in thread "main" com.oracle.svm.core.jdk.UnsupportedFeatureError: Unsupported method java.lang.ClassLoader.defineClass(String, byte[], int, int, ProtectionDomain) is reachable
    at com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:87)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:1015)
    at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.define(ClassLoaderForClassArtifacts.java:43)
    at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:76)
    at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:74)
    at java.security.AccessController.doPrivileged(AccessController.java:84)
    at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.defineClassAndGetConstructor(ClassLoaderForClassArtifacts.java:74)
    at org.codehaus.groovy.runtime.callsite.CallSiteGenerator.compileStaticMethod(CallSiteGenerator.java:262)
    at org.codehaus.groovy.reflection.CachedMethod.createStaticMetaMethodSite(CachedMethod.java:297)
    at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.createStaticMetaMethodSite(StaticMetaMethodSite.java:112)
    at groovy.lang.MetaClassImpl.createStaticSite(MetaClassImpl.java:3449)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:76)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:161)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127)
    at com.powsybl.dsl.DslLoader.<init>(DslLoader.groovy:21)
    at com.powsybl.dsl.DslLoader.<init>(DslLoader.groovy:25)
    at com.powsybl.action.dsl.ActionDslLoader.<init>(ActionDslLoader.groovy:98)
    at com.powsybl.action.simulator.tools.ActionSimulatorTool.run(ActionSimulatorTool.java:263)
    at com.powsybl.tools.CommandLineTools.run(CommandLineTools.java:164)
    at com.powsybl.tools.Main.main(Main.java:45)

(if a question doesn't apply, you can delete it)

geofjamg commented 3 years ago

@yichen88 @sylvlecl This is normal, there is no way to compile Groovy code (exception code annotated with CompileStatic) because this is a dynamic language. This is why in the past months I made some refactoring in core repo to separate groovy code into dedicated and optional Maven modules. As it is, there is no way to run IAL script with a GraalVM compiled version of itools. If we want to do that, we should move to a statically compiled DSL similar to Groovy one: we can do that with Kotlin DSL. Maybe this is something to investigate? We also have the same question for dynamic simulation DSL.