RFR: 7903587: Revisit inlining of struct layouts into other layouts/descriptors [v2]
Maurizio Cimadamore
mcimadamore at openjdk.org
Tue Dec 12 15:51:59 UTC 2023
On Tue, 12 Dec 2023 15:49:35 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> This PR completes the sequence of changes that I've been working on, by allowing layout and descriptor strings to be generated directly from jextract types. This allows for generated layouts to respect the "structure" found in the corresponding C header. Consider this case:
>>
>>
>> struct Point {
>> int x;
>> int y;
>> };
>>
>> struct Rectangle {
>> struct Point topLeft;
>> struct Point bottomRight;
>> };
>>
>>
>> With the changes in this PR, the generate layout for `Rectangle` becomes:
>>
>>
>> private static final MemoryLayout $LAYOUT = MemoryLayout.structLayout(
>> Point.$LAYOUT().withName("topLeft"),
>> Point.$LAYOUT().withName("bottomRight")
>> ).withName("Rectangle");
>>
>>
>> Note how the layout for `Point` is no longer inlined, but instead is referred to "by name".
>>
>> The patch is quite straightforward, and aims at replacing the functions Declaration/Type.layoutFor/descriptorFor with new functions (now in the builder hierarchy) which generate layout and descriptor strings from the corresponding jextract types.
>>
>> Note: this patch introduces some additional issues when it comes with static initializer circularities. These issues will be dealt with in a separate change (since we have started accumulating some of these since https://git.openjdk.org/jextract/pull/145)
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>
> Add new packed struct test
test/jtreg/generator/TestPackedStructs.java line 48:
> 46: * @run testng/othervm --enable-native-access=ALL-UNNAMED TestPackedStructs
> 47: */
> 48: public class TestPackedStructs {
Since we can no longer access layouts from the declaration API, it's much easier to write a test against the generated code
-------------
PR Review Comment: https://git.openjdk.org/jextract/pull/157#discussion_r1424210924
More information about the jextract-dev
mailing list