RFR: 8374308: ImageBufferCache does not work as intended [v2]

David Beaumont duke at openjdk.org
Tue Jan 6 10:37:16 UTC 2026


On Tue, 6 Jan 2026 10:29:14 GMT, David Beaumont <duke at openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java line 394:
>> 
>>> 392:             throw new IndexOutOfBoundsException("size");
>>> 393:         }
>>> 394:         ByteBuffer result = ByteBuffer.allocateDirect((int) ((size + 0xFFF) & ~0xFFF));
>> 
>> Can you remind me why it allocates multiples of 4k?  
>> 
>> Also, would be useful to know if using ByteByte.allocate (to allocate a heap buffer) would be okay here.
>
> I can't, I've never seen this code before. No comments, no tests for why 4k is a good size. Probably just a "page size" heuristic. I'm just removing dead code and moving what's not dead out of the class to be deleted.
> 
> Changing details beyond that should probably be a different PR.

Actually, thinking about this more, it would have the benefit (in the situation where caching happens) of making buckets more likely to be reususeable, so if we're willing to assume that, and since the cache is going away, we could justify dropping the rounding and just allocating the exact size.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29043#discussion_r2664458010


More information about the core-libs-dev mailing list