diff --git a/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java b/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java index 2f38996aa4a..b68ac5985cd 100644 --- a/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java +++ b/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java @@ -28,66 +28,66 @@ public static void main(String[] args) throws InterruptedException { @SuppressWarnings("SystemOut") private void run() throws InterruptedException { System.out.println("Hit return to start"); - // Block until consumer sends the ready signal - Scanner scanner = new Scanner(System.in, UTF_8.name()); - System.out.println(scanner.nextLine()); - - // Allocate 1mb - for (int i = 0; i < 1024; i++) { - memory.add(new MemoryConsumer(CHUNK_SIZE)); - } + try (Scanner scanner = new Scanner(System.in, UTF_8.name())) { + System.out.println(scanner.nextLine()); - // Create 100mb of transient memory, invoking a number of YG gc's and promoting some to OG - for (int i = 0; i < 100 * 1024; i++) { - singleMemory = new MemoryConsumer(CHUNK_SIZE); - } - - // Run full GC - System.gc(); - - // Allocate 30mb, 25% of which is transient - for (int i = 0; i < 30 * 1024; i++) { - if ((i % 4) == 0) { - singleMemory = new MemoryConsumer(CHUNK_SIZE); - } else { + // Allocate 1mb + for (int i = 0; i < 1024; i++) { memory.add(new MemoryConsumer(CHUNK_SIZE)); } - } // Heap at 23.5mb - // Create 100mb of transient memory, invoking a number of YG gc's and promoting 40mb to OG - for (int i = 0; i < 100 * 1024; i++) { - singleMemory = new MemoryConsumer(CHUNK_SIZE); - } - - // free up 10mb - for (int i = 0; i < 10 * 1024; i++) { - memory.remove(0); - } // Heap at 13.5mb - - // Allocate 43mb, 50% of which is transient - for (int i = 0; i < 43 * 1024; i++) { - if ((i % 2) == 0) { + // Create 100mb of transient memory, invoking a number of YG gc's and promoting some to OG + for (int i = 0; i < 100 * 1024; i++) { singleMemory = new MemoryConsumer(CHUNK_SIZE); - } else { - memory.add(new MemoryConsumer(CHUNK_SIZE)); } - } // Heap at 35mb - // free up everything - memory.clear(); + // Run full GC + System.gc(); - // Run full GC - System.gc(); - // free up everything - memory.clear(); - // Run full GC - System.gc(); + // Allocate 30mb, 25% of which is transient + for (int i = 0; i < 30 * 1024; i++) { + if ((i % 4) == 0) { + singleMemory = new MemoryConsumer(CHUNK_SIZE); + } else { + memory.add(new MemoryConsumer(CHUNK_SIZE)); + } + } // Heap at 23.5mb - // Seems if the JVM exits too quickly MX beans do not report, give it some time + // Create 100mb of transient memory, invoking a number of YG gc's and promoting 40mb to OG + for (int i = 0; i < 100 * 1024; i++) { + singleMemory = new MemoryConsumer(CHUNK_SIZE); + } - System.out.println("Hit return to exit"); - System.out.println(scanner.nextLine()); + // free up 10mb + for (int i = 0; i < 10 * 1024; i++) { + memory.remove(0); + } // Heap at 13.5mb + + // Allocate 43mb, 50% of which is transient + for (int i = 0; i < 43 * 1024; i++) { + if ((i % 2) == 0) { + singleMemory = new MemoryConsumer(CHUNK_SIZE); + } else { + memory.add(new MemoryConsumer(CHUNK_SIZE)); + } + } // Heap at 35mb + + // free up everything + memory.clear(); + + // Run full GC + System.gc(); + // free up everything + memory.clear(); + // Run full GC + System.gc(); + + // Seems if the JVM exits too quickly MX beans do not report, give it some time + + System.out.println("Hit return to exit"); + System.out.println(scanner.nextLine()); + } } static class MemoryConsumer {