On Dec 3, 2015, at 8:01 AM, Peter Levart <peter.lev...@gmail.com> wrote: > > Hi Kim, > > Kudos for finding an observable change in behavior. Although the > specification could also be read in a way so that this would not be > observable. Originally it states: > > "Unlike soft and weak references, phantom references are not automatically > cleared by the garbage collector as they are enqueued. An object that is > reachable via phantom references will remain so until all such references are > cleared or themselves become unreachable." > > I read this as: "... An object that is reachable via phantom references will > remain phantom reachable ..." > > If phantom-reachable objects have links among them, this doesn't make them > strongly reachable. > > So I would argue that when both roots to O1 and O2 (in the test) are finally > removed, O1 and O2 should be considered phantom-reachable, regardless of the > link from O1 -> O2. When root to O2 is removed before the 2nd GC round, P2 > should be notified as O2 transitions from reachable -> phantom reachable. > This is no different from the situation when both roots to O1 and O2 are > removed at the same time before a GC round: both P1 and P2 are notified.
I don't think that reading is correct. Consider the case of R being a weak (not phantom) reference. In that case, X can never be "phantom reachable", because the definition of that state includes "some phantom reference refers to it". If, in the scenario described, the reference from O to X did not prevent (the weak) R from being cleared and notified, the special rule for phantom references would have no visible impact. In which case we wouldn't need to change the specification; we could just change the implementation and claim there was no specified visible difference.