Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8340205: Native linker allows MemoryLayout consisting of only PaddingLayout #21041

Closed
wants to merge 37 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1ac1998
Prevent embeded only padding layout in linker
minborg Sep 17, 2024
b9833b4
Update copyright year
minborg Sep 17, 2024
d11b700
Document a sequence layout cannot contain a padding layout
minborg Sep 20, 2024
59d0569
Improve excception message
minborg Sep 20, 2024
c1d3b65
Merge branch 'master' into linker-padding-layout-only
minborg Sep 20, 2024
5f0c509
Remove redundant doc section
minborg Sep 23, 2024
d0575fd
Check exception message
minborg Sep 23, 2024
5cb406d
Merge branch 'master' into linker-padding-layout-only
minborg Sep 23, 2024
78d38ef
Add specific message for group layouts with only padding layouts
minborg Sep 23, 2024
bba0b78
Add to specification and refine detection of PL GLs
minborg Sep 23, 2024
b755c61
Reword doce
minborg Sep 23, 2024
8381d57
Merge branch 'master' into linker-padding-layout-only
minborg Oct 14, 2024
b5e795f
Update Linker docs
minborg Oct 14, 2024
0c13e8a
Merge branch 'master' into linker-padding-layout-only
minborg Oct 29, 2024
8e4ee28
Add rule checkings in AbstractLinker and add tests
minborg Oct 29, 2024
9344daa
Merge branch 'master' into linker-padding-layout-only
minborg Nov 4, 2024
0f4e93f
Rephrase liker arg requirements
minborg Nov 4, 2024
d5a667c
Update src/java.base/share/classes/java/lang/foreign/Linker.java
minborg Nov 5, 2024
52a60d0
Update src/java.base/share/classes/java/lang/foreign/Linker.java
minborg Nov 5, 2024
dfcec4e
Update src/java.base/share/classes/jdk/internal/foreign/abi/AbstractL…
minborg Nov 5, 2024
ab106f1
Update src/java.base/share/classes/jdk/internal/foreign/abi/AbstractL…
minborg Nov 5, 2024
dc3330e
Update src/java.base/share/classes/jdk/internal/foreign/abi/AbstractL…
minborg Nov 5, 2024
1b00b2a
Update src/java.base/share/classes/jdk/internal/foreign/abi/AbstractL…
minborg Nov 5, 2024
e81b34f
Update test/jdk/java/foreign/TestLinker.java
minborg Nov 5, 2024
3f53760
Add checks of exception messages
minborg Nov 5, 2024
8f89d4f
Improve language
minborg Nov 5, 2024
b92ff23
Rephrase doc
minborg Nov 5, 2024
0c13482
Remove redundant check
minborg Nov 5, 2024
7bd1e3d
Merge branch 'master' into linker-padding-layout-only
minborg Nov 6, 2024
6a97fe5
Simplify exception testing
minborg Nov 6, 2024
3274a46
Merge branch 'master' into linker-padding-layout-only
minborg Nov 13, 2024
786b173
Update after comments
minborg Nov 13, 2024
97f8da6
Merge branch 'master' into linker-padding-layout-only
minborg Nov 13, 2024
69e6593
Fix failing test
minborg Nov 13, 2024
59ecf49
Merge branch 'master' into linker-padding-layout-only
minborg Nov 20, 2024
28b3ad6
Update after comments
minborg Nov 20, 2024
0102e56
Fix checking of padding layouts
minborg Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions src/java.base/share/classes/java/lang/foreign/Linker.java
Original file line number Diff line number Diff line change
@@ -250,15 +250,15 @@
* <ol>
* <li>{@code L.byteAlignment()} is equal to the sequence layout's <em>natural alignment</em>
* , and</li>
* <li>{@code S.elementLayout()} is a well-defined layout.</li>
* <li>{@code S.elementLayout()} is a well-formed layout.</li>
* </ol>
* </li>
* <li>{@code L} is a group layout {@code G} and all the following conditions hold:
* <ol>
* <li>{@code G.byteAlignment()} is equal to the group layout's <em>natural alignment</em></li>
* <li>{@code G.byteSize()} is a multiple of {@code G.byteAlignment()}</li>
* <li>Each member layout in {@code G.memberLayouts()} is either a padding layout or a
* well-defined layout</li>
* well-formed layout</li>
* <li>Each non-padding member layout {@code E} in {@code G.memberLayouts()} follows an
* optional padding member layout, whose size is the minimum size required to
* align {@code E}</li>
@@ -268,27 +268,13 @@
* </li>
* </ul>
* <p>
* Well-formed layouts in function descriptions consumed by a native linker constitute
* a necessary, but not sufficient, requirement for acceptance. For example, some
* native linkers may reject <em>packed</em> struct layouts. A packed struct is a struct
* in which there is at least one member layout {@code L} that has an alignment constraint
* less strict than its natural alignment. This allows padding between member layouts and
* padding at the end to be avoided in struct layouts.
* For example:
* {@snippet lang = java:
* // No padding between the 2 element layouts:
* MemoryLayout noFieldPadding = MemoryLayout.structLayout(
* ValueLayout.JAVA_INT,
* ValueLayout.JAVA_DOUBLE.withByteAlignment(4));
*
* // No padding at the end of the struct:
* MemoryLayout noTrailingPadding = MemoryLayout.structLayout(
* ValueLayout.JAVA_DOUBLE.withByteAlignment(4),
* ValueLayout.JAVA_INT);
* }
* <p>
* A native linker only supports function descriptors whose argument/return layouts are
* layouts supported by that linker and are not sequence layouts.
* A function descriptor is well-formed if its argument and return layouts are
* well-formed and are not sequence layouts. A native linker is guaranteed to reject
* function descriptors that are not well-formed. However, a native linker can still
* reject well-formed function descriptors, according to platform-specific rules.
* For example, some native linkers may reject <em>packed</em> struct layouts -- struct
* layouts whose member layouts feature relaxed alignment constraints, to avoid
* the insertion of additional padding.
*
* <h3 id="function-pointers">Function pointers</h3>
*
Original file line number Diff line number Diff line change
@@ -199,7 +199,6 @@ private void checkLayoutRecursive(MemoryLayout layout) {
if (!(member instanceof PaddingLayout pl)) {
lastUnpaddedOffset = offset;
if (preceedingPadding != null) {
assertIsAlignedBy(sl, preceedingPadding, member);
preceedingPadding = null;
}
} else {
@@ -253,21 +252,10 @@ private static void checkGroup(GroupLayout gl, long maxUnpaddedOffset) {
}
}

private static void assertIsAlignedBy(StructLayout gl, PaddingLayout padding, MemoryLayout element) {
if (padding.byteSize() > element.byteAlignment()) {
throw new IllegalArgumentException("The padding layout " + padding +
" is not of minimum size to align " + element +
"(with byte alignment " + element.byteAlignment() + ")" + inMessage(gl));
}
}

private static String inMessage(GroupLayout gl) {
return gl != null
? " in " + gl
: "";
return " in " + gl;
}


// checks both that there is no excess padding between 'memberLayout' and
// the previous layout
private static void checkMemberOffset(StructLayout parent, MemoryLayout memberLayout,