Skip to content

Commit

Permalink
simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbarrett committed Oct 14, 2020
1 parent 8b7c333 commit efa40d7
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions test/hotspot/jtreg/gc/TestReferenceRefersTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public TestObject(int value) {
}
}

private static volatile TestObject testObjectNone = null;
private static volatile TestObject testObject1 = null;
private static volatile TestObject testObject2 = null;
private static volatile TestObject testObject3 = null;
Expand All @@ -66,6 +67,7 @@ public TestObject(int value) {
private static WeakReference<TestObject> testWeak4 = null;

private static void setup() {
testObjectNone = new TestObject(0);
testObject1 = new TestObject(1);
testObject2 = new TestObject(2);
testObject3 = new TestObject(3);
Expand All @@ -90,6 +92,7 @@ private static void gcUntilOld(Object o) throws Exception {
}

private static void gcUntilOld() throws Exception {
gcUntilOld(testObjectNone);
gcUntilOld(testObject1);
gcUntilOld(testObject2);
gcUntilOld(testObject3);
Expand All @@ -112,13 +115,15 @@ private static void fail(String msg) throws Exception {

private static void expectCleared(Reference<TestObject> ref,
String which) throws Exception {
expectNotValue(ref, testObjectNone, which);
if (!ref.refersTo(null)) {
fail("expected " + which + " to be cleared");
}
}

private static void expectNotCleared(Reference<TestObject> ref,
String which) throws Exception {
expectNotValue(ref, testObjectNone, which);
if (ref.refersTo(null)) {
fail("expected " + which + " to not be cleared");
}
Expand All @@ -127,12 +132,10 @@ private static void expectNotCleared(Reference<TestObject> ref,
private static void expectValue(Reference<TestObject> ref,
TestObject value,
String which) throws Exception {
expectNotValue(ref, testObjectNone, which);
expectNotCleared(ref, which);
if (!ref.refersTo(value)) {
if (ref.refersTo(null)) {
fail("expected " + which + " to not be cleared");
} else {
fail(which + " refers to unexpected value");
}
fail(which + " doesn't refer to expected value");
}
}

Expand All @@ -152,6 +155,7 @@ private static void checkInitialStates() throws Exception {
}

private static void discardStrongReferences() {
// testObjectNone not dropped
testObject1 = null;
testObject2 = null;
// testObject3 not dropped
Expand All @@ -178,11 +182,7 @@ private static void testConcurrentCollection() throws Exception {

progress("fetch test objects, possibly keeping some alive");
expectNotCleared(testPhantom1, "testPhantom1");

expectNotCleared(testWeak2, "testWeak2");
expectNotCleared(testWeak3, "testWeak3");

expectNotValue(testWeak2, testObject3, "testWeak2");
expectValue(testWeak3, testObject3, "testWeak3");

// For some collectors, calling get() will keep testObject4 alive.
Expand All @@ -196,12 +196,9 @@ private static void testConcurrentCollection() throws Exception {
progress("verify expected clears");
expectCleared(testPhantom1, "testPhantom1");
expectCleared(testWeak2, "testWeak2");
expectNotCleared(testWeak3, "testWeak3");
expectNotCleared(testWeak4, "testWeak4");

expectNotValue(testPhantom1, testObject3, "testPhantom1");
expectValue(testWeak3, testObject3, "testWeak3");
expectNotValue(testWeak4, testObject3, "testWeak4");
// This is true for all currently supported concurrent collectors.
expectNotCleared(testWeak4, "testWeak4");

progress("verify get returns expected values");
if (testWeak2.get() != null) {
Expand Down Expand Up @@ -278,11 +275,8 @@ private static void testSimpleCollection() throws Exception {
progress("verify expected clears");
expectCleared(testPhantom1, "testPhantom1");
expectCleared(testWeak2, "testWeak2");
expectNotCleared(testWeak3, "testWeak3");
expectNotCleared(testWeak4, "testWeak4");

expectNotValue(testWeak2, testObject3, "testWeak2");
expectValue(testWeak3, testObject3, "testWeak3");
expectNotCleared(testWeak4, "testWeak4");

progress("verify get returns expected values");
if (testWeak2.get() != null) {
Expand Down

0 comments on commit efa40d7

Please sign in to comment.