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
@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
- relates to
-
JDK-8149356 Leftover from JDK-8141044: UseNewCode usage
-
- Resolved
-