RFR: 8334229: Optimize InterpreterOopMap layout [v2]
Coleen Phillimore
coleenp at openjdk.org
Tue Jul 2 14:28:21 UTC 2024
On Mon, 1 Jul 2024 21:53:52 GMT, Xiaolong Peng <xpeng at openjdk.org> wrote:
>> Hi all,
>> This PR is re-arrange the fields in InterpreterOopMap to optimize the layout of the class; by moving ```unsigned short _bci ``` to the place after ```int _expression_stack_size```, and ```int _num_oops``` to the place before ```intptr_t _bit_mask[4];```, most of the holes are removed.
>>
>> Layout before the fix:
>>
>> (gdb) ptype /xo InterpreterOopMap
>> /* offset | size */ type = class InterpreterOopMap : private ResourceObj {
>> private:
>> /* 0x0000 | 0x0008 */ class Method *_method;
>> /* 0x0008 | 0x0002 */ unsigned short _bci;
>> /* XXX 2-byte hole */
>> /* 0x000c | 0x0004 */ int _mask_size;
>> /* 0x0010 | 0x0004 */ int _expression_stack_size;
>> protected:
>> /* XXX 4-byte hole */
>> /* 0x0018 | 0x0020 */ intptr_t _bit_mask[4];
>> /* 0x0038 | 0x0004 */ int _num_oops;
>> /* XXX 4-byte padding */
>>
>> /* total size (bytes): 64 */
>> }
>>
>>
>> After fix:
>>
>> (gdb) ptype /xo InterpreterOopMap
>> /* offset | size */ type = class InterpreterOopMap : private ResourceObj {
>> private:
>> /* 0x0000 | 0x0008 */ class Method *_method;
>> /* 0x0008 | 0x0004 */ int _mask_size;
>> /* 0x000c | 0x0004 */ int _expression_stack_size;
>> /* 0x0010 | 0x0002 */ unsigned short _bci;
>> protected:
>> /* XXX 2-byte hole */
>> /* 0x0014 | 0x0004 */ int _num_oops;
>> /* 0x0018 | 0x0020 */ intptr_t _bit_mask[4];
>>
>> /* total size (bytes): 56 */
>> }
>>
>>
>> (Also moved ```bool _resource_allocate_bit_mask``` to before ```intptr_t _bit_mask[4];```, so it will use 1 byte of the 2-byte hole, resulting in 1 byte hole in fastdebug build.)
>>
>> Layout in fastdebug build:
>>
>> (gdb) ptype /xo InterpreterOopMap
>> /* offset | size */ type = class InterpreterOopMap : private ResourceObj {
>> private:
>> /* 0x0000 | 0x0008 */ class Method *_method;
>> /* 0x0008 | 0x0004 */ int _mask_size;
>> /* 0x000c | 0x0004 */ int _expression_stack_size;
>> /* 0x0010 | 0x0002 */ unsigned short _bci;
>> protected:
>> /* 0x0012 | 0x0001 */ bool _resource_allocate_bit_mask;
>> /* XXX 1-byte hole */
>> /* 0x0014 |...
>
> Xiaolong Peng has updated the pull request incrementally with one additional commit since the last revision:
>
> Move _resource_allocate_bit_mask to the place before _num_oops for better layout in debug build
This seems fine. Sometimes fields are grouped together where they make sense together at the expense of some alignment gaps, but this isn't the case here.
-------------
Marked as reviewed by coleenp (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/19979#pullrequestreview-2154024650
More information about the hotspot-runtime-dev
mailing list