About native support for lazy constants

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

About native support for lazy constants

Daniel.Sun
Hi all,

      I read an article[1] about the new features of Java 11 just now, and
find "JEP 309: Dynamic Class-File Constants"[2] can help us implement lazy
constants elegantly, e.g. `@Lazy static final Object SOME_LAZY_CONST =
<heavy lifts>`. The feature is very useful, so I propose to add *native*
support for lazy constants in some future version of Groovy.

      Any thoughts?

Cheers,
Daniel.Sun
[1]
https://javabeginnerstutorial.com/core-java-tutorial/java-11-new-features/
[2] https://openjdk.java.net/jeps/309



-----
Apache Groovy committer & PMC member
Blog: http://blog.sunlan.me 
Twitter: @daniel_sun

--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun
Reply | Threaded
Open this post in threaded view
|

Re: About native support for lazy constants

Remi Forax
Several things to know:
- you can rewrite all access to a field marked @Lazy to use a constant dynamic,
  that part can already be implemented. If you want to keep the compatibility
  with Java 8, it means that you have to have two translations one for Java 11+
  and one for Java 10-.
- if you want the bytecode getstatic to access the field, here you need the VM
  to be changed, it's in the roadmap for the VM but not yet implemented
- you don't care about getstatic because you can simulate it with an indy*
  (which means that even with @CompileStatic you will use indy)
  in that case you can implement it but it means that all codes that use
  a combination of @Lazy + @CompileStatic has to be recompiled.

Rémi

* there is actually no support of ldc constantdynamic in java.lang.invoke.


----- Mail original -----
> De: "sunlan" <[hidden email]>
> À: "dev" <[hidden email]>
> Envoyé: Dimanche 12 Janvier 2020 13:34:22
> Objet: About native support for lazy constants

> Hi all,
>
>      I read an article[1] about the new features of Java 11 just now, and
> find "JEP 309: Dynamic Class-File Constants"[2] can help us implement lazy
> constants elegantly, e.g. `@Lazy static final Object SOME_LAZY_CONST =
> <heavy lifts>`. The feature is very useful, so I propose to add *native*
> support for lazy constants in some future version of Groovy.
>
>      Any thoughts?
>
> Cheers,
> Daniel.Sun
> [1]
> https://javabeginnerstutorial.com/core-java-tutorial/java-11-new-features/
> [2] https://openjdk.java.net/jeps/309
>
>
>
> -----
> Apache Groovy committer & PMC member
> Blog: http://blog.sunlan.me
> Twitter: @daniel_sun
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
r
MG
Reply | Threaded
Open this post in threaded view
|

Re: About native support for lazy constants

MG
In reply to this post by Daniel.Sun
Hi Daniel,

I have no technical input, but I use @Lazy all the time, it's a great
Groovy feature to avoid boilderplate code - so making it (internally)
better sounds like a good idea, if it is not too much effort G-)

Cheers,
mg


On 12/01/2020 13:34, Daniel.Sun wrote:

> Hi all,
>
>        I read an article[1] about the new features of Java 11 just now, and
> find "JEP 309: Dynamic Class-File Constants"[2] can help us implement lazy
> constants elegantly, e.g. `@Lazy static final Object SOME_LAZY_CONST =
> <heavy lifts>`. The feature is very useful, so I propose to add *native*
> support for lazy constants in some future version of Groovy.
>
>        Any thoughts?
>
> Cheers,
> Daniel.Sun
> [1]
> https://javabeginnerstutorial.com/core-java-tutorial/java-11-new-features/
> [2] https://openjdk.java.net/jeps/309
>
>
>
> -----
> Apache Groovy committer & PMC member
> Blog: http://blog.sunlan.me
> Twitter: @daniel_sun
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Reply | Threaded
Open this post in threaded view
|

Re: About native support for lazy constants

Daniel.Sun
In reply to this post by Remi Forax
Hi Rémi,

> - if you want the bytecode getstatic to access the field, here you need the VM
>   to be changed, it's in the roadmap for the VM but not yet implemented

I wish we could still access the constants with bytecode getstatic, which is simple enough for us to use and read, but I do not know which version of Java will support the feature. Luckily, no rush to have the native lazy constants support, we can wait ;-)

    Thanks for your suggestions and detailed explaination.

Cheers,
Daniel.Sun
On 2020/01/12 15:19:08, Remi Forax <[hidden email]> wrote:

> Several things to know:
> - you can rewrite all access to a field marked @Lazy to use a constant dynamic,
>   that part can already be implemented. If you want to keep the compatibility
>   with Java 8, it means that you have to have two translations one for Java 11+
>   and one for Java 10-.
> - if you want the bytecode getstatic to access the field, here you need the VM
>   to be changed, it's in the roadmap for the VM but not yet implemented
> - you don't care about getstatic because you can simulate it with an indy*
>   (which means that even with @CompileStatic you will use indy)
>   in that case you can implement it but it means that all codes that use
>   a combination of @Lazy + @CompileStatic has to be recompiled.
>
> Rémi
>
> * there is actually no support of ldc constantdynamic in java.lang.invoke.
>
>
> ----- Mail original -----
> > De: "sunlan" <[hidden email]>
> > À: "dev" <[hidden email]>
> > Envoyé: Dimanche 12 Janvier 2020 13:34:22
> > Objet: About native support for lazy constants
>
> > Hi all,
> >
> >      I read an article[1] about the new features of Java 11 just now, and
> > find "JEP 309: Dynamic Class-File Constants"[2] can help us implement lazy
> > constants elegantly, e.g. `@Lazy static final Object SOME_LAZY_CONST =
> > <heavy lifts>`. The feature is very useful, so I propose to add *native*
> > support for lazy constants in some future version of Groovy.
> >
> >      Any thoughts?
> >
> > Cheers,
> > Daniel.Sun
> > [1]
> > https://javabeginnerstutorial.com/core-java-tutorial/java-11-new-features/
> > [2] https://openjdk.java.net/jeps/309
> >
> >
> >
> > -----
> > Apache Groovy committer & PMC member
> > Blog: http://blog.sunlan.me
> > Twitter: @daniel_sun
> >
> > --
> > Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
> r
>
Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun