[jdk20] RFR: 8298084: Memory leak in Method::build_profiling_method_data [v3]

Coleen Phillimore coleenp at openjdk.org
Tue Dec 13 00:58:40 UTC 2022


On Tue, 13 Dec 2022 00:13:38 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> Coleen Phillimore has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Even more metaprogramming improvements
>
> src/hotspot/share/oops/instanceKlass.cpp line 2675:
> 
>> 2673:   if (release_sub_metadata) {
>> 2674:     methods_do(method_release_C_heap_structures);
>> 2675:   }
> 
> I don't understand this aspect of the change. It seems unrelated to the missing destructor issue and seems to cause a significant change in behaviour as we will no longer call `methods_do` when called from `deallocate_contents` with the renamed `false` argument.

This boolean prevents us from calling the MethodData destructor twice and releasing MethodData C heap memory twice.  InstanceKlass::deallocate_contents calls release_C_heap_structures with it false, and then calls through the Metadata pointer hierarchy to MetadataFactory::free_metadata, which calls the MethodData destructor and MethodData::deallocate_contents which calls MethodData::release_C_heap_structures().   This is the delegation scheme for releasing metadata between InstanceKlass and ConstantPool.

InstanceKlass::release_C_heap_structures() is also called during class unloading and must walk the whole metadata, releasing C heap memory.  It's passed true. It doesn't go through deallocate_contents because the metadata is freed together at the same time with the metaspace that contains it.

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

PR: https://git.openjdk.org/jdk20/pull/13


More information about the hotspot-dev mailing list