RFR: 8291457: Clean up lifecycle of CDS dump-time data structures

Ioi Lam iklam at openjdk.org
Wed Aug 3 17:52:25 UTC 2022


On Wed, 3 Aug 2022 17:45:17 GMT, Calvin Cheung <ccheung at openjdk.org> wrote:

>> I've rewritten the following data CDS structures to follow the [C++ rule-of-three](https://en.cppreference.com/w/cpp/language/rule_of_three) to improve their lifecycle handling and fix a memory leak. This is done to prepare for future CDS changes that make more allocations during archive creation.
>> 
>>> Rule of Three: If a class requires a user-defined destructor, a user-defined copy constructor, or a user-defined copy assignment operator, it almost certainly requires all three.
>> 
>> - DumpTimeClassInfo
>> - DumpTimeClassInfo::DTLoaderConstraint
>> - DumpTimeClassInfo::DTVerifierConstraint
>> - DumpTimeLambdaProxyClassInfo
>> 
>> I implemented some of the assignment operators using the [copy-and-swap idiom](https://en.cppreference.com/w/cpp/language/copy_assignment) to handle `Symbol` refcounting. Thanks to @kimbarrett for the suggestion.
>
> src/hotspot/share/cds/dumpTimeClassInfo.hpp line 69:
> 
>> 67:       maybe_increment_refcount(_name);
>> 68:     }
>> 69:     DTLoaderConstraint& operator=(DTLoaderConstraint src) {
> 
> Could the src be passed as reference?

To use the copy-and-swap idiom, which makes the assignment operator reliably, src needs to be passed by value. See https://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom

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

PR: https://git.openjdk.org/jdk/pull/9722


More information about the hotspot-runtime-dev mailing list