From c1db53bd12034b2056122de8cab90eb2ea99e1c4 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 10 Feb 2023 09:51:56 +0100 Subject: [PATCH 1/2] ignore pointer size tests As of JVM 12 and later it is no longer possible to cast away the ``final`` modifier using reflection so the ``forece{32,64}Bit`` helpers error out with an exception: Tests run: 34, Failures: 0, Errors: 2, Skipped: 1, Time elapsed: 0.052 sec <<< FAILURE! - in org.bridj.DemanglingTest testIntVsPointer_32bits(org.bridj.DemanglingTest) Time elapsed: 0.006 sec <<< ERROR! java.lang.RuntimeException: java.lang.NoSuchFieldException: modifiers at java.base/java.lang.Class.getDeclaredField(Class.java:2610) at org.bridj.util.ReflectionUtils.makeFieldWritable(ReflectionUtils.java:42) at org.bridj.util.PlatformTestUtils.forcePointerSize(PlatformTestUtils.java:22) at org.bridj.util.PlatformTestUtils.force32Bits(PlatformTestUtils.java:30) at org.bridj.DemanglingTest.testIntVsPointer_32bits(DemanglingTest.java:553) testIntVsPointer_64bits(org.bridj.DemanglingTest) Time elapsed: 0.001 sec <<< ERROR! java.lang.RuntimeException: java.lang.NoSuchFieldException: modifiers at java.base/java.lang.Class.getDeclaredField(Class.java:2610) at org.bridj.util.ReflectionUtils.makeFieldWritable(ReflectionUtils.java:42) at org.bridj.util.PlatformTestUtils.forcePointerSize(PlatformTestUtils.java:22) at org.bridj.util.PlatformTestUtils.force64Bits(PlatformTestUtils.java:33) at org.bridj.DemanglingTest.testIntVsPointer_64bits(DemanglingTest.java:566) Disable those tests until the functionality can be restored. References: - https://bugs.openjdk.java.net/browse/JDK-8210522 - https://stackoverflow.com/a/56043252/7321177 Signed-off-by: Philipp Gesang --- src/test/java/org/bridj/DemanglingTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/bridj/DemanglingTest.java b/src/test/java/org/bridj/DemanglingTest.java index 6af7df24..26c18226 100644 --- a/src/test/java/org/bridj/DemanglingTest.java +++ b/src/test/java/org/bridj/DemanglingTest.java @@ -549,6 +549,7 @@ static void checkSymbol(String demanglerName, String str, MemberRef symbol, Type } @Test + @Ignore("Can’t work in JVM 12+: https://bugs.openjdk.org/browse/JDK-8210522") public void testIntVsPointer_32bits() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { force32Bits(); @@ -562,6 +563,7 @@ public void testIntVsPointer_32bits() throws NoSuchFieldException, IllegalArgume } @Test + @Ignore("Can’t work in JVM 12+: https://bugs.openjdk.org/browse/JDK-8210522") public void testIntVsPointer_64bits() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { force64Bits(); From 56ef3dcacf994dd6f973380931c447b4bcdf095d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 10 Feb 2023 13:28:33 +0100 Subject: [PATCH 2/2] fix platform detection logic on MacOS This was tested on an M1 MacBook; it reports the machine type as ``arm64``, not ``aarch64``. The full ``uname -a`` output is: Darwin -MBP14.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64 This diverges from what ``System.getProperty("os.arch")`` reports as the architecture. Signed-off-by: Philipp Gesang --- BuildNative | 7 ++++++- src/main/java/org/bridj/Platform.java | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/BuildNative b/BuildNative index 91250c44..36e3f661 100755 --- a/BuildNative +++ b/BuildNative @@ -8,6 +8,11 @@ export DYNCALL_HOME=$BASE_DIR/dyncall DYNCALL_DIFF=$BASE_DIR/src/main/cpp/bridj/dyncall.diff +function failed() { + echo "$@" + exit 1 +} + if [[ ! -d "$DYNCALL_HOME" ]] then $BASE_DIR/admin/checkout_and_patch_dyncall.sh $DYNCALL_DIFF || failed "Failed to checkout and patch dyncall" @@ -40,7 +45,7 @@ function get_arch() { x86_64|amd64) echo x64 ;; - aarch64) + aarch64|arm64) echo arm64 ;; arm*) diff --git a/src/main/java/org/bridj/Platform.java b/src/main/java/org/bridj/Platform.java index f04f5e6f..8777107f 100644 --- a/src/main/java/org/bridj/Platform.java +++ b/src/main/java/org/bridj/Platform.java @@ -525,6 +525,9 @@ public static String getMachine() { return "i386"; // we are running a 32 bits JVM on a 64 bits platform } } + if (isMacOSX() && arch.equals("aarch64")) { + return "arm64"; + } return arch; }