-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
Java: Better support for GraalVM native images #6497
Comments
By default generated classes have generated code for equals and hashCode. Are you using java-lite? |
If I try to compile a dummy application to a native image using graalvm I get the following error during compilation. (protobuf 3.10.0) The error is caused by the usage of MethodHandles, which are unsupported by graalvm native images.
If I try to use the If I try to set GeneratedMessageV3#forTestUseReflection to true and invoke it again, the same error is shown. I have tried to substitute the call to It works with protobuf-java 3.9.2 (Haven't tested all aspects yet). |
Having just used pb in the context of GraalVM native images for the first time, I ended up configuring native-image for reflection code around this project. I'm surprised that pb for Java uses reflection. I'm sure there are good reasons from a historical perspective, but a reflection-free pb sounds like something to strive for. |
@huntc I recommend the "lite" runtime if you want to be reflection free: |
Good to know! Thanks! However, perhaps avoiding reflection is still worth striving for with the main code base given the caveats associated with Lite? |
There are still good reasons to use reflection in the main implementation (based on APIs we've published that effectively require it), so we'll likely leave it as is for now, but this is why we have the lite flavor, to allow folks to decide what is best for them. |
Thanks for the further insight. Should this issue therefore be closed given your answer of using lite for when dealing with GraalVM? Btw, and for more info, there are transitive dependency situations that aren’t avoidable. For this, perhaps guidance docs for GraalVM usage might be useful. Thoughts? |
If you'd like to contribute said docs, I'd be happy to approve! I'll go ahead and close this as suggested. Thanks! |
Thanks. Happy to raise a PR. Can you recommend a link to an appropriate doc page source? |
Here would be perfect: |
Currently, Java generated messages use reflection to implement
equals
/hashCode
/toString
. This places a large burden on anyone using protobuf with GraalVM native images, since any class that gets reflected over needs to have an explicit reflection configuration created for it so that GraalVM native images can know to provide that information during reflection. Replacing the reflection with generated code would be of a big help to GraalVM native image users.The text was updated successfully, but these errors were encountered: