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

Kim Barrett kbarrett at openjdk.org
Tue Jan 24 23:26:08 UTC 2023


On Tue, 24 Jan 2023 07:42:20 GMT, Xin Liu <xliu at openjdk.org> wrote:

> Currently, sizeof(Message) is 64. Message is just a header. The real payload is Message + a '\0'-terminated c-str and pads.
> 
> You are right about the purpose of 'calc_size()', but we don't load 'Message" as an object. We only load its fields individually. eg. *(message->_output). That's why I think it's good enough to align to the pointer size.

In order to access through an object, the object must be correctly aligned for its type, else UB.
 
> Let's assume the log string is empty ''. calc_size(0) returns 72 now, so the next Message starts at buffer+72. *_output is still aligned load. If we alignof(Message), it starts with buffer+128. that takes 63 bytes to pad.

Agreed that calc_size(0) is 72 currently. But disagree about the value if
using alignof(Message) instead of sizeof(void*) in that calculation. Using
alignof(Message) will also return 72. Maybe you are misremembering what
alignof returns?

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

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


More information about the hotspot-dev mailing list