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

Volatile Unsafe accesses do not subsume null checks

    XMLWordPrintable

    Details

      Description

      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

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: