spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.67k stars 38.15k forks source link

Add support for GraalVM `lambdaCapturingTypes` #29655

Closed ccwxl closed 1 year ago

ccwxl commented 1 year ago

Affects: Spring Framework 6.0.2


bclozel commented 1 year ago

I don't understand what's expected of us here. Spring Framework requires GraalVM 22.3 as a baseline, so I guess this feature is already present?

Do you have a sample Spring application that fails currently because of something missing here? Do you want to register "lambdaCapturingTypes" metadata yourself and would like this to be introduced in RuntimeHints and more specifically SerializationHints?

Without more information and a concrete use case it's hard for us to decide what to do here.

ccwxl commented 1 year ago

yes. In Spring 6 I encountered the inability to register lambdaCapturingTypes programmatically

bclozel commented 1 year ago

After having a second look at the MyBatis issue I understand now. This is also something we were interested in for libraries that create lambdas as a way to make reflection faster.

Those cannot be detected during the AOT phase as they usually require running the code.

We can include this on the RuntimeHints API but I'm not sure we should surface it on an annotation as there is no place for this for now. Marking for team attention to discuss this. Thanks for creating this issue!

ccwxl commented 1 year ago

Thanks reply . At this stage, I use the following method to solve this problem

  1. add native-image.properties
    Args =--features=com.example.demo.RuntimeRegistrationFeature
  2. on duringSetup stage register registerLambdaCapturingClass
    public class RuntimeRegistrationFeature implements Feature {
    @Override
    public void duringSetup(DuringSetupAccess access) {
        System.out.println("duringSetup register MpController.");
        RuntimeSerialization.registerLambdaCapturingClass(MpController.class);
        RuntimeSerialization.register(SerializedLambda.class, SFunction.class);
    }
    }
sdeleuze commented 1 year ago

@siaron I understand the aask, but I would like to assess how frequent is the need for this, could you please share a minimal repro of a failing project and more details on your concrete use case (needed for your code, a library, etc.) ?

spring-projects-issues commented 1 year ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 1 year ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

grpubr commented 4 months ago

Do you want to register "lambdaCapturingTypes" metadata yourself and would like this to be introduced in RuntimeHints and more specifically SerializationHints?

YES, and also proxies

according documents in https://www.graalvm.org/latest/reference-manual/native-image/metadata/ serialization-config.json support "types" "lambdaCapturingTypes" and "proxies" but now SerializationHints just support types.

now thing may work if we write serialization-config.json manually or generate by a spring test in normal mode(not in native test). because we can approach spring beans in test. while "Feature" nativeimage are restricted, we can not get enough information to get the class we need in build time.

grpubr commented 4 months ago

/reopen

bclozel commented 4 months ago

@grpubr Our RuntimeHints API is not meant to mirror the GraalVM metadata format, but rather provide actionable API for Spring AOT support. As it stands, there is no way for Spring to detect and declare lambda capturing types. If you would like to declare "lambdaCapturingTypes" metadata, you can do so by writing your own "serialization-config.json" file in a different namespace.

Now for proxies, we do support this type of metadata through RuntimeHints#proxies().