1 /* |
1 /* |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
36 import jdk.test.lib.OutputAnalyzer; |
36 import jdk.test.lib.OutputAnalyzer; |
37 import java.util.LinkedList; |
37 import java.util.LinkedList; |
38 |
38 |
39 public class TestG1TraceEagerReclaimHumongousObjects { |
39 public class TestG1TraceEagerReclaimHumongousObjects { |
40 public static void main(String[] args) throws Exception { |
40 public static void main(String[] args) throws Exception { |
41 testGCLogs(); |
|
42 testHumongousObjectGCLogs(); |
|
43 } |
|
44 |
|
45 private static void testGCLogs() throws Exception { |
|
46 |
|
47 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", |
|
48 "-Xms128M", |
|
49 "-Xmx128M", |
|
50 "-Xmn16M", |
|
51 "-XX:G1HeapRegionSize=1M", |
|
52 "-Xlog:gc+phases=trace", |
|
53 "-XX:+UnlockExperimentalVMOptions", |
|
54 GCTest.class.getName()); |
|
55 |
|
56 OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
57 |
|
58 // As G1EagerReclaimHumongousObjects is set(default), below logs should be displayed. |
|
59 // And GCTest doesn't have humongous objects, so values should be zero. |
|
60 output.shouldContain("Humongous Reclaim"); |
|
61 output.shouldContain("Humongous Total: 0"); |
|
62 output.shouldContain("Humongous Candidate: 0"); |
|
63 output.shouldContain("Humongous Reclaimed: 0"); |
|
64 |
|
65 output.shouldHaveExitValue(0); |
|
66 } |
|
67 |
|
68 private static void testHumongousObjectGCLogs() throws Exception { |
|
69 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", |
41 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", |
70 "-Xms128M", |
42 "-Xms128M", |
71 "-Xmx128M", |
43 "-Xmx128M", |
72 "-Xmn16M", |
44 "-Xmn16M", |
73 "-XX:G1HeapRegionSize=1M", |
45 "-XX:G1HeapRegionSize=1M", |
86 // As G1TraceReclaimDeadHumongousObjectsAtYoungGC is set and GCWithHumongousObjectTest has humongous objects, |
58 // As G1TraceReclaimDeadHumongousObjectsAtYoungGC is set and GCWithHumongousObjectTest has humongous objects, |
87 // these logs should be displayed. |
59 // these logs should be displayed. |
88 output.shouldContain("Live humongous"); |
60 output.shouldContain("Live humongous"); |
89 output.shouldContain("Dead humongous region"); |
61 output.shouldContain("Dead humongous region"); |
90 output.shouldHaveExitValue(0); |
62 output.shouldHaveExitValue(0); |
91 } |
|
92 |
|
93 static class GCTest { |
|
94 private static byte[] garbage; |
|
95 |
|
96 public static void main(String [] args) { |
|
97 System.out.println("Creating garbage"); |
|
98 // create 128MB of garbage. This should result in at least one GC |
|
99 for (int i = 0; i < 1024; i++) { |
|
100 garbage = new byte[128 * 1024]; |
|
101 } |
|
102 System.out.println("Done"); |
|
103 } |
|
104 } |
63 } |
105 |
64 |
106 static class GCWithHumongousObjectTest { |
65 static class GCWithHumongousObjectTest { |
107 |
66 |
108 public static final int M = 1024*1024; |
67 public static final int M = 1024*1024; |