RFR: 8377307: Refactor code for AOT cache pointer compression
Johan Sjölen
jsjolen at openjdk.org
Fri Feb 6 12:48:44 UTC 2026
On Thu, 5 Feb 2026 17:22:08 GMT, Ioi Lam <iklam at openjdk.org> wrote:
> AOT cache uses pointer compression to store 64-bit pointers in 32 bits. Currently the compression algorithm is simply (base + narrowPtr). However, in [JDK-8376125](https://bugs.openjdk.org/browse/JDK-8376125), we may change it to (base + narrowPtr << 3).
>
> This RFE changed the encoded pointer from an u4 to (thanks to @jdksjolen for the idea):
>
>
> enum class narrowPtr : u4;
>
>
> This allows better tracking of where the encoded pointers are stored. Also, we can distinguish between byte offsets vs encoded pointers -- they currently have the same numerical values but after [JDK-8376125](https://bugs.openjdk.org/browse/JDK-8376125), they will be different.
>
> Also minor clean up in ArchiveBuilder to change some `uintx` to `size_t`, which is used by `pointer_delta()`.
Thanks for looking into my idea! I've got some questions, but most of the patch looks fine to me.
src/hotspot/share/cds/aotCompressedPointers.hpp line 52:
> 50: static narrowPtr cast_to_narrowPtr(T narrowp) {
> 51: return checked_cast<narrowPtr>(narrowp);
> 52: }
This is an escape hatch that let's you encode anything into a `narrowPtr`, maybe it should be private? It doesn't seem to be used outside of the header (did a quick Ctrl+F).
src/hotspot/share/cds/aotCompressedPointers.hpp line 68:
> 66: }
> 67:
> 68: static narrowPtr null_narrowPtr() {
Nit: I think you can just call this `null` and that's fine and a bit prettier, but up to you.
src/hotspot/share/cds/aotCompressedPointers.hpp line 103:
> 101:
> 102: template <typename T>
> 103: static narrowPtr encode_null_or_address_cache(T ptr) { // may be null
For everything else we have `X` and `X_not_null` but for this one we have `X` and `X_or_null`, so here we do the inverse. Is that on purpose?
src/hotspot/share/cds/aotCompressedPointers.hpp line 145:
> 143: return decode_not_null<T>(base_address, narrowp);
> 144: }
> 145: }
We don't wanna do this with the `base_address` being an optional argument at the end instead so we just have one function def?
src/hotspot/share/cds/aotCompressedPointers.hpp line 169:
> 167: inline u4 to_u4(AOTCompressedPointers::narrowPtr narrowp) {
> 168: return cast_from_narrowPtr<u4>(narrowp);
> 169: }
Seems like `cast_to_narrowPtr` could do with a `from_u4` analogue, and the only usage of the cast_to_narrowPtr can actually be replaced with that call. Maybe we don't need those globals, and the `from_` `to_` u4 variants are the only necessary ones?
-------------
PR Review: https://git.openjdk.org/jdk/pull/29590#pullrequestreview-3762777282
PR Review Comment: https://git.openjdk.org/jdk/pull/29590#discussion_r2773863004
PR Review Comment: https://git.openjdk.org/jdk/pull/29590#discussion_r2773912597
PR Review Comment: https://git.openjdk.org/jdk/pull/29590#discussion_r2773907733
PR Review Comment: https://git.openjdk.org/jdk/pull/29590#discussion_r2773935608
PR Review Comment: https://git.openjdk.org/jdk/pull/29590#discussion_r2773942865
More information about the serviceability-dev
mailing list