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

C1 should fold (this == null) to false

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b93

      Description

      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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: