1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test TestPrintGCDetails 26 * @bug 8035406 8027295 8035398 27 * @summary Ensure that the PrintGCDetails output for a minor GC with G1 28 * includes the expected necessary messages. 29 * @key gc 30 * @library /testlibrary 31 */ 32 33 import com.oracle.java.testlibrary.ProcessTools; 34 import com.oracle.java.testlibrary.OutputAnalyzer; 35 36 public class TestGCLogMessages { 37 public static void main(String[] args) throws Exception { 38 testNormalLogs(); 39 testWithToSpaceExhaustionLogs(); 40 } 41 42 private static void testNormalLogs() throws Exception { 43 44 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 45 "-Xmx10M", 46 GCTest.class.getName()); 47 48 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 49 50 output.shouldNotContain("[Redirty Cards"); 51 output.shouldNotContain("[Code Root Purge"); 52 output.shouldNotContain("[Young Free CSet"); 53 output.shouldNotContain("[Non-Young Free CSet"); 54 output.shouldHaveExitValue(0); 55 56 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 57 "-Xmx10M", 58 "-XX:+PrintGCDetails", 59 GCTest.class.getName()); 60 61 output = new OutputAnalyzer(pb.start()); 62 63 output.shouldContain("[Redirty Cards"); 64 output.shouldContain("[Code Root Purge"); 65 output.shouldNotContain("[Young Free CSet"); 66 output.shouldNotContain("[Non-Young Free CSet"); 67 output.shouldHaveExitValue(0); 68 69 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 70 "-Xmx10M", 71 "-XX:+PrintGCDetails", 72 "-XX:+UnlockExperimentalVMOptions", 73 "-XX:G1LogLevel=finest", 74 GCTest.class.getName()); 75 76 output = new OutputAnalyzer(pb.start()); 77 78 output.shouldContain("[Redirty Cards"); 79 output.shouldContain("[Code Root Purge"); 80 output.shouldContain("[Young Free CSet"); 81 output.shouldContain("[Non-Young Free CSet"); 82 83 // also check evacuation failure messages once 84 output.shouldNotContain("[Evacuation Failure"); 85 output.shouldNotContain("[Recalculate Used"); 86 output.shouldNotContain("[Remove Self Forwards"); 87 output.shouldNotContain("[Restore RemSet"); 88 output.shouldHaveExitValue(0); 89 } 90 91 private static void testWithToSpaceExhaustionLogs() throws Exception { 92 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 93 "-Xmx10M", 94 "-Xmn5M", 95 "-XX:+PrintGCDetails", 96 GCTestWithToSpaceExhaustion.class.getName()); 97 98 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 99 output.shouldContain("[Evacuation Failure"); 100 output.shouldNotContain("[Recalculate Used"); 101 output.shouldNotContain("[Remove Self Forwards"); 102 output.shouldNotContain("[Restore RemSet"); 103 output.shouldHaveExitValue(0); 104 105 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 106 "-Xmx10M", 107 "-Xmn5M", 108 "-XX:+PrintGCDetails", 109 "-XX:+UnlockExperimentalVMOptions", 110 "-XX:G1LogLevel=finest", 111 GCTestWithToSpaceExhaustion.class.getName()); 112 113 output = new OutputAnalyzer(pb.start()); 114 output.shouldContain("[Evacuation Failure"); 115 output.shouldContain("[Recalculate Used"); 116 output.shouldContain("[Remove Self Forwards"); 117 output.shouldContain("[Restore RemSet"); 118 output.shouldHaveExitValue(0); 119 } 120 121 static class GCTest { 122 private static byte[] garbage; 123 public static void main(String [] args) { 124 System.out.println("Creating garbage"); 125 // create 128MB of garbage. This should result in at least one GC 126 for (int i = 0; i < 1024; i++) { 127 garbage = new byte[128 * 1024]; 128 } 129 System.out.println("Done"); 130 } 131 } 132 133 static class GCTestWithToSpaceExhaustion { 134 private static byte[] garbage; 135 private static byte[] largeObject; 136 public static void main(String [] args) { 137 largeObject = new byte[5*1024*1024]; 138 System.out.println("Creating garbage"); 139 // create 128MB of garbage. This should result in at least one GC, 140 // some of them with to-space exhaustion. 141 for (int i = 0; i < 1024; i++) { 142 garbage = new byte[128 * 1024]; 143 } 144 System.out.println("Done"); 145 } 146 } 147 }