GoodforGod / graalvm-hint

🧰 Generates GraalVM configuration hints for native-image applications.
http://goodforgod.dev/graalvm-hint/
Apache License 2.0
35 stars 4 forks source link

How about @DynamicProxyHint and @SubstitutionHint #2

Closed linux-china closed 2 years ago

linux-china commented 2 years ago

@GoodforGod, it's nice project 👍

Now I use optionNames to add DynamicProxy support with following code:

@NativeImageHint(optionNames = {"-H:DynamicProxyConfigurationResources=com.example.UserService"})

Another problem is -H:SubstitutionResources=${.}/substitutions.json , and substitutions should be supplied by json file.

How about new @DynamicProxyHint and @SubstitutionHint annotations? I think they are more friendly to developers.

GoodforGod commented 2 years ago

Hello @linux-china and thanks! Looks like it can be easily integrated, I'll look into the details of those options how better they can be implemented, and will come back with more info!

GoodforGod commented 2 years ago

Couldn't find any info about SubstitutionResources except this

This option basically only allow to specify resources like list of string to be substituted? Like: -H:SubstitutionResources=${.}/substitutions1.json,${.}/substitutions1.json

But what exactly they substitute? What is their purpose? I dont get it and couldn't find any documentation, may be you can provide some info please @linux-china

linux-china commented 2 years ago

Yes, it's hard to find document, and you can find some examples from following:

GoodforGod commented 2 years ago

Thanks! Looks like some wodo black magic, will try to find some more info from GraalVM devs

GoodforGod commented 2 years ago

I deployed 0.18.0-SNASHOT version, can you please try DynamycProxyHint and give your feedback and potential bugs, cause I don't have any real world usages for this hint @linux-china

Do not forget to add snapshot repo

repositories {
    maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots" }
}
GoodforGod commented 2 years ago

Looks like Substitution option is deprecated so, no point in supporting it

https://github.com/oracle/graal/commit/6054669045f1504ccfbdf987f2200b365335de96

linux-china commented 2 years ago

@GoodforGod yes, from https://www.graalvm.org/release-notes/22_0/. Removed the option -H:SubstitutionFiles=... to register substitutions via a JSON file.

But you can find some information from https://docs.oracle.com/en/graalvm/enterprise/22/docs/reference-manual/native-image/BuildConfiguration/

image

GoodforGod commented 2 years ago

Looks like just devs forgot to clean up this doc, cause I asked them and they confirmed option is deprecated

linux-china commented 2 years ago

@GoodforGod only few developers use substitution feature, and it's not for normal developers. @DynamycProxyHint is good enough for me now :)

GoodforGod commented 2 years ago

Would like a lot to hear your feedback on @DynamicProxyHint, is it working properly, do you like the @DynamicProxyHint.Configuration hint annotation and is it useful, so please share your experience when you will play with it :)

GoodforGod commented 2 years ago

Hello @linux-china any success trying @DynamicProxyHint annotation?:)

linux-china commented 2 years ago

@GoodforGod It works, and I forgot to give you feedback.

@DynamicProxyHint
interface UserService {

    String findNickById(Integer id);
}

class UserServiceHandler implements InvocationHandler {

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return "nick: 1";
    }
}

I think 0.18.0-SNAPSHOT did not merge https://github.com/GoodforGod/graalvm-hint/pull/3 :)

Expect new 0.18.0 version.

GoodforGod commented 2 years ago

Great! Thanks for feedback!

Actually it is merged, but there is slight change, the artifact name is always hint now and package name is same as class package name or default one, so the path for hints is something like: "META-INF/native-image/" + package + "/hint/" + fileName;

If you have any issues with unnamed packages or any other, just let me know

linux-china commented 2 years ago

@GoodforGod I got the following error if without package declare with 0.18.0-SNAPSHOT

error: Couldn't write META-INF/native-image//hint/dynamic-proxy-config.json due to: Invalid relative name: META-INF/native-image//hint/dynamic-proxy-config.json
error: Couldn't write META-INF/native-image//hint/native-image.properties due to: Invalid relative name: META-INF/native-image//hint/native-image.properties
error: Couldn't write META-INF/native-image//hint/reflect-config.json due to: Invalid relative name: META-INF/native-image//hint/reflect-config.json
3 errors
GoodforGod commented 2 years ago

Just published 0.18.0-SNAPSHOT with hotfix for this issue, please refresh dependencies in gradle/maven and try again, hope issue will be resolved :)

linux-china commented 2 years ago

Yes, it works well without package declare now.