-
Enhancement
-
Resolution: Unresolved
-
P4
-
9, 10
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
@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