RFR: 8285979: G1: G1SegmentedArraySegment::header_size() is incorrect since JDK-8283368 [v2]

Jie Fu jiefu at openjdk.java.net
Mon May 2 10:48:43 UTC 2022


> 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

Jie Fu has updated the pull request incrementally with one additional commit since the last revision:

  Address review comment

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/8494/files
  - new: https://git.openjdk.java.net/jdk/pull/8494/files/785b9312..1441dcbc

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=8494&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=8494&range=00-01

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/8494.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/8494/head:pull/8494

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



More information about the hotspot-gc-dev mailing list