RFR: 8316694: Implement relocation of nmethod within CodeCache [v2]

Chad Rakoczy duke at openjdk.org
Fri Mar 14 20:49:42 UTC 2025


On Fri, 14 Mar 2025 12:04:29 GMT, Evgeny Astigeevich <eastigeevich at openjdk.org> wrote:

>> src/hotspot/share/code/nmethod.cpp line 1404:
>> 
>>> 1402:   memcpy(nm_copy, this, size());
>>> 1403: 
>>> 1404:   // Allocate memory and copy immutable data from C heap
>> 
>> A new immutable data block is allocated for the new nmethod. Would it be possible to reuse the old one instead? This could help reduce memory allocation overhead, though it would make the logic more complicated. The destroyed nmethod should consider whether it is the last one holding the immutable nmethod blob. Probably, concurrent modification issues could arise. What do you think?
>
>> A new immutable data block is allocated for the new nmethod. Would it be possible to reuse the old one instead? ... What do you think?
> 
> You are reading our minds :)
> Yes, we have discussed this. This sharing must be thread safe. We need to research whether it won't increase complexity.

I added a reference counter to the end of immutable data. The only time the value is accessed/updated is during nmethod creation or destruction both of which hold the `CodeCache_lock` so I believe concurrent modifications should not be an issue

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23573#discussion_r1996254997


More information about the hotspot-compiler-dev mailing list