Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8256862: Several java/foreign tests fail on x86_32 platforms
Reviewed-by: sundar
  • Loading branch information
JornVernee committed Nov 26, 2020
1 parent 7946c94 commit 734d3c3b8a14df1e2fb352152489f50fedcac127
@@ -95,6 +95,8 @@
* {@link #asVarArg(MemoryLayout)} is used to create the memory layouts for each parameter corresponding to a variadic
* argument in a specialized function descriptor.
*
* <p>On unsupported platforms this class will fail to initialize with an {@link ExceptionInInitializerError}.
*
* <p> Unless otherwise specified, passing a {@code null} argument, or an array argument containing one or more {@code null}
* elements to a method in this class causes a {@link NullPointerException NullPointerException} to be thrown. </p>
*
@@ -25,6 +25,10 @@
*/
package jdk.internal.foreign;

import jdk.internal.foreign.abi.SharedUtils;

import static jdk.incubator.foreign.MemoryLayouts.ADDRESS;

public enum CABI {
SysV,
Win64,
@@ -35,7 +39,10 @@ public enum CABI {
static {
String arch = System.getProperty("os.arch");
String os = System.getProperty("os.name");
if (arch.equals("amd64") || arch.equals("x86_64")) {
long addressSize = ADDRESS.bitSize();
// might be running in a 32-bit VM on a 64-bit platform.
// addressSize will be correctly 32
if ((arch.equals("amd64") || arch.equals("x86_64")) && addressSize == 64) {
if (os.startsWith("Windows")) {
current = Win64;
} else {
@@ -44,7 +51,8 @@ public enum CABI {
} else if (arch.equals("aarch64")) {
current = AArch64;
} else {
throw new ExceptionInInitializerError("Unsupported os or arch: " + os + ", " + arch);
throw new ExceptionInInitializerError(
"Unsupported os, arch, or address size: " + os + ", " + arch + ", " + addressSize);
}
}

@@ -141,7 +141,7 @@ private SysV() {
/**
* The {@code T*} native type.
*/
public static final ValueLayout C_POINTER = ofPointer(LITTLE_ENDIAN, ADDRESS.bitSize());
public static final ValueLayout C_POINTER = ofPointer(LITTLE_ENDIAN, 64);

/**
* The {@code va_list} native type, as it is passed to a function.
@@ -201,7 +201,7 @@ private Win64() {
/**
* The {@code T*} native type.
*/
public static final ValueLayout C_POINTER = ofPointer(LITTLE_ENDIAN, ADDRESS.bitSize());
public static final ValueLayout C_POINTER = ofPointer(LITTLE_ENDIAN, 64);

/**
* The {@code va_list} native type, as it is passed to a function.
@@ -266,7 +266,7 @@ private AArch64() {
/**
* The {@code T*} native type.
*/
public static final ValueLayout C_POINTER = ofPointer(LITTLE_ENDIAN, ADDRESS.bitSize());
public static final ValueLayout C_POINTER = ofPointer(LITTLE_ENDIAN, 64);

/**
* The {@code va_list} native type, as it is passed to a function.
@@ -23,6 +23,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @run testng/othervm -Dforeign.restricted=permit StdLibTest
*/

@@ -23,6 +23,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @modules jdk.incubator.foreign/jdk.internal.foreign
* @run testng/othervm TestCircularInit1
*/
@@ -23,6 +23,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @modules jdk.incubator.foreign/jdk.internal.foreign
* @run testng/othervm TestCircularInit2
*/
@@ -23,7 +23,7 @@

/*
* @test
*
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @run testng TestCondy
*/

@@ -24,6 +24,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @modules jdk.incubator.foreign/jdk.internal.foreign
* @build NativeTestHelper CallGeneratorHelper TestDowncall
*
@@ -24,6 +24,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @run testng TestFunctionDescriptor
*/

@@ -24,7 +24,7 @@

/*
* @test
*
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @run testng/othervm -Dforeign.restricted=permit TestIllegalLink
*/

@@ -23,6 +23,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @modules jdk.incubator.foreign/jdk.internal.foreign
* @run testng/othervm -Dforeign.restricted=permit TestLibraryLookup
*/
@@ -41,6 +42,11 @@

import static org.testng.Assert.*;

// FYI this test is run on 64-bit platforms only for now,
// since the windows 32-bit linker fails and there
// is some fallback behaviour to use the 64-bit linker,
// where cygwin gets in the way and we accidentally pick up its
// link.exe
public class TestLibraryLookup {

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Library not found.*")
@@ -24,6 +24,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @modules jdk.incubator.foreign/jdk.internal.foreign
* @run testng/othervm -Dforeign.restricted=permit TestNative
*/
@@ -59,6 +59,7 @@
public class TestNativeScope {

final static int ELEMS = 128;
final static Class<?> ADDRESS_CARRIER = MemoryLayouts.ADDRESS.bitSize() == 64 ? long.class : int.class;

@Test(dataProvider = "nativeScopes")
public <Z> void testAllocation(Z value, ScopeFactory scopeFactory, ValueLayout layout, AllocationFunction<Z> allocationFunction, Function<MemoryLayout, VarHandle> handleFactory) {
@@ -221,7 +222,7 @@ static Object[][] nativeScopes() {
(Function<MemoryLayout, VarHandle>)l -> l.varHandle(double.class) },
{ MemoryAddress.ofLong(42), (ScopeFactory) NativeScope::boundedScope, MemoryLayouts.ADDRESS.withOrder(ByteOrder.BIG_ENDIAN),
(AllocationFunction<MemoryAddress>) NativeScope::allocate,
(Function<MemoryLayout, VarHandle>)l -> MemoryHandles.asAddressVarHandle(l.varHandle(long.class)) },
(Function<MemoryLayout, VarHandle>)l -> MemoryHandles.asAddressVarHandle(l.varHandle(ADDRESS_CARRIER)) },

{ (byte)42, (ScopeFactory) NativeScope::boundedScope, MemoryLayouts.BITS_8_LE,
(AllocationFunction<Byte>) NativeScope::allocate,
@@ -247,7 +248,7 @@ static Object[][] nativeScopes() {
(Function<MemoryLayout, VarHandle>)l -> l.varHandle(double.class) },
{ MemoryAddress.ofLong(42), (ScopeFactory) NativeScope::boundedScope, MemoryLayouts.ADDRESS.withOrder(ByteOrder.LITTLE_ENDIAN),
(AllocationFunction<MemoryAddress>) NativeScope::allocate,
(Function<MemoryLayout, VarHandle>)l -> MemoryHandles.asAddressVarHandle(l.varHandle(long.class)) },
(Function<MemoryLayout, VarHandle>)l -> MemoryHandles.asAddressVarHandle(l.varHandle(ADDRESS_CARRIER)) },

{ (byte)42, (ScopeFactory)size -> NativeScope.unboundedScope(), MemoryLayouts.BITS_8_BE,
(AllocationFunction<Byte>) NativeScope::allocate,
@@ -273,7 +274,7 @@ static Object[][] nativeScopes() {
(Function<MemoryLayout, VarHandle>)l -> l.varHandle(double.class) },
{ MemoryAddress.ofLong(42), (ScopeFactory)size -> NativeScope.unboundedScope(), MemoryLayouts.ADDRESS.withOrder(ByteOrder.BIG_ENDIAN),
(AllocationFunction<MemoryAddress>) NativeScope::allocate,
(Function<MemoryLayout, VarHandle>)l -> MemoryHandles.asAddressVarHandle(l.varHandle(long.class)) },
(Function<MemoryLayout, VarHandle>)l -> MemoryHandles.asAddressVarHandle(l.varHandle(ADDRESS_CARRIER)) },

{ (byte)42, (ScopeFactory)size -> NativeScope.unboundedScope(), MemoryLayouts.BITS_8_LE,
(AllocationFunction<Byte>) NativeScope::allocate,
@@ -299,7 +300,7 @@ static Object[][] nativeScopes() {
(Function<MemoryLayout, VarHandle>)l -> l.varHandle(double.class) },
{ MemoryAddress.ofLong(42), (ScopeFactory)size -> NativeScope.unboundedScope(), MemoryLayouts.ADDRESS.withOrder(ByteOrder.LITTLE_ENDIAN),
(AllocationFunction<MemoryAddress>) NativeScope::allocate,
(Function<MemoryLayout, VarHandle>)l -> MemoryHandles.asAddressVarHandle(l.varHandle(long.class)) },
(Function<MemoryLayout, VarHandle>)l -> MemoryHandles.asAddressVarHandle(l.varHandle(ADDRESS_CARRIER)) },
};
}

@@ -23,6 +23,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @modules java.base/jdk.internal.ref
* jdk.incubator.foreign
* @run testng/othervm -Dforeign.restricted=permit TestNulls
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2020, 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
* @requires !(((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64")
* @modules jdk.incubator.foreign/jdk.internal.foreign
* @run testng/othervm -Dforeign.restricted=permit TestUnsupportedPlatform
*/

import jdk.incubator.foreign.CLinker;
import jdk.incubator.foreign.MemoryLayout;
import jdk.incubator.foreign.NativeScope;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import static jdk.incubator.foreign.MemoryAddress.NULL;
import static jdk.incubator.foreign.MemoryLayouts.JAVA_BYTE;
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() {
CLinker.getInstance(); // trigger initialization
}

}
@@ -24,6 +24,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @modules jdk.incubator.foreign/jdk.internal.foreign
* @build NativeTestHelper CallGeneratorHelper TestUpcall
*
@@ -24,6 +24,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @modules jdk.incubator.foreign/jdk.internal.foreign
* @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity
*
@@ -24,6 +24,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @run testng/othervm -Dforeign.restricted=permit TestUpcallStubs
*/

@@ -24,6 +24,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @run testng/othervm -Dforeign.restricted=permit TestVarArgs
*/

@@ -23,6 +23,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @library /test/lib
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
@@ -24,6 +24,7 @@

/*
* @test
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
* @modules jdk.incubator.foreign/jdk.internal.foreign
* jdk.incubator.foreign/jdk.internal.foreign.abi
* jdk.incubator.foreign/jdk.internal.foreign.abi.aarch64

0 comments on commit 734d3c3

Please sign in to comment.