-
Enhancement
-
Resolution: Unresolved
-
P3
-
6u14
Behavior change since 6u14. The GC decides not to clear the SoftReference but
an object in the reference chain of that SoftReference is being cleared.
Below is the test program showing the problem. Specifically,
o2 is only reachable via s2 (SoftReference) and s2 is not cleared
and thus w2.get() should return non-null.
import java.lang.ref.*;
import java.util.*;
public class RefCompliance {
RefCompliance () {
}
public static void test() {
int[] o1 = new int[10];
WeakReference w1 = new WeakReference(o1);
SoftReference s1 = new SoftReference(w1);
int[] o2 = new int[10];
WeakReference w2 = new WeakReference(o2);
SoftReference s2 = new SoftReference(w2);
int[] o3 = new int[10];
WeakReference w3 = new WeakReference(o3);
o1 = null;
o2 = null;
o3 = null;
w2 = null;
// Scrub stack because of conservative collector
int[] dummy1 = new int[10];
int[] dummy2 = new int[10];
System.gc();
int res1;
w2 = (WeakReference)s2.get();
if (w1 == s1.get()) {
res1 = 0;
if (w1.get() == null) {
res1 += 100;
}
if (w2.get() == null) {
res1 += 10;
}
if (w3.get() == null) {
res1 += 1;
}
} else {
res1 = -1;
}
if (res1 == 101) {
System.err.println("JDK1.2");
} else if (res1 == 111) {
System.err.println("weakest link on strongest chain");
} else if (res1 == 001) {
System.err.println("API spec");
} else {
System.err.println("unknown: result " + res1);
}
}
public static void main(String[] args) {
test();
test();
test();
test();
test();
}
}
$ /java/re/jdk/6u13/latest/binaries/solaris-i586/bin/java RefCompliance
JDK1.2
JDK1.2
JDK1.2
JDK1.2
JDK1.2
$ /java/re/jdk/6u14/latest/binaries/solaris-i586/bin/java RefCompliance
weakest link on strongest chain
weakest link on strongest chain
weakest link on strongest chain
weakest link on strongest chain
weakest link on strongest chain
an object in the reference chain of that SoftReference is being cleared.
Below is the test program showing the problem. Specifically,
o2 is only reachable via s2 (SoftReference) and s2 is not cleared
and thus w2.get() should return non-null.
import java.lang.ref.*;
import java.util.*;
public class RefCompliance {
RefCompliance () {
}
public static void test() {
int[] o1 = new int[10];
WeakReference w1 = new WeakReference(o1);
SoftReference s1 = new SoftReference(w1);
int[] o2 = new int[10];
WeakReference w2 = new WeakReference(o2);
SoftReference s2 = new SoftReference(w2);
int[] o3 = new int[10];
WeakReference w3 = new WeakReference(o3);
o1 = null;
o2 = null;
o3 = null;
w2 = null;
// Scrub stack because of conservative collector
int[] dummy1 = new int[10];
int[] dummy2 = new int[10];
System.gc();
int res1;
w2 = (WeakReference)s2.get();
if (w1 == s1.get()) {
res1 = 0;
if (w1.get() == null) {
res1 += 100;
}
if (w2.get() == null) {
res1 += 10;
}
if (w3.get() == null) {
res1 += 1;
}
} else {
res1 = -1;
}
if (res1 == 101) {
System.err.println("JDK1.2");
} else if (res1 == 111) {
System.err.println("weakest link on strongest chain");
} else if (res1 == 001) {
System.err.println("API spec");
} else {
System.err.println("unknown: result " + res1);
}
}
public static void main(String[] args) {
test();
test();
test();
test();
test();
}
}
$ /java/re/jdk/6u13/latest/binaries/solaris-i586/bin/java RefCompliance
JDK1.2
JDK1.2
JDK1.2
JDK1.2
JDK1.2
$ /java/re/jdk/6u14/latest/binaries/solaris-i586/bin/java RefCompliance
weakest link on strongest chain
weakest link on strongest chain
weakest link on strongest chain
weakest link on strongest chain
weakest link on strongest chain
- relates to
-
JDK-4214755 (ref) JDK1.2 handling of nested refs seems to go against API spec
- Closed
-
JDK-6990438 (ref) Soft reference could consider strong if GC decides not to clear
- Open
-
JDK-7146977 finalize and PermGen and PhantomReference prevent GC inocrrectly
- Resolved
-
JDK-6684579 SoftReference processing can be made more efficient
- Resolved
-
JDK-8051680 (ref) unnecessary process_soft_ref_reconsider
- Resolved
-
JDK-8046124 JEP 134: Intuitive Semantics for Nested Reference Objects
- Candidate
(1 relates to)