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 TestGCLogMessages 26 * @bug 8035406 8027295 8035398 8019342 8027959 8048179 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 * @build com.oracle.java.testlibrary.* 32 * @run main/othervm TestGCLogMessages 33 */ 34 35 import com.oracle.java.testlibrary.ProcessTools; 36 import com.oracle.java.testlibrary.OutputAnalyzer; 37 38 public class TestGCLogMessages { 39 public static void main(String[] args) throws Exception { 40 testNormalLogs(); 41 testWithToSpaceExhaustionLogs(); 42 } 43 44 private static void testNormalLogs() throws Exception { 45 46 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 47 "-Xmx10M", 48 GCTest.class.getName()); 49 50 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 51 52 output.shouldNotContain("[Redirty Cards"); 53 output.shouldNotContain("[Parallel Redirty"); 54 output.shouldNotContain("[Redirtied Cards"); 55 output.shouldNotContain("[Code Root Purge"); 56 output.shouldNotContain("[String Dedup Fixup"); 57 output.shouldNotContain("[Young Free CSet"); 58 output.shouldNotContain("[Non-Young Free CSet"); 59 output.shouldNotContain("[Humongous Register"); 60 output.shouldNotContain("[Humongous Reclaim"); 61 output.shouldHaveExitValue(0); 62 63 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 64 "-XX:+UseStringDeduplication", 65 "-Xmx10M", 66 "-XX:+PrintGCDetails", 67 GCTest.class.getName()); 68 69 output = new OutputAnalyzer(pb.start()); 70 71 output.shouldContain("[Redirty Cards"); 72 output.shouldNotContain("[Parallel Redirty"); 73 output.shouldNotContain("[Redirtied Cards"); 74 output.shouldContain("[Code Root Purge"); 75 output.shouldContain("[String Dedup Fixup"); 76 output.shouldNotContain("[Young Free CSet"); 77 output.shouldNotContain("[Non-Young Free CSet"); 78 output.shouldContain("[Humongous Register"); 79 output.shouldNotContain("[Humongous Total"); 80 output.shouldNotContain("[Humongous Candidate"); 81 output.shouldContain("[Humongous Reclaim"); 82 output.shouldNotContain("[Humongous Reclaimed"); 83 output.shouldHaveExitValue(0); 84 85 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 86 "-XX:+UseStringDeduplication", 87 "-Xmx10M", 88 "-XX:+PrintGCDetails", 89 "-XX:+UnlockExperimentalVMOptions", 90 "-XX:G1LogLevel=finest", 91 GCTest.class.getName()); 92 93 output = new OutputAnalyzer(pb.start()); 94 95 output.shouldContain("[Redirty Cards"); 96 output.shouldContain("[Parallel Redirty"); 97 output.shouldContain("[Redirtied Cards"); 98 output.shouldContain("[Code Root Purge"); 99 output.shouldContain("[String Dedup Fixup"); 100 output.shouldContain("[Young Free CSet"); 101 output.shouldContain("[Non-Young Free CSet"); 102 output.shouldContain("[Humongous Register"); 103 output.shouldContain("[Humongous Total"); 104 output.shouldContain("[Humongous Candidate"); 105 output.shouldContain("[Humongous Reclaim"); 106 output.shouldContain("[Humongous Reclaimed"); 107 output.shouldHaveExitValue(0); 108 } 109 110 private static void testWithToSpaceExhaustionLogs() throws Exception { 111 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 112 "-Xmx32M", 113 "-Xmn16M", 114 "-XX:+PrintGCDetails", 115 GCTestWithToSpaceExhaustion.class.getName()); 116 117 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 118 output.shouldContain("[Evacuation Failure"); 119 output.shouldNotContain("[Recalculate Used"); 120 output.shouldNotContain("[Remove Self Forwards"); 121 output.shouldNotContain("[Restore RemSet"); 122 output.shouldHaveExitValue(0); 123 124 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 125 "-Xmx32M", 126 "-Xmn16M", 127 "-XX:+PrintGCDetails", 128 "-XX:+UnlockExperimentalVMOptions", 129 "-XX:G1LogLevel=finest", 130 GCTestWithToSpaceExhaustion.class.getName()); 131 132 output = new OutputAnalyzer(pb.start()); 133 output.shouldContain("[Evacuation Failure"); 134 output.shouldContain("[Recalculate Used"); 135 output.shouldContain("[Remove Self Forwards"); 136 output.shouldContain("[Restore RemSet"); 137 output.shouldHaveExitValue(0); 138 } 139 140 static class GCTest { 141 private static byte[] garbage; 142 public static void main(String [] args) { 143 System.out.println("Creating garbage"); 144 // create 128MB of garbage. This should result in at least one GC 145 for (int i = 0; i < 1024; i++) { 146 garbage = new byte[128 * 1024]; 147 } 148 System.out.println("Done"); 149 } 150 } 151 152 static class GCTestWithToSpaceExhaustion { 153 private static byte[] garbage; 154 private static byte[] largeObject; 155 public static void main(String [] args) { 156 largeObject = new byte[16*1024*1024]; 157 System.out.println("Creating garbage"); 158 // create 128MB of garbage. This should result in at least one GC, 159 // some of them with to-space exhaustion. 160 for (int i = 0; i < 1024; i++) { 161 garbage = new byte[128 * 1024]; 162 } 163 System.out.println("Done"); 164 } 165 } 166 }