Merge
This commit is contained in:
commit
923462467e
@ -34,34 +34,41 @@ public enum CABI {
|
|||||||
LinuxAArch64,
|
LinuxAArch64,
|
||||||
MacOsAArch64;
|
MacOsAArch64;
|
||||||
|
|
||||||
private static final CABI current;
|
private static final CABI ABI;
|
||||||
|
private static final String ARCH;
|
||||||
|
private static final String OS;
|
||||||
|
private static final long ADDRESS_SIZE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String arch = privilegedGetProperty("os.arch");
|
ARCH = privilegedGetProperty("os.arch");
|
||||||
String os = privilegedGetProperty("os.name");
|
OS = privilegedGetProperty("os.name");
|
||||||
long addressSize = ADDRESS.bitSize();
|
ADDRESS_SIZE = ADDRESS.bitSize();
|
||||||
// might be running in a 32-bit VM on a 64-bit platform.
|
// might be running in a 32-bit VM on a 64-bit platform.
|
||||||
// addressSize will be correctly 32
|
// addressSize will be correctly 32
|
||||||
if ((arch.equals("amd64") || arch.equals("x86_64")) && addressSize == 64) {
|
if ((ARCH.equals("amd64") || ARCH.equals("x86_64")) && ADDRESS_SIZE == 64) {
|
||||||
if (os.startsWith("Windows")) {
|
if (OS.startsWith("Windows")) {
|
||||||
current = Win64;
|
ABI = Win64;
|
||||||
} else {
|
} else {
|
||||||
current = SysV;
|
ABI = SysV;
|
||||||
}
|
}
|
||||||
} else if (arch.equals("aarch64")) {
|
} else if (ARCH.equals("aarch64")) {
|
||||||
if (os.startsWith("Mac")) {
|
if (OS.startsWith("Mac")) {
|
||||||
current = MacOsAArch64;
|
ABI = MacOsAArch64;
|
||||||
} else {
|
} else {
|
||||||
// The Linux ABI follows the standard AAPCS ABI
|
// The Linux ABI follows the standard AAPCS ABI
|
||||||
current = LinuxAArch64;
|
ABI = LinuxAArch64;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException(
|
// unsupported
|
||||||
"Unsupported os, arch, or address size: " + os + ", " + arch + ", " + addressSize);
|
ABI = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CABI current() {
|
public static CABI current() {
|
||||||
return current;
|
if (ABI == null) {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"Unsupported os, arch, or address size: " + OS + ", " + ARCH + ", " + ADDRESS_SIZE);
|
||||||
|
}
|
||||||
|
return ABI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,6 @@ import java.lang.foreign.MemoryLayout;
|
|||||||
import java.lang.foreign.ValueLayout;
|
import java.lang.foreign.ValueLayout;
|
||||||
|
|
||||||
public class PlatformLayouts {
|
public class PlatformLayouts {
|
||||||
public static <Z extends MemoryLayout> Z pick(Z sysv, Z win64, Z aarch64) {
|
|
||||||
return switch (CABI.current()) {
|
|
||||||
case SysV -> sysv;
|
|
||||||
case Win64 -> win64;
|
|
||||||
case LinuxAArch64, MacOsAArch64 -> aarch64;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class defines layout constants modelling standard primitive types supported by the x64 SystemV ABI.
|
* This class defines layout constants modelling standard primitive types supported by the x64 SystemV ABI.
|
||||||
|
60
test/jdk/java/foreign/TestUnsupportedLinker.java
Normal file
60
test/jdk/java/foreign/TestUnsupportedLinker.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @enablePreview
|
||||||
|
*
|
||||||
|
* @run testng/othervm -Dos.arch=unknown -Dos.name=unknown --enable-native-access=ALL-UNNAMED TestUnsupportedLinker
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.foreign.Linker;
|
||||||
|
import java.lang.foreign.MemoryAddress;
|
||||||
|
import java.lang.foreign.MemorySession;
|
||||||
|
import java.lang.foreign.VaList;
|
||||||
|
import java.lang.foreign.ValueLayout;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class TestUnsupportedLinker {
|
||||||
|
|
||||||
|
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||||
|
public void testLinker() {
|
||||||
|
Linker.nativeLinker();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||||
|
public void testEmptyVaList() {
|
||||||
|
VaList.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||||
|
public void testNonEmptyVaList() {
|
||||||
|
VaList.make(builder -> builder.addVarg(ValueLayout.JAVA_INT, 42), MemorySession.openImplicit());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||||
|
public void testUnsafeVaList() {
|
||||||
|
VaList.ofAddress(MemoryAddress.NULL, MemorySession.openImplicit());
|
||||||
|
}
|
||||||
|
}
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @test
|
|
||||||
* @enablePreview
|
|
||||||
* @requires !(((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64")
|
|
||||||
* @run testng/othervm --enable-native-access=ALL-UNNAMED TestUnsupportedPlatform
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java.lang.foreign.Linker;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertNull;
|
|
||||||
|
|
||||||
// tests run on 32-bit platforms, which are currently not supported
|
|
||||||
public class TestUnsupportedPlatform {
|
|
||||||
|
|
||||||
@Test(expectedExceptions = ExceptionInInitializerError.class)
|
|
||||||
public void testNoInitialization() {
|
|
||||||
Linker.nativeLinker(); // trigger initialization
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user