[ 
https://issues.apache.org/jira/browse/LOG4J2-2649?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17537265#comment-17537265
 ] 

Matt Sicker commented on LOG4J2-2649:
-------------------------------------

The DI system migration has completed earlier this year, and I've been looking 
back over the backlog for things that were related, and this issue is one of 
them. I've managed to refactor a lot of static initialization via two 
strategies: singleton-scoped beans from dependency injection and use of a 
LazyValue holder class that allows for lazy initialization on use rather than 
on class load for places that haven't been able to be injectable. Due to issues 
with JPMS, we aren't using MethodHandles anywhere as they're harder to get 
module opening to work properly with, so regular reflection APIs are still in 
use there.

While it probably won't be ready for 3.0.0, this does leave open the 
possibility for generating more metadata or code to avoid performing reflection 
at runtime. There's the Avaje framework for example which implements both 
reflection and code generation for inspiration on how to do similarly.

One thing that is already possible with the code now, though, would be to 
define an InjectorCallback service class that sets up the bindings for things 
statically without further setup logic being executed. For example, you could 
construct a ConfigurationFactory binding right there to construct a 
statically-created Configuration instance, and the startup time would mostly 
depend on how quickly those classes can be loaded from disk in the first place 
(regardless of execution environment).

Since this has some overlap with LOG4J2-2795, [~romain.manni-bucau], have you 
tried out master with Graal lately? I wonder if this works more easily.

>  Is Log4j2 considered to support successful static compilation under GraalVM?
> -----------------------------------------------------------------------------
>
>                 Key: LOG4J2-2649
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2649
>             Project: Log4j 2
>          Issue Type: New Feature
>            Reporter: YangGuanchao
>            Priority: Blocker
>   Original Estimate: 168h
>  Remaining Estimate: 168h
>
> Oracle released GraalVM [https://github.com/oracle/graal] to support the 
> static compilation of Java applications to Native Image, which can increase 
> the startup speed of Java by at least 10 times. In the cloud native field, 
> this basic technology is believed to be in the near future. Will be supported 
> by more and more vendors, such as the Spring/Spring Boot community has 
> supported or plans to support the feature of GraalVM, see this issue: 
> [https://github.com/spring-projects/spring-framework/search?q=Graalvm&type=Issues]
>  can support static compilation, so it is recommended that Log4j2 also need 
> to support static compilation as soon as possible, and can be compiled 
> correctly under GraalVM.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to