I have been reading the section 17.5.1 Semantics of final Fields of Java8 Language specification. I am not able to understand what Dereference Chain is. Here's what's written in the specification:
For each execution, the behavior of reads is influenced by two additional partial orders, the dereference chain dereferences() and the memory chain mc(), which are considered to be part of the execution (and thus, fixed for any particular execution). These partial orders must satisfy the following constraints (which need not have a unique solution):
• Dereference Chain: If an action a is a read or write of a field or element of an object o by a thread t that did not initialize o, then there must exist some read r by thread t that sees the address of o such that r dereferences(r, a).
• Memory Chain: There are several constraints on the memory chain ordering: – If r is a read that sees a write w, then it must be the case that mc(w, r). – If r and a are actions such that dereferences(r, a), then it must be the case that mc(r, a). – If w is a write of the address of an object o by a thread t that did not initialize o, then there must exist some read r by thread t that sees the address of o such that mc(r, w).
Please help me understad. Thank You.
The dereferencing chain is nothing more then the access path to a field.
For example:
class Foo {
final Object finalVal;
Object nonFinalVal;
Bar(Object val) {
finalVal = val;
nonFinalVal = val;
}
}
Given an instance Foo foo
, you can now dereference the instance val
both via foo.finalVal
and foo.nonFinalVal
. Only foo.finalVal
passes through a final field reference such that its visibility is guaranteed.
In the Java memory model it is therefore essential what dereferencing chain is used for reading an object, even if the read object is identical.