JDK-6858496 : Clear all SoftReferences before reaching the GC overhead limit.
Type:Enhancement
Component:hotspot
Sub-Component:gc
Affected Version:7
Priority:P3
Status:Closed
Resolution:Fixed
OS:generic
CPU:generic
Submitted:2009-07-08
Updated:2011-03-08
Resolved:2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
EVALUATION
Clear all SoftReferences before throwing an out-of-memory due to GC overhead
considerations.
13-08-2009
PUBLIC COMMENTS
I'm adding here a small application, given to me by a customer, that aggressively touches all soft references and can cause an OOM in the server VM due to reaching the GC overhead limit with soft references not properly cleared.
public class SoftCrash {
public static void main(String[] args) {
Map<Integer, SoftReference<byte[]>> map =
new HashMap<Integer, SoftReference<byte[]>>();
for (int i = 0; i < Integer.MAX_VALUE; i++) {
map.put(i, new SoftReference<byte[]>(new byte[100000]));
if ((i & 255) == 0)
System.out.print("*");
/*
* If you comment this block out or run on the client VM,
* this program will run indefinitely. If you run it on the
* server VM, it quickly crashes with an OutOfMemoryError.
*/
for (int j = 0; j <= i; j++) {
byte[] a = map.get(i).get();
if (a != null)
a[0]++;
}
}
}
}