Fwd: Will lambdas be inline?

Brian Goetz brian.goetz at oracle.com
Sun Apr 12 16:15:29 UTC 2020


The below was received on the -comments list.

Short answer: Yes, this is very much under consideration; the identity 
of a lambda is irrelevant, and JLS 15.27.4 makes this clear:

>     This implies that the identity of the result of evaluating a 
> lambda expression (or, of serializing and deserializing a lambda 
> expression) is unpredictable, and therefore identity-sensitive 
> operations (such as reference equality (§15.21.3), object locking 
> (§14.19), and the System.identityHashCode method) may produce 
> different results in different implementations of the Java programming 
> language, or even upon different lambda expression evaluations in the 
> same implementation.
>

It is likely that this change will expose more opportunities for escape 
analysis, though it would likely not expose significant flatness/density 
optimizations since field descriptors / array components would never 
name the inline proxy directly.  Still, this is exactly the sort of 
optimization we had in mind when we penned the above flexibility in 15.27.4.

As to accidental behavioral compatibility concerns, this change will 
make _more_ lambdas equal to each other, since `==` on two lambda 
instances would no longer be an identity comparison, but a comparison of 
all the state of the lambda, so two otherwise-identical but separately 
constructed lambda proxies would be `==` if they were inline but might 
not be under the current situation, but it is unlikely to go in the 
other direction.

On the other hand, it will make `==` operations on lambdas slower.

Overall I'd like to see this change made, but we have to work through 
the details to ensure that it is not excessively surprising.


-------- Forwarded Message --------
Subject: 	Will lambdas be inline?
Date: 	Sat, 11 Apr 2020 21:14:22 -0700
From: 	Steven Stewart-Gallus <stevenselectronicmail at gmail.com>
To: 	valhalla-spec-comments at openjdk.java.net



Hi

I was curious if lambdas will be inline?
I feel this is pretty natural.
You're already not really supposed to be doing these kinds of things with
lambdas.
Technically you could spin both depending on the situation.

Correct me if I'm wrong but under the current plan you'd need to use
InlineCont for the best performance.

interface Cont {
Cont next();
}

interface InlineCont extends InlineObject {
InlineCont next();
}

interface IdentityCont extends IdentityObject {
IdentityCont next();
}

Slightly unfortunate because I think it's highly unlikely many interfaces
will break compat for a slight perf boost.

And if lambdas are inline than would IdentityCont not be a functional
interface?
Thanks
Steven Stewart-Gallus



More information about the valhalla-dev mailing list