[foreign-memaccess+abi] RFR: 8291826: Rework MemoryLayout Sealed Hierarchy [v4]
Per Minborg
duke at openjdk.org
Fri Aug 19 09:39:03 UTC 2022
> This PR is a significant refactor of the `MemoryLayout` sealed hierarchy and whose purpose is described more in detail in https://bugs.openjdk.org/browse/JDK-8291826. In short, the main purpose is to allow pattern matching.
>
> The objective of the PR is to fix the issues described above while retaining as much API compatibility as possible with the pre-PR API. No changes were needed in any of the existing tests for example.
>
> The old sealed hierarchy prevented pattern matching with totality from being used and implied a number of other problems as illustrated in the picture below:
>
> 
>
> Red nodes cannot be used in pattern matching. Light red nodes are implementations that are visible in the API. White nodes are interfaces.
>
> After this PR has been integrated, an improved sealed hierarchy will exist as depicted here:
>
> 
>
> Gray "Impl" nodes are internal and not exported by the `java.base` module. White nodes are interfaces.
>
> Below, the "Principal Totalities" for the new API are outlined:
>
>
> var v0 = switch (memoryLayout) {
> case MemoryLayout ml -> 0;
> };
> var v1 = switch (memoryLayout) {
> case GroupLayout gl -> 0;
> case PaddingLayout pl -> 0; // leaf
> case SequenceLayout sl -> 0; // leaf
> case ValueLayout vl -> 0;
> };
> var v2 = switch (memoryLayout) {
> case PaddingLayout pl -> 0; // leaf
> case SequenceLayout sl -> 0; // leaf
> case ValueLayout vl -> 0;
> case StructLayout sl -> 0; // leaf
> case UnionLayout ul -> 0; // leaf
> };
> var v3 = switch (memoryLayout) {
> case PaddingLayout pl -> 0; // leaf
> case SequenceLayout sl -> 0; // leaf
> case StructLayout sl -> 0; // leaf
> case UnionLayout ul -> 0; // leaf
> case OfAddress oa -> 0; // leaf
> case OfBoolean ob -> 0; // leaf
> case OfByte ob -> 0; // leaf
> case OfChar oc -> 0; // leaf
> case OfDouble od -> 0; // leaf
> case OfFloat of -> 0; // leaf
> case OfInt oi -> 0; // leaf
> case OfLong ol -> 0; // leaf
> case OfShort os -> 0; // leaf
> };
> var v4 = switch (memoryLayout) {
> case GroupLayout gl -> 0;
> case PaddingLayout pl -> 0; // leaf
> case SequenceLayout sl -> 0; // leaf
> case OfAddress oa -> 0; // leaf
> case OfBoolean ob -> 0; // leaf
> case OfByte ob -> 0; // leaf
> case OfChar oc -> 0; // leaf
> case OfDouble od -> 0; // leaf
> case OfFloat of -> 0; // leaf
> case OfInt oi -> 0; // leaf
> case OfLong ol -> 0; // leaf
> case OfShort os -> 0; // leaf
> };
>
>
>
> Additional improvements can be made later in a separate PR, including removing/improving some of the internal abstract classes.
Per Minborg has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains five commits:
- Merge foreign-memaccess+abi
- Update after comments
- Update src/java.base/share/classes/java/lang/foreign/MemoryLayout.java
Co-authored-by: Paul Sandoz <paul.d.sandoz at googlemail.com>
- Add tests and update return types
- Rework MemoryLayout Sealed Hierarchy
-------------
Changes: https://git.openjdk.org/panama-foreign/pull/710/files
Webrev: https://webrevs.openjdk.org/?repo=panama-foreign&pr=710&range=03
Stats: 2672 lines in 19 files changed: 1759 ins; 730 del; 183 mod
Patch: https://git.openjdk.org/panama-foreign/pull/710.diff
Fetch: git fetch https://git.openjdk.org/panama-foreign pull/710/head:pull/710
PR: https://git.openjdk.org/panama-foreign/pull/710
More information about the panama-dev
mailing list