Skip to content

Commit 37aa320

Browse files
committed
8342376: More reliable OOM handling in ExceptionDuringDumpAtObjectsInitPhase test
Reviewed-by: iklam, phh
1 parent 18bcbf7 commit 37aa320

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

test/hotspot/jtreg/runtime/cds/appcds/javaldr/GCDuringDumpTransformer.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public class GCDuringDumpTransformer implements ClassFileTransformer {
3434
static boolean TEST_WITH_CLEANER = Boolean.getBoolean("test.with.cleaner");
3535
static boolean TEST_WITH_EXCEPTION = Boolean.getBoolean("test.with.exception");
3636
static boolean TEST_WITH_OOM = Boolean.getBoolean("test.with.oom");
37+
38+
static final int WASTE_SIZE = 1024;
3739
static List<byte[]> waste = new ArrayList();
40+
static Object sink;
3841

3942
static Cleaner cleaner;
4043
static Thread thread;
@@ -59,10 +62,13 @@ public byte[] transform(ClassLoader loader, String name, Class<?> classBeingRede
5962
return new byte[] {1, 2, 3, 4, 5, 6, 7, 8};
6063
}
6164
if (TEST_WITH_OOM) {
62-
// fill until OOM
65+
// Fill until OOM and fail. This sets up heap for secondary OOM
66+
// later on, which should be caught by CDS code. The size of waste
67+
// array defines how much max free space would be left for later
68+
// code to run with.
6369
System.out.println("Fill objects until OOM");
64-
for (;;) {
65-
waste.add(new byte[64*1024]);
70+
while (true) {
71+
waste.add(new byte[WASTE_SIZE]);
6672
}
6773
}
6874
}
@@ -104,8 +110,8 @@ public static void agentmain(String args, Instrumentation inst) throws Exception
104110
}
105111

106112
public static void makeGarbage() {
107-
for (int x=0; x<10; x++) {
108-
Object[] a = new Object[10000];
113+
for (int x = 0; x < 10; x++) {
114+
sink = new byte[WASTE_SIZE];
109115
}
110116
}
111117

@@ -115,7 +121,7 @@ static class MyCleaner implements Runnable {
115121
public void run() {
116122
// Allocate something. This will cause G1 to allocate an EDEN region.
117123
// See JDK-8245925
118-
Object o = new Object();
124+
sink = new Object();
119125
System.out.println("cleaning " + i);
120126
}
121127
}

0 commit comments

Comments
 (0)