RFR: 8274400: HotSpot Style Guide should permit use of alignof

Kim Barrett kbarrett at openjdk.org
Thu Dec 22 20:06:50 UTC 2022


On Thu, 22 Dec 2022 04:39:47 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.

Changes requested by kbarrett (Reviewer).

What is the use-case for permitting use of `alignof`?  Usually we don't add
such permits without some use-case in mind.

An obvious use-case was for computing the alignment of a type for use in
ATTRIBUTE_ALIGNED (which currently has compiler-specific implementations that
only support alignment values, though see JDK-8250269). But since we can now
use `alignas` directly (JDK-8297912), that's no longer important.

The use-case mentioned in the RFE (JDK-8274400), using it with
std::aligned_storage, is also not important (or is even counter-productive) -
see JDK-8298399.

I'm not opposed to permitting the use of `alignof`, but wondering why we
might need it.

doc/hotspot-style.md line 1060:

> 1058: 
> 1059: * `alignof`
> 1060: ([n2341](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf))

Should say that `alignof` should be used instead of `std::alignment_of`.

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

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


More information about the hotspot-dev mailing list