Not-yet-discussed in HotSpot style guide: C++ Lambdas

Stefan Karlsson stefan.karlsson at oracle.com
Mon Aug 16 06:19:43 UTC 2021



On 2021-08-14 20:25, Kim Barrett wrote:
>> On Aug 14, 2021, at 5:28 AM, Andrew Haley <aph-open at littlepinkcloud.com> wrote:
>>
>> https://github.com/openjdk/jdk/blob/master/doc/hotspot-style.md says:
>>
>> "Undecided Features
>>
>> This list is incomplete; it serves to explicitly call out some
>> features that have not yet been discussed.  ...  Lambdas"
>>
>> I can't see any reason to forbid Lambdas from a performance point of
>> view, and they can add to readability and maintainability in C++ for
>> the same reasons that they do in Java.
>>
>> I have a job I'm working on (in the AArch64 back end) where Lambdas
>> would be very useful.  How about I give it a try, and I'll produce the
>> patch for review, as an initial proposal? Then anyone can put in their
>> 2c worth.
> Funny you should mention lambdas.  There has been a fair amount of
> discussion around them internally here at Oracle.  And there are some
> folks trying them out in not-yet-ready-for-production work.

We've been trying this out in the zgc_generational branch:

https://github.com/openjdk/zgc/tree/zgc_generational

For anyone that wants to take a look, search for [&].

>    I’ve drafted
> a style-guide modification reflecting that discussion, along with a couple
> examples, and am planning to open a PR in the next few days.
>
> You can see the current work in progress here:
>
> https://github.com/kimbarrett/openjdk-jdk/tree/permit_lambda
>
> Note that I'm planning to rebase and do some commit refactoring / reordering
> before opening the PR.
>
> There is one downside that has recently been noted.  Stack frame names
> in stack traces where lambdas are involved are pretty indecipherable.

Just to give an example what the frames sometimes look like in the debugger:

#3 
ZPageTableParallelIterator::do_pages<ZGenerationPagesParallelIterator::do_pages<ZRememberScanPageTask::work()::{lambda(ZPage*)#1}>(ZRememberScanPageTask::work()::{lambda(ZPage*)#1})::{lambda(ZPage*)#1}>(ZGenerationPagesParallelIterator::do_pages<ZRememberScanPageTask::work()::{lambda(ZPage*)#1}>(ZRememberScanPageTask::work()::{lambda(ZPage*)#1})::{lambda(ZPage*)#1})::{lambda(int)#1}::operator()(int) 
const (index=<optimized out>, this=<optimized out>) at 
/home/stefank/git/alt/open/src/hotspot/share/gc/z/zPageTable.inline.hpp:75

It's not this bad all the time, but it seems easy to end up in this 
situation when you write generic iterator code that accepts lambdas.

StefanK

>



More information about the guide-dev mailing list