codeconsole opened a new issue, #16754:
URL: https://github.com/apache/grails-core/issues/16754

   To start in a native image without recorded metadata, the framework 
registers the declared methods of every trait helper it scans for reflection: 
each `$Trait$Helper`, `$Trait$FieldHelper` and `$Trait$StaticFieldHelper` 
(`BytecodeRuntimeHints`, added in #16180, the `traitHelpers` loop in 
`register`). Its javadoc gives the reason. A class implementing a trait 
initializes it from its constructor by calling the helper's `$init$` through 
`ScriptBytecodeAdapter.invokeMethodN`, a dynamic call, even in a 
`@CompileStatic` class. The framework's traits sit on the application class, 
the controllers, the tag libraries and the domain classes. Without the 
registration none of them can be created, and the application class itself 
fails first with "No signature of static method: $init$".
   
   apache/groovy#3025 makes that call direct. Implementing classes now call 
`T$Trait$Helper.$init$(T)` with an `invokestatic`, in dynamic and statically 
compiled classes alike, including the classes `withTraits` and `as Trait` 
generate at run time.
   
   ## What to change once a Groovy release with apache/groovy#3025 is in use
   
   - [ ] Re-evaluate the trait-helper registration in `BytecodeRuntimeHints`. 
The `$Trait$Helper` registration exists for the `$init$` call, which no longer 
needs reflection.
   - [ ] Keep the field helpers unless the native-i18n checks pass without 
them. In a trait that is not statically compiled, the helper's own `$init$` 
body still writes the trait's fields through the field helper's methods with 
invokedynamic. A narrower option is to register the helpers only for traits 
that are not statically compiled.
   - [ ] Update the trait bullet in `BytecodeRuntimeHints`' javadoc and the 
matching bullet in `deploymentAot.adoc` ("initializing a trait from a class 
that implements it"), so they describe what is still registered and why.
   - [ ] Update `BytecodeRuntimeHintsSpec`'s trait features to match: 'a trait 
can be initialized by the classes implementing it', 'a trait helper is 
registered under the name its class has' and 'the trait still initializes' 
(fixtures `GreetingTraitFixture`/`GreeterFixture` and 
`OptionalDependencyTraitFixture`).
   - [ ] Build the native-i18n image and run its checks: `./gradlew 
:native-i18n:check -PnativeTests` from `end-to-end`, with a GraalVM 
`JAVA_HOME`. The application class, a controller, a tag library and a domain 
class must all still be created.
   
   ## Groovy version
   
   apache/groovy#3025 targets Groovy master (7.0.0-SNAPSHOT). Grails 9 builds 
with Groovy 6.0.x, so it only benefits once the change is backported to 
`GROOVY_6_0_X`; the PR asks for that.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to