Integrated: 8285979: G1: G1SegmentedArraySegment::header_size() is incorrect since JDK-8283368

Jie Fu jiefu at openjdk.java.net
Mon May 2 22:43:37 UTC 2022


On Sun, 1 May 2022 23:56:55 GMT, Jie Fu <jiefu at openjdk.org> wrote:

> Hi all,
> 
> `G1SegmentedArraySegment::header_size()` is incorrect if `DEFAULT_CACHE_LINE_SIZE <= 32`.
> This bug can be easily reproduced by running `gc/g1` with VM configured and built with `--with-jvm-features=-compiler2`.
> 
> The reason is that there are paddings in the layout of `G1SegmentedArraySegment`.
> 
>   const uint _slot_size;                   // offset 0-byte
>   const uint _num_slots;                   // offset 4-byte
>   const MEMFLAGS _mem_flag;                // offset 8-byte
>     // --- padding 4 bytes
>   G1SegmentedArraySegment* volatile _next; // offset 16-byte
>   uint volatile _next_allocate;            // offset 24
>     // --- padding 4 bytes
>   char* _bottom;                           // offset 32-byte
> 
> 
> So if we calculate `header_size()` like this, it will return 32 bytes when `DEFAULT_CACHE_LINE_SIZE=32`, which should be at least 40 bytes actually.
> 
> static size_t header_size() { return align_up(offset_of(G1SegmentedArraySegment, _bottom) + sizeof(_bottom), DEFAULT_CACHE_LINE_SIZE); }
> 
> 
> Two changes are made in this patch:
> - Fix the implementation of `header_size()`.
> - Fix the layout of `G1SegmentedArraySegment` to eliminate paddings.
> 
> Testing:
> - tier1~3 on Linux/x64, no regression
> - gc/g1 with `--with-jvm-features=-compiler2` on Linux/x64, all passed
> 
> Thanks.
> Best regards,
> Jie

This pull request has now been integrated.

Changeset: fbcd8749
Author:    Jie Fu <jiefu at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/fbcd874907ebed91024354fef1d5bd4c25a2f17e
Stats:     6 lines in 2 files changed: 2 ins; 2 del; 2 mod

8285979: G1: G1SegmentedArraySegment::header_size() is incorrect since JDK-8283368

Reviewed-by: tschatzl, iwalulya

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

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



More information about the hotspot-gc-dev mailing list