nativelibs4java / BridJ

BridJ: blazing fast Java / C / C++ interop
https://code.google.com/archive/p/bridj/
Other
297 stars 77 forks source link

Test failures on Linux AMD64 #119

Open phi-gamma opened 1 year ago

phi-gamma commented 1 year ago

Hi, both on current master and on the 0.7.0 tag two tests fail for me with these backtraces:

Tests run: 33, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.049 sec <<< FAILURE! - in org.bridj.DemanglingTest
testIntVsPointer_32bits(org.bridj.DemanglingTest)  Time elapsed: 0.005 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:21)
    at org.bridj.util.PlatformTestUtils.force32Bits(PlatformTestUtils.java:29)
    at org.bridj.DemanglingTest.testIntVsPointer_32bits(DemanglingTest.java:546)

testIntVsPointer_64bits(org.bridj.DemanglingTest)  Time elapsed: 0 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:21)
    at org.bridj.util.PlatformTestUtils.force64Bits(PlatformTestUtils.java:32)
    at org.bridj.DemanglingTest.testIntVsPointer_64bits(DemanglingTest.java:559)

From a look at the code, that absent field is SIZE.

My system:

$ uname -a
Linux styx 6.1.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 01 Feb 2023 17:07:39 +0000 x86_64 GNU/Linux

$ java --version
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 -Duser.language=en -Duser.country=US -Duser.timezone=UTC
openjdk 17.0.6 2023-01-17
OpenJDK Runtime Environment (build 17.0.6+10)
OpenJDK 64-Bit Server VM (build 17.0.6+10, mixed mode)

$ pacman -Q glibc
glibc 2.36-7

Let me know if you need more info.

phi-gamma commented 1 year ago

From a look at the code, that absent field is SIZE.

Looks like I was mistaken. It’s actually this line that crashes:

Field modifiersField = Field.class.getDeclaredField("modifiers");

Google led me to this answer which in turn leads to this JVM commit from 2018 that introduced screening of various fields on account of their “sensitivity”. Thus the current approach taken in makeFieldWritable can no longer work with recent JVMs.