Project Lambda: Java Language Specification draft
John Rose
John.Rose at Sun.COM
Thu Jan 28 15:21:57 PST 2010
On Jan 28, 2010, at 1:41 AM, Fredrik Öhrström wrote:
> I think it would be preferable if the lambda-implementation is
> designed in such a way that the JVM can figure this out with only a few
> inlines. No premature optimizations in the bytecode please.
+1 from another JVM hacker.
Also, I'll reaffirm that I think the ECMAScript spec. got the issue of lambda creation correct; see shameless self-quote below. (When I said "compiler" I thought "JVM JIT", but I should have said "runtime system" or something vague like that. I tend to forget that JVM implementors use the word "compiler" like that.)
I don't think, BTW, that this issue links strongly to SAM class constructors. If a lambda is allowed to promote to a SAM class, that is one of the circumstances that would forbid the runtime system from reusing object identities, since constructors are guaranteed to run on fresh instances. SAM interfaces need not have the same restriction, since only Object.<init> is in play there, and we can afford to be indeterminate about whether it executes, as in the case of autoboxing.
-- John
On Jan 23, 2010, at 12:02 AM, John Rose wrote:
>> - The draft
>> tries to take no position on when lambda expression evaluation
>> physically occurs.
>
> +1 It's a similar situation to Integer.valueOf, but with more degrees of freedom.
>
> Basically, if you can get away with hoisting a closure up a few scopes (because no inner scopes are captured), the compiler should be free to do so. The only way to catch the "cheat" is to ask about object identities. Such questions should be defined as having indeterminate answers. Note that the ECMAScript spec. very carefully allows such hoisting for JavaScript closures.
>
> Phrasing this in terms of "when evaluation occurs" may not be the best formula, though. How about saying evaluation occurs at the normal time, but if two evaluations would produce functions with identical behavior, the system is free to return the same function object both times.
More information about the lambda-dev
mailing list