Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8243151

Intrinsic _getInt may remove the side effect of Unsafe.getInt()

    Details

      Description

      jdk.internal.misc.Unsafe.getInt() can be recognized as an intrinsic _getInt by C2. If C2 does, it may wipe out the whole statement in GVN.

      C2 optimizer may accidentally remove the side effect of Unsafe.getInt(). It will cause inconsistent behavior between C2 and others.

      eg. $cat TestUnsafeIntrinsics.java
      import jdk.internal.misc.Unsafe;

      public class TestUnsafeIntrinsics {
          static final Unsafe UNSAFE = Unsafe.getUnsafe();
          static boolean f = false;
          static int address;

          private static int getAddress() {
              return address;
          }

          public static void test() {
              // UNSAFE.getInt(0); // failed to inline.
              UNSAFE.getInt(getAddress()); // succeed to inline and intrinsify,
          }

          static public void main(String[] args) {
              test();
          }
      }

      javac --add-exports java.base/jdk.internal.misc=ALL-UNNAMED TestUnsafeIntrinsics.java
      java -XX:+UnlockDiagnosticVMOptions -Xcomp -XX:CompileCommand=compileonly,TestUnsafeIntrinsics::* --add-exports java.base/jdk.internal.misc=ALL-UNNAMED -XX:-TieredCompilation --cp . TestUnsafeIntrinsics

      nothing will happen because UNSAFE.getInt(getAddress()) is removed.
      Hotspot with -Xint will crash because getInt(0) violates off-heap address space.

      Please note that after JDK-8224658, UNSAFE.getInt(0) will fail to inline.

        Attachments

          Activity

            People

            • Assignee:
              xliu Xin Liu
              Reporter:
              xliu Xin Liu
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: