RFR: 8274400: HotSpot Style Guide should permit use of alignof [v3]

Kim Barrett kbarrett at openjdk.org
Fri Dec 30 02:11:50 UTC 2022


On Wed, 28 Dec 2022 11:02:06 GMT, Julian Waters <jwaters at openjdk.org> wrote:

>> The alignof operator was added by C++11. It returns the alignment for the given type. Various metaprogramming usages exist, in particular when using std::aligned_storage. Use of this operator should be permitted in HotSpot code.
>
> Julian Waters has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
> 
>  - Make section more brief
>  - Merge remote-tracking branch 'upstream/master' into alignof
>  - More Descriptive Version
>  - Merge remote-tracking branch 'upstream/master' into alignof
>  - HotSpot Style Guide should permit use of alignof

> What is the use-case for permitting use of `alignof`? Usually we don't add such permits without some use-case in mind.
> [...] 
> I'm not opposed to permitting the use of `alignof`, but wondering why we might need it.

Responding to myself, I've found a usage category where `alignof` would be appropriate.  We have various
places where we are aligning a pointer to the size of some type, where it would be more appropriate to align to the
alignment of that type.  See, for example, `Message::calc_size()` (logging/logAsyncWriter.hpp), which uses
`sizeof(void*)` where it seems like it should be using `alignof(Message)`.

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

PR: https://git.openjdk.org/jdk/pull/11761


More information about the hotspot-dev mailing list