RFR: 8276789: Support C++ lambda in ResourceHashtable::iterate [v4]
Stefan Karlsson
stefank at openjdk.java.net
Wed May 25 06:31:09 UTC 2022
On Tue, 24 May 2022 16:21:18 GMT, Ioi Lam <iklam at openjdk.org> wrote:
>> src/hotspot/share/classfile/systemDictionaryShared.cpp line 672:
>>
>>> 670: SystemDictionaryShared::check_for_exclusion(k, &info);
>>> 671: };
>>> 672: _dumptime_table->iterate_all(check_for_exclusion);
>>
>> Can't this be changed to just:
>> `_dumptime_table->iterate_all(SystemDictionaryShared::check_for_exclusion);`
>>
>> or maybe even:
>> `_dumptime_table->iterate_all(check_for_exclusion);`
>
> The second parameter to `SystemDictionaryShared::check_for_exclusion()` is a `DumpTimeClassInfo*` because NULL is allowed. However, the iterator requires a `DumpTimeClassInfo&`.
OK
>> src/hotspot/share/utilities/resourceHash.hpp line 210:
>>
>>> 208: };
>>> 209: iterate(function);
>>> 210: }
>>
>> Do you still have any usages of this? I'm a bit surprised that the compiler don't complain about not being able to disambiguate calls to this vs the new lambda enabled function.
>
> This is still needed as there are many places that use the old style iteration. Also, when the body of the iteration is complex, it might be more readable to do it as a separate class. E.g., here in systemDictionaryShared.cpp:
>
>
> UnregisteredClassesDuplicationChecker dup_checker;
> _dumptime_table->iterate(&dup_checker);
>
>
> I think there's no ambiguity because `iter->do_entry()` cannot be substituted with the other template, and `function(node->_key, node->_value)` in the other template cannot be substituted here. So by SFINAE the C++ compiler can pick the correct template.
Interesting. I got problems when I converted BitMap to support both closures and lambdas. The problem might have been that the iterate function took an specific closure class, and didn't use a template.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8761
More information about the hotspot-dev
mailing list