First draft of translation document

Nathan Bryant nathan.bryant at linkshare.com
Thu May 20 10:32:38 PDT 2010


Brian,

Thanks for reiterating this.

Can that sort of thing be made safe from a permgen churn perspective?
Seems like it can't kick in unless the VM sees a runtime profile where
functions are always constructed (partially applied) from a small,
consistent set of arguments.

More generally: at least in principle, the VM has analogous information
available to it for every object that is constructed with final fields,
but there must be some reasons why it doesn't do the analogous
optimization there. (i.e. automatically generate specialized subclasses
wherever it feels like, and dead code eliminate everything that touches
a final field!)

-----Original Message-----
From: Brian Goetz [mailto:brian.goetz at oracle.com] 
Sent: Thursday, May 20, 2010 11:33 AM
To: Nathan Bryant
Cc: Howard Lovatt; lambda-dev at openjdk.java.net
Subject: Re: First draft of translation document

> With regard to the recent proposals, the advantages of interface
> injection are clear. I do not see any clear advantage to MethodHandle
> with bind for partial application (but maybe I'm just missing
something)

Yes, you're missing something: optimization!

To take a simple example, lets say I have a function

   f(x, y) { if (x != null) x.foo() else y.foo() }

If I partially apply x, now x is a constant for purposes of compilation.
So 
if I partially apply a null x argument, the test and branch get 
dead-code-eliminated and it reduces to

   f(y) { y.foo() }

This may not seem like a big deal, but partial application gives the VM
way 
more information -- type information, nullity information, array bounds 
information -- with which it can perform all sorts of optimizations
(type 
sharpening which leads to better inlining, null check elimination, array

bounds check elimination, dead code elimination, etc).



More information about the lambda-dev mailing list