什么是解引用链偏序?

What is Dereference Chain partial ordering?

我一直在阅读 Java8 语言规范的 17.5.1 最终字段语义部分。我无法理解取消引用链是什么。 以下是规范中的内容:

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).

请帮我理解一下。谢谢。

解引用链只不过是字段的访问路径。

例如:

class Foo {

  final Object finalVal;
  Object nonFinalVal;

  Bar(Object val) {
    finalVal = val;
    nonFinalVal = val;
  }
}

给定实例 Foo foo,您现在可以通过 foo.finalValfoo.nonFinalVal 取消引用实例 val。只有 foo.finalVal 通过最终字段引用以保证其可见性。

因此,在 Java 内存模型中,使用什么解引用链来读取对象是很重要的,即使读取的对象是相同的。