8305201: Improve error message for GroupLayouts that are too large on SysV
Reviewed-by: mcimadamore
This commit is contained in:
parent
67dd841432
commit
7d07d19523
@ -190,7 +190,13 @@ class TypeClass {
|
|||||||
|
|
||||||
private static List<ArgumentClassImpl>[] groupByEightBytes(GroupLayout group) {
|
private static List<ArgumentClassImpl>[] groupByEightBytes(GroupLayout group) {
|
||||||
long offset = 0L;
|
long offset = 0L;
|
||||||
int nEightbytes = (int) Utils.alignUp(group.byteSize(), 8) / 8;
|
int nEightbytes;
|
||||||
|
try {
|
||||||
|
// alignUp can overflow the value, but it's okay since toIntExact still catches it
|
||||||
|
nEightbytes = Math.toIntExact(Utils.alignUp(group.byteSize(), 8) / 8);
|
||||||
|
} catch (ArithmeticException e) {
|
||||||
|
throw new IllegalArgumentException("GroupLayout is too large: " + group, e);
|
||||||
|
}
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
List<ArgumentClassImpl>[] groups = new List[nEightbytes];
|
List<ArgumentClassImpl>[] groups = new List[nEightbytes];
|
||||||
for (MemoryLayout l : group.memberLayouts()) {
|
for (MemoryLayout l : group.memberLayouts()) {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @enablePreview
|
* @enablePreview
|
||||||
|
* @modules java.base/jdk.internal.foreign
|
||||||
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" | os.arch == "riscv64"
|
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" | os.arch == "riscv64"
|
||||||
* @run testng/othervm --enable-native-access=ALL-UNNAMED TestIllegalLink
|
* @run testng/othervm --enable-native-access=ALL-UNNAMED TestIllegalLink
|
||||||
*/
|
*/
|
||||||
@ -39,7 +40,11 @@ import java.lang.invoke.MethodHandle;
|
|||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import jdk.internal.foreign.CABI;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@ -48,6 +53,8 @@ import static org.testng.Assert.fail;
|
|||||||
|
|
||||||
public class TestIllegalLink extends NativeTestHelper {
|
public class TestIllegalLink extends NativeTestHelper {
|
||||||
|
|
||||||
|
private static final boolean IS_SYSV = CABI.current() == CABI.SYS_V;
|
||||||
|
|
||||||
private static final MemorySegment DUMMY_TARGET = MemorySegment.ofAddress(1);
|
private static final MemorySegment DUMMY_TARGET = MemorySegment.ofAddress(1);
|
||||||
private static final MethodHandle DUMMY_TARGET_MH = MethodHandles.empty(MethodType.methodType(void.class));
|
private static final MethodHandle DUMMY_TARGET_MH = MethodHandles.empty(MethodType.methodType(void.class));
|
||||||
private static final Linker ABI = Linker.nativeLinker();
|
private static final Linker ABI = Linker.nativeLinker();
|
||||||
@ -101,7 +108,7 @@ public class TestIllegalLink extends NativeTestHelper {
|
|||||||
|
|
||||||
@DataProvider
|
@DataProvider
|
||||||
public static Object[][] types() {
|
public static Object[][] types() {
|
||||||
return new Object[][]{
|
List<Object[]> cases = new ArrayList<>(Arrays.asList(new Object[][]{
|
||||||
{
|
{
|
||||||
FunctionDescriptor.of(MemoryLayout.paddingLayout(64)),
|
FunctionDescriptor.of(MemoryLayout.paddingLayout(64)),
|
||||||
"Unsupported layout: x64"
|
"Unsupported layout: x64"
|
||||||
@ -185,7 +192,18 @@ public class TestIllegalLink extends NativeTestHelper {
|
|||||||
MemoryLayout.paddingLayout(32))), // too much trailing padding
|
MemoryLayout.paddingLayout(32))), // too much trailing padding
|
||||||
"has unexpected size"
|
"has unexpected size"
|
||||||
},
|
},
|
||||||
};
|
}));
|
||||||
|
|
||||||
|
if (IS_SYSV) {
|
||||||
|
cases.add(new Object[] {
|
||||||
|
FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
|
||||||
|
MemoryLayout.sequenceLayout(
|
||||||
|
C_INT
|
||||||
|
))),
|
||||||
|
"GroupLayout is too large"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return cases.toArray(Object[][]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ByteOrder nonNativeOrder() {
|
private static ByteOrder nonNativeOrder() {
|
||||||
|
Loading…
Reference in New Issue
Block a user