RFR: 8253779: Amalloc may be wasting space by overaligning

Kim Barrett kbarrett at openjdk.java.net
Thu Jul 8 22:52:56 UTC 2021


On Thu, 8 Jul 2021 22:16:23 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Thanks to @kimbarrett for noticing this. The alignment was changed to 64 bits for 32 bit platforms, but overalign for 64 bits platforms.  I changed this to BytesPerLong to cover both, since the long case is why it was changed on 32 bits in the first place in JDK-4526490.
>> I also removed Amalloc_D since I don't know what D stands for and it's the same as Amalloc_4.  That's not a great name either. I'm open to suggestions!
>> Tested with tier1-3.
>
> src/hotspot/share/memory/arena.hpp line 159:
> 
>> 157:     assert((x & (sizeof(char*)-1)) == 0, "misaligned size");
>> 158:     debug_only(if (UseMallocOnly) return malloc(x);)
>> 159:     if (!check_for_overflow(x, "Arena::Amalloc_4", alloc_failmode))
> 
> [pre-existing] Missing brackets for the multiline `if` is contrary to the style guide.  Similarly in Amalloc.

[pre-existing: I can't comment directly on line 161, so adding here.]
`if (_hwm + x > _max)` has a risk of overflow if x is excessively large. Better is `if (_max - _hwm < x)`.  Similarly in Amalloc.

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

PR: https://git.openjdk.java.net/jdk/pull/4732


More information about the hotspot-dev mailing list