openj9 icon indicating copy to clipboard operation
openj9 copied to clipboard

java.lang.IllegalAccessException thrown for jdk.internal.misc.Unsafe.theUnsafe in Valhalla vt_standard testing

Open hzongaro opened this issue 1 year ago • 8 comments

Many test failures are seen in recent PR sanity.functional testing with {x|z|a|p}linuxvalst (i.e., vt_standard) for pull requests #20112 and #20332. In most, if not all, cases IllegalAccessExceptions are thrown. I was able to reproduce this in an internal personal build with the latest merged source.

12:45:24  openjdk version "24-internal" 2025-03-18
12:45:24  OpenJDK Runtime Environment (build 24-internal-adhoc.jenkins.BuildJDKnextx86-64linuxvtstandardPersonal)
12:45:24  Eclipse OpenJ9 VM (build master-d51176e7598, JRE 24 Linux amd64-64-Bit Compressed References 20241016_390 (JIT enabled, AOT enabled)
12:45:24  OpenJ9   - d51176e7598
12:45:24  OMR      - 0de486a739f
12:45:24  JCL      - 972edea3789 based on jdk-24+12)
13:00:49  Testing: Create and Restore Criu Checkpoint Image once - CheckpointDeadlock
13:00:49  Test start time: 2024/10/16 10:00:48 Pacific Standard Time
13:00:49  Running command: bash /home/jenkins/workspace/Test_openjdknext_j9_sanity.functional_x86-64_linux_vt_standard_Personal_testList_1/aqa-tests/TKG/../../jvmtest/functional/cmdLineTests/criu/criuScript.sh /home/jenkins/workspace/Test_openjdknext_j9_sanity.functional_x86-64_linux_vt_standard_Personal_testList_1/aqa-tests/TKG/../../jvmtest/functional/cmdLineTests/criu /home/jenkins/workspace/Test_openjdknext_j9_sanity.functional_x86-64_linux_vt_standard_Personal_testList_1/jdkbinary/j2sdk-image/bin/java " -Xjit -XX:+CRIURestoreNonPortableMode  --add-opens java.base/jdk.internal.misc=ALL-UNNAMED  --add-exports java.base/openj9.internal.criu=ALL-UNNAMED" org.openj9.criu.DeadlockTest CheckpointDeadlock 1 false false
13:00:49  Time spent starting: 2 milliseconds
13:00:51  Time spent executing: 2266 milliseconds
13:00:51  Test result: FAILED
13:00:51  Output from test:
13:00:51   [OUT] start running script
13:00:51   [OUT] export GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVEC,-XSAVE,-AVX2,-ERMS,-AVX,-AVX_Fast_Unaligned_Load
13:00:51   [OUT] export LD_BIND_NOT=on
13:00:51   [OUT] /home/jenkins/workspace/Test_openjdknext_j9_sanity.functional_x86-64_linux_vt_standard_Personal_testList_1/jdkbinary/j2sdk-image/bin/java -XX:+EnableCRIUSupport  -Xjit -XX:+CRIURestoreNonPortableMode  --add-opens java.base/jdk.internal.misc=ALL-UNNAMED  --add-exports java.base/openj9.internal.criu=ALL-UNNAMED -cp /home/jenkins/workspace/Test_openjdknext_j9_sanity.functional_x86-64_linux_vt_standard_Personal_testList_1/aqa-tests/TKG/../../jvmtest/functional/cmdLineTests/criu/criu.jar org.openj9.criu.DeadlockTest CheckpointDeadlock 1
13:00:51   [OUT] Exception in thread "main" java.lang.InternalError: java.lang.IllegalAccessException: static final field has no write access: jdk.internal.misc.Unsafe.theUnsafe/jdk.internal.misc.Unsafe/putStatic, from class java.lang.Object (module java.base)
13:00:51   [OUT] 	at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.newFieldAccessor(MethodHandleAccessorFactory.java:207)
13:00:51   [OUT] 	at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:144)
13:00:51   [OUT] 	at java.base/java.lang.reflect.Field.acquireOverrideFieldAccessor(Field.java:1212)
13:00:51   [OUT] 	at java.base/java.lang.reflect.Field.getOverrideFieldAccessor(Field.java:1181)
13:00:51   [OUT] 	at java.base/java.lang.reflect.Field.get(Field.java:454)
13:00:51   [OUT] 	at org.openj9.criu.DeadlockTest.<clinit>(DeadlockTest.java:356)
13:00:51   [OUT] Caused by: java.lang.IllegalAccessException: static final field has no write access: jdk.internal.misc.Unsafe.theUnsafe/jdk.internal.misc.Unsafe/putStatic, from class java.lang.Object (module java.base)
13:00:51   [OUT] 	at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:913)
13:00:51   [OUT] 	at java.base/java.lang.invoke.MethodHandles$Lookup.unreflectField(MethodHandles.java:3608)
13:00:51   [OUT] 	at java.base/java.lang.invoke.MethodHandles$Lookup.unreflectSetter(MethodHandles.java:3599)
13:00:51   [OUT] 	at java.base/java.lang.invoke.MethodHandleImpl$1.unreflectField(MethodHandleImpl.java:1621)
13:00:51   [OUT] 	at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.newFieldAccessor(MethodHandleAccessorFactory.java:185)
13:00:51   [OUT] 	... 5 more
13:00:51   [OUT] initiate restore
13:00:51   [OUT] Error (criu/protobuf.c:72): Unexpected EOF on (empty-image)
13:00:51   [OUT] Removed test output files
13:00:51   [OUT] finished script

hzongaro avatar Oct 17 '24 14:10 hzongaro

@theresa-m, @a7ehuo - FYI

hzongaro avatar Oct 17 '24 14:10 hzongaro

Issue Number: 20372 Status: Open Recommended Components: comp:test, comp:vm, comp:gc Recommended Assignees: jasonfengj9, tajila, babsingh

github-actions[bot] avatar Oct 17 '24 14:10 github-actions[bot]

The failed line is: https://github.com/eclipse-openj9/openj9/blob/64cb0dbf2bbba87a294e5b5a5c3a7e5d92ec0514/test/functional/cmdLineTests/criu/src/org/openj9/criu/DeadlockTest.java#L356

@JasonFengJ9 Do you know if this fails on regular JDK24 build ?

hangshao0 avatar Oct 17 '24 16:10 hangshao0

Do you know if this fails on regular JDK24 build ?

Currently, there are no JDK24 nightly builds. Last openjdknext_j9_sanity.functional_aarch64_mac passed on Oct. 3rd. Launched a JDKnext_x86-64_linux.

JasonFengJ9 avatar Oct 17 '24 17:10 JasonFengJ9

Those failed tests in openjdknext_j9_sanity.functional_x86-64_linux_vt_standard passed in a regular openjdkNext_j9_sanity.functional_x86-64_linux

cmdLineTester_criu_nonPortableRestore_0_PASSED
...
cmdLineTester_libpathTestRtf_0_PASSED
...

FYI @hangshao0

JasonFengJ9 avatar Oct 17 '24 19:10 JasonFengJ9

Have you seen this failure before ? @babsingh @fengxue-IS

The https://github.com/ibmruntimes/openj9-openjdk-jdk.valuetypes repo is a few weeks behind https://github.com/ibmruntimes/openj9-openjdk-jdk though.

hangshao0 avatar Oct 18 '24 14:10 hangshao0

Two possible solutions come to mind:

  1. update https://github.com/ibmruntimes/openj9-openjdk-jdk.valuetypes - perhaps this is already fixed upstream
  2. change the way the Unsafe instance is acquired in tests - we're already using --add-opens to gain access to the package so we could just use Unsafe.getUnsafe() rather than reflection

keithc-ca avatar Oct 18 '24 14:10 keithc-ca

Have you seen this failure before ?

It seems new. I haven't seen it before.

babsingh avatar Oct 18 '24 18:10 babsingh

I tried the failing code with old Valhalla nightly builds and it started failing after the https://github.com/ibmruntimes/openj9-openjdk-jdk.valuetypes update in early May.

theresa-m avatar Oct 22 '24 16:10 theresa-m

I looked through the merge commits of these files from the May extensions update but did not see anything inconsistent with the https://github.com/ibmruntimes/openj9-openjdk-jdk repository. This list is a subset of files identified as having had conflicts in https://github.com/ibmruntimes/openj9-openjdk-jdk.valuetypes/pull/10, https://github.com/ibmruntimes/openj9-openjdk-jdk.valuetypes/pull/11, https://github.com/ibmruntimes/openj9-openjdk-jdk.valuetypes/pull/12

src/java.base/share/classes/sun/invoke/util/VerifyAccess.java
src/java.base/share/classes/java/lang/reflect/Modifier.java
src/java.base/share/classes/java/lang/invoke/MethodHandles.java
src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java
src/java.base/share/classes/jdk/internal/misc/Unsafe.java
src/java.base/share/classes/sun/invoke/util/Wrapper.java
src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java
src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java

theresa-m avatar Oct 31 '24 17:10 theresa-m

I'm inclined to believe that openjdk hasn't finished updating the Field implementation. The usage pattern (seen in the description) should not require generation of a setter, but an override field is never considered read-only. See ReflectionFactory.java.

keithc-ca avatar Oct 31 '24 17:10 keithc-ca

ValueType changed Field.java's boolean trustedfinal to int flags to allow for multiple flags. Inorder to match the expected behaviour, we need to update reflecthelp.c:840 to set the correct bits instead of JNI_TRUE for value type builds. see https://github.com/ibmruntimes/openj9-openjdk-jdk.valuetypes/blob/f488e607b7b61b5e4e9c088fb88b627531d9b1a6/src/java.base/share/classes/java/lang/reflect/Field.java#L1243-L1244 for flag constant.

fengxue-IS avatar Nov 07 '24 21:11 fengxue-IS

Thanks @fengxue-IS !

I tested this out locally and it seems to solve the issue, I will work on testing further and submitting a fix.

theresa-m avatar Nov 08 '24 15:11 theresa-m

Issue Number: 20372 Status: Closed Actual Components: comp:vm, project:valhalla Actual Assignees: No one :( PR Assignees: theresa-m, JasonFengJ9

github-actions[bot] avatar Nov 12 '24 15:11 github-actions[bot]