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

Volatile Unsafe accesses do not subsume null checks

XMLWordPrintable

      Here is a simple example:

          @Benchmark
          public int plain_checked_local() {
              Target v = this.t;
              if (v == null) {
                  throw new NullPointerException();
              }
              return v.f;
          }

          @Benchmark
          public int unsafe_checked_local() {
              Target v = this.t;
              if (v == null) {
                  throw new NullPointerException();
              }
              return U.getIntVolatile(v, OFF);
          }

      In plain case, we will subsume the explicit null check into the access itself. In Unsafe case, we will keep the explicit null check untouched. This apparently happens only for volatile Unsafe accesses. "Regular" Unsafe accesses, e.g. getInt, apparently subsume the null checks without problems.

      This affects Atomic*FieldUpdater hotpaths now, and will affect future VarHandles hotpaths.

      Benchmark, plus abbreviated generated code:
       http://cr.openjdk.java.net/~shade/8144717/UnsafeImplicitNullCheck.java

      Full perfasm output:
       http://cr.openjdk.java.net/~shade/8144717/output.perfasm

      Runnable JAR:
        http://cr.openjdk.java.net/~shade/8144717/benchmarks.jar

            Unassigned Unassigned
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: