< prev index next >
test/gc/stress/TestStressRSetCoarsening.java
Print this page
rev 11275 : 8157153: TestStressRSetCoarsening fails with OOM
Reviewed-by:
@@ -101,10 +101,11 @@
private static final long MB = 1024 * KB;
private static final WhiteBox WB = WhiteBox.getWhiteBox();
public final Object[][] storage;
+ public int storageUsedCount;
/**
* Number of objects per region. This is a test parameter.
*/
public final int K;
@@ -159,10 +160,12 @@
Runtime rt = Runtime.getRuntime();
long used = rt.totalMemory() - rt.freeMemory();
long totalFree = rt.maxMemory() - used;
regionCount = (int) ((totalFree / regionSize) * heapFractionToAllocate);
long toAllocate = regionCount * regionSize;
+ long freeMemoryLimit = totalFree - toAllocate;
+
System.out.println("%% Test parameters");
System.out.println("%% Objects per region : " + K);
System.out.println("%% Heap fraction to allocate : " + (int) (heapFractionToAllocate * 100) + "%");
System.out.println("%% Regions to refresh to provoke GC: " + regsToRefresh);
@@ -210,13 +213,21 @@
System.out.println("%% K (objects in regions): " + K);
System.out.println("%% Object size : " + objSize +
" (sizeOf(new Object[" + N + "])");
System.out.println("%% Reference size : " + refSize);
+ // Maximum number of objects to allocate is regionCount * K.
storage = new Object[regionCount * K][];
- for (int i = 0; i < storage.length; i++) {
- storage[i] = new Object[N];
+ storageUsedCount = 0;
+
+ // Add objects as long as there is space in the array
+ // and we haven't used more memory than planned.
+ while (storageUsedCount < storage.length &&
+ (rt.maxMemory() - used) > freeMemoryLimit) {
+ storage[storageUsedCount++] = new Object[N];
+ // Update used memory
+ used = rt.totalMemory() - rt.freeMemory();
}
}
public void go() throws InterruptedException {
// threshold for sparce -> fine
@@ -253,11 +264,11 @@
for (int to = 0; to < regionCount; to++) {
// Select a celebrity object that we will install references to.
// The celebrity will be referred from all other regions.
// If the number of references after should be less than they
// were before, select NULL.
- Object celebrity = cur > pre ? storage[to * K] : null;
+ Object celebrity = cur > pre ? storage[(to * K) % storageUsedCount] : null;
for (int from = 0; from < regionCount; from++) {
if (to == from) {
continue; // no need to refer to itself
}
@@ -295,11 +306,11 @@
}
// 'Refresh' storage elements for the region 'to'
// After that loop all 'old' objects in the region 'to'
// should become unreachable.
for (int k = 0; k < K; k++) {
- storage[(to * K + k) % storage.length] = new Object[N];
+ storage[(to * K + k) % storageUsedCount] = new Object[N];
}
}
}
} catch (TimeoutException e) {
System.out.println("%% TIMEOUT!!!");
@@ -331,12 +342,12 @@
*
* @param to region # to refer to
* @param from region # to refer from
* @param rn number of reference
*
- * @return Y index in the range: [0 ... K*regionCount -1]
+ * @return Y index in the range: [0 ... storageUsedCount-1]
*/
private int getY(int to, int from, int rn) {
- return ((rn * regionCount + to) / N + from * K) % (regionCount * K);
+ return ((rn * regionCount + to) / N + from * K) % (regionCount * K) % storageUsedCount;
}
}
< prev index next >