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

C1 should fold (this == null) to false

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 9
    • hotspot
    • None
    • b93

      The predicate "(this == null)" is always false in a valid Java program, and therefore, it should be folded to "false". While the pattern is almost never explicitly appear in Java programs, it may effectively manifest after inlining, e.g. like:

          @Benchmark
          @CompilerControl(CompilerControl.Mode.DONT_INLINE)
          public void test() {
              m(this);
          }

          private void m(Object o) {
              if (o == null) {
                  throw new IllegalArgumentException();
              }
          }

      A real-life case is java.util.concurrent.atomic.A*FU checks. C2 optimizes these cases nicely. C1 does not optimize it, but it really should.

      Benchmark:
       http://cr.openjdk.java.net/~shade/8141044/ThisNull.java

      C1 perfasm, notice the null check in org.openjdk.ThisNull::test:
       http://cr.openjdk.java.net/~shade/8141044/c1.perfasm

      C2 perfasm, notice the absence of null check:
       http://cr.openjdk.java.net/~shade/8141044/c2.perfasm

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

              Created:
              Updated:
              Resolved: