Skip to content

Introduce AOT generated class proxies #28115

Closed

Description

@sdeleuze

GraalVM native-image only supports JDK dynamic proxies when configured explicitly on interfaces.

For proxies on classes, typically created at runtime with CGLIB on the JVM, there is a need to create such proxies Ahead-Of-Time. That's what @aclement did in Spring Native:

Spring Framework 6 should provide similar support for AOT generated class proxies, potentially by:

  • Leveraging ClassProxyHint to configure them
  • Deciding how the creation of the proxy should be implemented
  • Plug it into the AOT processing
  • Implement proper inferring if possible
  • Replace the substitution by proper handling in DefaultAopProxyFactory and/or other relevant classes

Activity

  1. added this to the 6.0.0-M4 milestone on Feb 28, 2022
  2. aclement commented on Feb 28, 2022

    @aclement
    Contributor

    Just a bit more context. I could have built my own proxy generation but it would have taken a while and I wasn't in a position to easily test it rigorously for all spring use cases. So I leveraged #1283 which replaced CGLIB with byte buddy because I knew that was passing the tests, and it would give me an easier route to pushing proxy generation to being something I could drive at build time rather than runtime. It had mechanisms for easily grabbing the bytecode for the proxy, and total control over the proxy naming (because when looking them up at runtime it had to exactly match what was created earlier).

    Importantly it was also generating a more optimal proxy that was using less of the generated support classes for invoking some methods. For 'well known' interfaces that the proxy was implementing it was directly wiring up the invocations. Whereas CGLIB was using a general approach for all methods, leading to lots of new classes. (However, hand crafting could have also performed these optimizations, obviously).

    The current version was definitely constructed as a building block. Ideally the necessary proxies could be more inferred rather than the user trying to work out what set of 'bits' they need to supply for proxy hints, or discovering it by trial and error when running the system is printing out the required hints.

  3. aclement commented on Feb 28, 2022

    @aclement
    Contributor

    The commit encompassing all these changes in spring-native is spring-attic/spring-native@af0e804

  4. sdeleuze commented on Mar 2, 2022

    @sdeleuze
    ContributorAuthor

    Related topic : Spring Native we currently relies on Hibernate Build-time enhancement to perform Hibernate bytecode manipulation at build time. I mention that because:

    • It could be interesting to see how they implemented that.
    • This seems not super actively maintained (for example, no Gradle Kotlin DSL support if I remember correctly).
    • Using that imply painful additional build configuration, we may be interested by a more integrated approach.

    Maybe a point to discuss with @mp911de, @schauder and @christophstrobl.

  5. added
    in: coreIssues in core modules (aop, beans, core, context, expression)
    on Mar 29, 2022
  6. modified the milestones: 6.0.0-M4, 6.0.0-M5 on May 4, 2022
  7. added 3 commits that reference this issue on Jul 8, 2022
  8. modified the milestones: 6.0.0-M5, 6.0.0-M6 on Jul 8, 2022
  9. jhoeller commented on Aug 10, 2022

    @jhoeller
    Contributor

    There is an initial commit coming to main now: This includes runtime storing of generated classes to a directory specified by the "cglib.generatedClasses" system property, to be picked up by the build process for further inclusion in a jar file (and ultimately in a native image). We also avoid lazy CGLIB fast-class generation now and replace the generated Enhancer and MethodWrapper key classes with equivalent record types. Last but not least, this introduces support for early type determination in InstantiationStrategy, AopProxy and SmartInstantiationAwareBeanPostProcessor - in order to trigger CGLIB class generation in refreshForAotProcessing (through early determineBeanType calls for bean definitions).

  10. added a commit that references this issue on Sep 17, 2026
    b31a158
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: aotAn issue related to Ahead-of-time processingtype: enhancementA general enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions