RFR: 8373794: Move nmethod header from CodeCache
Andrew Haley
aph at openjdk.org
Tue Jan 27 10:12:39 UTC 2026
On Wed, 17 Dec 2025 11:34:46 GMT, Mikhail Ablakatov <mablakatov at openjdk.org> wrote:
> nmethod objects in the CodeCache have the following layout:
>
>
> | CodeBlob header | NMethod header | Constants | MainCode | StubCode | Data/oops |
>
>
> Although mutable and immutable metadata have already been moved out of the code cache by JDK-8343789 and JDK-8331087 respectively, the embedded `nmethod` header fields still occupy ~160 B (with the `CodeBlob` header adding another 64 B). In JDK25 the total header footprint is 224 B. This space is reserved inside executable memory, which decreases overall executable code density.
>
> This patch relocates the `nmethod` header to a C-heap-allocated structure and keeps only 8-byte pointer to that header in the CodeCache. The resulting layout is:
>
>
> | CodeBlob header | Ptr to NMethodHeader | Constants | MainCode | StubCode | Data/oops |
>
>
> This change reduces the size of the CodeCache-resident header from 224 B to 72 B (64 B `CodeBlob` header + 8 B pointer), achieving roughly a **3x reduction** in header footprint.
>
> This change follows the direction established by JDK-7072317, JDK-8331087 and JDK-8343789.
>
> ## Testing
>
> The patch has passed `tier1-3` and `hotspot_all` tests on AArch64 and x86_64.
src/hotspot/share/code/nmethod.cpp line 487:
> 485: void nmethod::set_deoptimized_done() {
> 486: ConditionalMutexLocker ml(NMethodState_lock, !NMethodState_lock->owned_by_self(), Mutex::_no_safepoint_check_flag);
> 487: if (_hdr->_deoptimization_status != NMethodHeader::deoptimize_done) { // can't go backwards
Suggestion:
if (deoptimization_status() != deoptimize_done) { // can't go backwards
Create an accessor for `deoptimization_status`. Why is it now necessary to use `NMethodHeader::`?
src/hotspot/share/code/nmethod.cpp line 1301:
> 1299: _hdr->_compiler_type = type;
> 1300: _hdr->_orig_pc_offset = 0;
> 1301: _hdr->_num_stack_arg_slots = 0;
It'd be better to move this into a separate initializer for `NMethodHeader`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28866#discussion_r2731224628
PR Review Comment: https://git.openjdk.org/jdk/pull/28866#discussion_r2731235594
More information about the hotspot-dev
mailing list