RFR: 8264707: HotSpot Style Guide should permit use of lambda [v2]

Coleen Phillimore coleenp at openjdk.java.net
Tue Oct 5 15:59:12 UTC 2021


On Sat, 25 Sep 2021 00:14:50 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> src/hotspot/share/compiler/compilerOracle.cpp line 787:
>> 
>>> 785: 
>>> 786:   char* original_line = os::strdup(line, mtInternal);
>>> 787:   auto g = make_guard([&] { os::free(original_line); });
>> 
>> I have to admit that this usage is very mysterious.  I know you're going to take it out but using lambdas for something that's really hard to parse doesn't seem like a win.  Does save lines of code though.
>
> I think a different approach may be possible, that would have usage like this:
> 
> char* original_line = os::strdup(line, mtInternal); 
> ScopeGuard guard([&] { os::free(original_line); });
> 
> This would use something like (or maybe directly use) a solution to the type-erased lambda capturing problem a la std::function.

Yes, this second usage looks like the typical RAII object that is familiar in the code.

-------------

PR: https://git.openjdk.java.net/jdk/pull/5144


More information about the hotspot-dev mailing list