RFR: 8316661: CompilerThread leaks CodeBlob memory when dynamically stopping compiler thread in non-product
Thomas Schatzl
tschatzl at openjdk.org
Thu Sep 21 19:47:46 UTC 2023
On Thu, 21 Sep 2023 19:37:58 GMT, Vladimir Kozlov <kvn at openjdk.org> wrote:
>> Hi all,
>>
>> please review this change to fix a memory leak I found when having `CodeCache::free` call the destructor of `CodeBlob`: when adding the latter, one gets assertion failures that the native memory that `_asm_remarks` and `_dbg_strings` members were not deallocated properly when
>> * stopping a compiler thread due to dynamic compiler thread policy
>> * shutting down the compiler runtime
>>
>> Testing: gha
>>
>> Thanks,
>> Thomas
>
> src/hotspot/share/code/codeCache.cpp line 609:
>
>> 607: cb->~CodeBlob();
>> 608: // Get heap for given CodeBlob and deallocate
>> 609: get_code_heap(cb)->deallocate(cb);
>
> I am not sure it look correct - `cb` is used after you call destructor.
> I think it works because destructor only has assert but I don't think it is right thing to do here.
`get_code_heap` and `deallocate` only use the address as a chunk of memory, but not as a `CodeBlob`.
Maybe the parameter to `get_code_heap` should be made `void*` too to make it clear that what's passed here is an opaque address?
`deallocate` unwraps the given pointer to a `HeapBlock` immediately (and gets `cb` as a `void*`), not treating it as a `CodeBlob` any more.
So I think it is the appropriate location to call the destructor.
These two lines resemble a `delete` call: first call the destructor, then pass the pointer to `free`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15858#discussion_r1333528215
More information about the hotspot-compiler-dev
mailing list