-
Enhancement
-
Resolution: Fixed
-
P4
-
9
-
b92
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8143476 | emb-9 | Aleksey Shipilev | P4 | Resolved | Fixed | team |
JDK-8149216 | 8u101 | Aleksey Shipilev | P4 | Resolved | Fixed | b01 |
JDK-8143130 | 8u92 | Aleksey Shipilev | P4 | Resolved | Fixed | b01 |
JDK-8155312 | emb-8u101 | Aleksey Shipilev | P4 | Resolved | Fixed | b01 |
public class Data {
volatile int dataInt;
static final AtomicIntegerFieldUpdater<Data> UPDATER_INT
= AtomicIntegerFieldUpdater.newUpdater(Data.class, "dataInt");
int m() {
return UPDATER_INT.get(this);
}
}
This code will lose against the plain field access and Unsafe access, because updaters do the extensive checks before doing the actual access:
private final Class<T> tclass;
private final Class<?> cclass;
public final int get(T obj) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
return unsafe.getIntVolatile(obj, offset);
}
Fortunately, since the use pattern makes the updater a (static final) constant, we can make VM to trust the final instance fields in updater. Then, updater checks would be folded in as constants, closing the gap in updater performance. This is a special case of more general approach (see JDK-8058164), but it seems doable before a more generic solution arrives. This caters for lots of existing users.
Proof-of-concept change:
http://cr.openjdk.java.net/~shade/8140483/webrev.00/
Benchmarks:
http://cr.openjdk.java.net/~shade/8140483/AFUBench.java
http://cr.openjdk.java.net/~shade/8140483/benchmarks.jar
Quick runs show the entire slab of tests is folded into the typecheck + implicit NP check, with good performance improvements:
http://cr.openjdk.java.net/~shade/8140483/notes.txt
- backported by
-
JDK-8143130 Atomic*FieldUpdaters final fields should be trusted
-
- Resolved
-
-
JDK-8143476 Atomic*FieldUpdaters final fields should be trusted
-
- Resolved
-
-
JDK-8149216 Atomic*FieldUpdaters final fields should be trusted
-
- Resolved
-
-
JDK-8155312 Atomic*FieldUpdaters final fields should be trusted
-
- Resolved
-
- relates to
-
JDK-8233873 final field values should be trusted as constant
-
- Open
-
-
JDK-8140587 Atomic*FieldUpdaters should use Class.isInstance instead of direct class check
-
- Resolved
-
-
JDK-8058164 final fields in objects need to support inlining optimizations
-
- Open
-