RFR: 8323497: On x64, use 32-bit immediate moves for narrow klass base if possible [v7]
Aleksey Shipilev
shade at openjdk.org
Fri May 23 08:19:04 UTC 2025
On Fri, 23 May 2025 08:03:34 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
>> On x64, we always use the long form of mov immediate to load the klass base into a register. If the klass base fits into 32 bits, we could use the short form and save four instruction bytes.
>>
>> Before: mov uses 10 instruction bytes:
>>
>>
>> 35 ;; decode_klass_not_null
>> 36 0x00007f8b089e51c4: movabs $0x82000000,%r11
>> 37 0x00007f8b089e51ce: add %r11,%r10
>>
>>
>> Now: mov uses 6 instruction bytes:
>>
>>
>> 35 ;; decode_klass_not_null
>> 36 0x00007fbe609e51c4: mov $0x82000000,%r11d
>> 37 0x00007fbe609e51ca: add %r11,%r10
>>
>>
>> Note that this optimization does not depend on zero-based addressing, and therefore we change class space reservation: we now always look in low-address regions first.
>>
>> ----------
>>
>> Tests: tier1 (GHA), tier 2 on x64 linux
>
> Thomas Stuefe has updated the pull request incrementally with four additional commits since the last revision:
>
> - also for encode_klass
> - fix test
> - back to unconditional 4g, but with better comment
> - feedback alexey
This looks fine to me conceptually. I am going to run some tests too. Cosmetics:
src/hotspot/cpu/x86/compressedKlass_x86.cpp line 30:
> 28: #include "oops/compressedKlass.hpp"
> 29: #include "utilities/globalDefinitions.hpp"
> 30: #include "memory/metaspace.hpp"
`make test TEST=sources/` would likely complain about unsorted order.
src/hotspot/cpu/x86/compressedKlass_x86.cpp line 40:
> 38:
> 39: // Unconditionally attempting to reserve in lower 4G first makes always sense:
> 40: // -CDS -COH: try to get unscaled mode (zero base zero shift)
Suggestion:
// -CDS -COH: Try to get unscaled mode (zero base, zero shift)
src/hotspot/cpu/x86/macroAssembler_x86.cpp line 5418:
> 5416: shrq(r, CompressedKlassPointers::shift());
> 5417: }
> 5418: BLOCK_COMMENT("} encode_and_move_klass_not_null");
Copy-paste nit: this is still `encode_klass_not_null`.
-------------
PR Review: https://git.openjdk.org/jdk/pull/17340#pullrequestreview-2863599036
PR Review Comment: https://git.openjdk.org/jdk/pull/17340#discussion_r2104069315
PR Review Comment: https://git.openjdk.org/jdk/pull/17340#discussion_r2104068645
PR Review Comment: https://git.openjdk.org/jdk/pull/17340#discussion_r2104066124
More information about the hotspot-dev
mailing list