@@ -34,7 +34,10 @@ public class GCDuringDumpTransformer implements ClassFileTransformer {
34
34
static boolean TEST_WITH_CLEANER = Boolean .getBoolean ("test.with.cleaner" );
35
35
static boolean TEST_WITH_EXCEPTION = Boolean .getBoolean ("test.with.exception" );
36
36
static boolean TEST_WITH_OOM = Boolean .getBoolean ("test.with.oom" );
37
+
38
+ static final int WASTE_SIZE = 1024 ;
37
39
static List <byte []> waste = new ArrayList ();
40
+ static Object sink ;
38
41
39
42
static Cleaner cleaner ;
40
43
static Thread thread ;
@@ -59,10 +62,13 @@ public byte[] transform(ClassLoader loader, String name, Class<?> classBeingRede
59
62
return new byte [] {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
60
63
}
61
64
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.
63
69
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 ]);
66
72
}
67
73
}
68
74
}
@@ -104,8 +110,8 @@ public static void agentmain(String args, Instrumentation inst) throws Exception
104
110
}
105
111
106
112
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 ];
109
115
}
110
116
}
111
117
@@ -115,7 +121,7 @@ static class MyCleaner implements Runnable {
115
121
public void run () {
116
122
// Allocate something. This will cause G1 to allocate an EDEN region.
117
123
// See JDK-8245925
118
- Object o = new Object ();
124
+ sink = new Object ();
119
125
System .out .println ("cleaning " + i );
120
126
}
121
127
}
0 commit comments