Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit 8c9d5ad

Browse files
committed
8290455: jck test api/java_lang/foreign/VaList/Empty.html fails on some platforms
Reviewed-by: jvernee, mbaesken
1 parent c29242e commit 8c9d5ad

File tree

3 files changed

+82
-22
lines changed

3 files changed

+82
-22
lines changed

src/java.base/share/classes/jdk/internal/foreign/CABI.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,41 @@ public enum CABI {
3434
LinuxAArch64,
3535
MacOsAArch64;
3636

37-
private static final CABI current;
37+
private static final CABI ABI;
38+
private static final String ARCH;
39+
private static final String OS;
40+
private static final long ADDRESS_SIZE;
3841

3942
static {
40-
String arch = privilegedGetProperty("os.arch");
41-
String os = privilegedGetProperty("os.name");
42-
long addressSize = ADDRESS.bitSize();
43+
ARCH = privilegedGetProperty("os.arch");
44+
OS = privilegedGetProperty("os.name");
45+
ADDRESS_SIZE = ADDRESS.bitSize();
4346
// might be running in a 32-bit VM on a 64-bit platform.
4447
// addressSize will be correctly 32
45-
if ((arch.equals("amd64") || arch.equals("x86_64")) && addressSize == 64) {
46-
if (os.startsWith("Windows")) {
47-
current = Win64;
48+
if ((ARCH.equals("amd64") || ARCH.equals("x86_64")) && ADDRESS_SIZE == 64) {
49+
if (OS.startsWith("Windows")) {
50+
ABI = Win64;
4851
} else {
49-
current = SysV;
52+
ABI = SysV;
5053
}
51-
} else if (arch.equals("aarch64")) {
52-
if (os.startsWith("Mac")) {
53-
current = MacOsAArch64;
54+
} else if (ARCH.equals("aarch64")) {
55+
if (OS.startsWith("Mac")) {
56+
ABI = MacOsAArch64;
5457
} else {
5558
// The Linux ABI follows the standard AAPCS ABI
56-
current = LinuxAArch64;
59+
ABI = LinuxAArch64;
5760
}
5861
} else {
59-
throw new UnsupportedOperationException(
60-
"Unsupported os, arch, or address size: " + os + ", " + arch + ", " + addressSize);
62+
// unsupported
63+
ABI = null;
6164
}
6265
}
6366

6467
public static CABI current() {
65-
return current;
68+
if (ABI == null) {
69+
throw new UnsupportedOperationException(
70+
"Unsupported os, arch, or address size: " + OS + ", " + ARCH + ", " + ADDRESS_SIZE);
71+
}
72+
return ABI;
6673
}
6774
}

src/java.base/share/classes/jdk/internal/foreign/PlatformLayouts.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@
2929
import java.lang.foreign.ValueLayout;
3030

3131
public class PlatformLayouts {
32-
public static <Z extends MemoryLayout> Z pick(Z sysv, Z win64, Z aarch64) {
33-
return switch (CABI.current()) {
34-
case SysV -> sysv;
35-
case Win64 -> win64;
36-
case LinuxAArch64, MacOsAArch64 -> aarch64;
37-
};
38-
}
3932

4033
/**
4134
* This class defines layout constants modelling standard primitive types supported by the x64 SystemV ABI.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @enablePreview
27+
*
28+
* @run testng/othervm -Dos.arch=unknown -Dos.name=unknown --enable-native-access=ALL-UNNAMED TestUnsupportedLinker
29+
*/
30+
31+
import java.lang.foreign.Linker;
32+
import java.lang.foreign.MemoryAddress;
33+
import java.lang.foreign.MemorySession;
34+
import java.lang.foreign.VaList;
35+
import java.lang.foreign.ValueLayout;
36+
37+
import org.testng.annotations.Test;
38+
39+
public class TestUnsupportedLinker {
40+
41+
@Test(expectedExceptions = UnsupportedOperationException.class)
42+
public void testLinker() {
43+
Linker.nativeLinker();
44+
}
45+
46+
@Test(expectedExceptions = UnsupportedOperationException.class)
47+
public void testEmptyVaList() {
48+
VaList.empty();
49+
}
50+
51+
@Test(expectedExceptions = UnsupportedOperationException.class)
52+
public void testNonEmptyVaList() {
53+
VaList.make(builder -> builder.addVarg(ValueLayout.JAVA_INT, 42), MemorySession.openImplicit());
54+
}
55+
56+
@Test(expectedExceptions = UnsupportedOperationException.class)
57+
public void testUnsafeVaList() {
58+
VaList.ofAddress(MemoryAddress.NULL, MemorySession.openImplicit());
59+
}
60+
}

0 commit comments

Comments
 (0)