RFR: 8188055: (ref) Add Reference::refersTo predicate [v2]
Per Liden
pliden at openjdk.java.net
Mon Oct 12 19:25:20 UTC 2020
On Mon, 12 Oct 2020 15:56:59 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> test/hotspot/jtreg/gc/TestReferenceRefersTo.java line 186:
>>
>>> 184:
>>> 185: expectNotValue(testWeak2, testObject3, "testWeak2");
>>> 186: expectValue(testWeak3, testObject3, "testWeak3");
>>
>> It looks to me like the `expectNotCleared()` and `expectNotValue()` methods can be removed. All expect-tests can be
>> done with just `expectCleared()` and `expectValue()`.
>
> I don't think so. For example,
> `expectNotCleared(testWeak1, "testWeak1")`
> is not testing the same thing as
> `expectValue(testWeak1, testObject1, "testWeak1")`
> If the implementation is correct they will indeed always be consistent. But they could be different with an incorrect
> implementation.
Doesn't that just depend on how you implement `expectValue()`/`expectCleared()`? You could for example implement
`expectValue()`/`expectCleared()` to be supersets of `expectNotCleared()`/`expectNotValue()`, which I think would make
this easier to read. Something like this:
private static void expectValue(...) {
if (ref.refersTo(null)) {
fail("expected " + which + " to not be cleared");
}
if (!ref.refersTo(value)) {
fail(which + " refers to unexpected value");
}
}
private static void expectCleared(...) {
if (ref.refersTo(new TestObject(5))) {
fail(which + " refers to unexpected value");
}
if (!ref.refersTo(null)) {
fail("expected " + which + " to be cleared");
}
}
-------------
PR: https://git.openjdk.java.net/jdk/pull/498
More information about the core-libs-dev
mailing list