On Mon, 7 Dec 2020 23:34:00 GMT, Chris Plummer <[email protected]> wrote:

>> I don't follow your reasoning here Chris. All ObjectReferences can be GC'd 
>> at any time unless GC has been disallowed. So a reference create via 
>> newInstance is no different to any other reference. If it is currently 
>> reachable then instances() should return it. Are you treating "reachable for 
>> the purposes of garbage collection" as-if it said "strongly reachable"? It 
>> doesn't so I think you are reading too much into this. I think there is a 
>> lot of flexibility in this API in terms of what it may return regarding weak 
>> references.
>
> I read "reachable for the purposes of garbage collection" as not including 
> objects reachable only via weak reference. So if the only reference to an 
> object is a weak reference, which is normally what you have after calling 
> `ClassType.newInstance()`, then the object is not considered reachable. At 
> the very least, his is how `ReferenceType.instances()` is implemented, and is 
> based on JVMTI 
> [FollowReferences](https://docs.oracle.com/en/java/javase/14/docs/specs/jvmti.html#FollowReferences)().
> 
> So given that, the expectation would be that an object returned 
> `ClassType.newInstance()` would not be counted by `ReferenceType.instances()` 
> unless something is done to add a strong reference to the object, such as 
> calling `ObjectReference.disableCollection()`. Now with Per's changes a 
> strong reference is also created with doing a VM.suspend(). The test doesn't 
> expect this behavior, and it's understandable why.

I think we're still within what the spec says, given that the wording is so 
loose. But it's hard to tell if this change will be problematic for some use 
case.

-------------

PR: https://git.openjdk.java.net/jdk/pull/1595

Reply via email to