Lambda vs anon class optimization effect on CHA
Vitaly Davidovich
vitalyd at gmail.com
Wed Aug 10 13:29:23 UTC 2016
Sorry, forgot to mention that this is on 8u51.
On Wed, Aug 10, 2016 at 9:28 AM, Vitaly Davidovich <vitalyd at gmail.com>
wrote:
> Hi all,
>
> Suppose we have the following classes and code:
>
> public abstract class Foo {
> public static java.util.Supplier<Foo> null() {
> return () -> Null.INSTANCE;
>
> }
>
> // some abstract methods
> }
>
> public final class Impl extends Foo {}
>
> public final class Null extends Foo {
> public static final Null INSTANCE = new Null();
>
> }
>
> It seems that the lambda in null(), even when not invoked, causes Null to
> be loaded and single-class CHA optimization is disabled. If I change
> null() to use an anon class:
>
> public static java.util.Supplier<Foo> null() {
> return new Supplier<Foo>() {
> public Foo get() { return Null.INSTANCE; }
> }
> };
> }
>
> Then CHA kicks in. Keep in mind that the code I'm running never invokes
> null() and only instantiates Impl, so the expectation is that Null would
> not load (and disable the single impl CHA optimization).
>
> My understanding was that the lambda in null() would have a bootstrap
> method that invokes the lambda metafactory to actually bind the call to the
> synthetic static method that's generated, which in turn actually references
> Null.INSTANCE (and would cause the class to load). However, I'm clearly
> missing or misunderstanding something.
>
> Would anyone be able to explain the above situation? Is that expected? Let
> me know if you need more info.
>
> Thanks
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20160810/a63389b7/attachment.html>
More information about the hotspot-compiler-dev
mailing list