159 Asserts.assertTrue(getWhiteBox().isObjectInOldGen(toUnreachable), "List of the objects is suppose to be in OldGen");
160 }
161
162 private static void waitTillCMCFinished(int sleepTime) {
163 while (getWhiteBox().g1InConcurrentMark()) {
164 try {sleep(sleepTime);} catch (Exception e) {}
165 }
166 }
167
168 /**
169 * The necessary condition for guaranteed mixed GC is running in VM with the following flags:
170 * -XX:+UnlockExperimentalVMOptions -XX:+AlwaysTenure -Xms{HEAP_SIZE}M
171 * -Xmx{HEAP_SIZE}M -XX:G1MixedGCLiveThresholdPercent=100 -XX:G1HeapWastePercent=0
172 * -XX:G1HeapRegionSize={REGION_SIZE}m
173 *
174 * @param g1HeapRegionSize The size of your regions in bytes
175 */
176 public static void provokeMixedGC(int g1HeapRegionSize) {
177 final var arraySize = 20_000;
178 var liveOldObjects = new ArrayList<byte[]>();
179 allocateOldObjects(liveOldObjects, g1HeapRegionSize, arraySize);
180 waitTillCMCFinished(10);
181 getWhiteBox().g1StartConcMarkCycle();
182 waitTillCMCFinished(10);
183 getWhiteBox().youngGC();
184 getWhiteBox().youngGC();
185
186 // check that liveOldObjects still alive
187 assertTrue(getWhiteBox().isObjectInOldGen(liveOldObjects), "List of the objects is suppose to be in OldGen");
188 }
189 }
|
159 Asserts.assertTrue(getWhiteBox().isObjectInOldGen(toUnreachable), "List of the objects is suppose to be in OldGen");
160 }
161
162 private static void waitTillCMCFinished(int sleepTime) {
163 while (getWhiteBox().g1InConcurrentMark()) {
164 try {sleep(sleepTime);} catch (Exception e) {}
165 }
166 }
167
168 /**
169 * The necessary condition for guaranteed mixed GC is running in VM with the following flags:
170 * -XX:+UnlockExperimentalVMOptions -XX:+AlwaysTenure -Xms{HEAP_SIZE}M
171 * -Xmx{HEAP_SIZE}M -XX:G1MixedGCLiveThresholdPercent=100 -XX:G1HeapWastePercent=0
172 * -XX:G1HeapRegionSize={REGION_SIZE}m
173 *
174 * @param g1HeapRegionSize The size of your regions in bytes
175 */
176 public static void provokeMixedGC(int g1HeapRegionSize) {
177 final var arraySize = 20_000;
178 var liveOldObjects = new ArrayList<byte[]>();
179
180 // Make sure the heap is in a known state.
181 getWhiteBox().fullGC();
182 allocateOldObjects(liveOldObjects, g1HeapRegionSize, arraySize);
183 waitTillCMCFinished(10);
184 getWhiteBox().g1StartConcMarkCycle();
185 waitTillCMCFinished(10);
186 getWhiteBox().youngGC();
187 getWhiteBox().youngGC();
188
189 // check that liveOldObjects still alive
190 assertTrue(getWhiteBox().isObjectInOldGen(liveOldObjects), "List of the objects is suppose to be in OldGen");
191 }
192 }
|