tschatzl@6402: /* tschatzl@6402: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. tschatzl@6402: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. tschatzl@6402: * tschatzl@6402: * This code is free software; you can redistribute it and/or modify it tschatzl@6402: * under the terms of the GNU General Public License version 2 only, as tschatzl@6402: * published by the Free Software Foundation. tschatzl@6402: * tschatzl@6402: * This code is distributed in the hope that it will be useful, but WITHOUT tschatzl@6402: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or tschatzl@6402: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License tschatzl@6402: * version 2 for more details (a copy is included in the LICENSE file that tschatzl@6402: * accompanied this code). tschatzl@6402: * tschatzl@6402: * You should have received a copy of the GNU General Public License version tschatzl@6402: * 2 along with this work; if not, write to the Free Software Foundation, tschatzl@6402: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. tschatzl@6402: * tschatzl@6402: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA tschatzl@6402: * or visit www.oracle.com if you need additional information or have any tschatzl@6402: * questions. tschatzl@6402: */ tschatzl@6402: tschatzl@6402: /* tschatzl@6402: * @test TestPrintGCDetails tschatzl@6405: * @bug 8035406 8027295 8035398 tschatzl@6402: * @summary Ensure that the PrintGCDetails output for a minor GC with G1 tschatzl@6402: * includes the expected necessary messages. tschatzl@6402: * @key gc tschatzl@6402: * @library /testlibrary tschatzl@6402: */ tschatzl@6402: tschatzl@6402: import com.oracle.java.testlibrary.ProcessTools; tschatzl@6402: import com.oracle.java.testlibrary.OutputAnalyzer; tschatzl@6402: tschatzl@6402: public class TestGCLogMessages { tschatzl@6402: public static void main(String[] args) throws Exception { tschatzl@6406: testNormalLogs(); tschatzl@6406: testWithToSpaceExhaustionLogs(); tschatzl@6406: } tschatzl@6406: tschatzl@6406: private static void testNormalLogs() throws Exception { tschatzl@6402: tschatzl@6402: ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", tschatzl@6402: "-Xmx10M", tschatzl@6402: GCTest.class.getName()); tschatzl@6402: tschatzl@6402: OutputAnalyzer output = new OutputAnalyzer(pb.start()); tschatzl@6402: tschatzl@6405: output.shouldNotContain("[Redirty Cards"); tschatzl@6404: output.shouldNotContain("[Code Root Purge"); pliden@6413: output.shouldNotContain("[String Dedup Fixup"); tschatzl@6404: output.shouldNotContain("[Young Free CSet"); tschatzl@6404: output.shouldNotContain("[Non-Young Free CSet"); tschatzl@6404: output.shouldHaveExitValue(0); tschatzl@6404: tschatzl@6404: pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", pliden@6413: "-XX:+UseStringDeduplication", tschatzl@6404: "-Xmx10M", tschatzl@6404: "-XX:+PrintGCDetails", tschatzl@6404: GCTest.class.getName()); tschatzl@6404: tschatzl@6404: output = new OutputAnalyzer(pb.start()); tschatzl@6404: tschatzl@6405: output.shouldContain("[Redirty Cards"); tschatzl@6402: output.shouldContain("[Code Root Purge"); pliden@6413: output.shouldContain("[String Dedup Fixup"); tschatzl@6404: output.shouldNotContain("[Young Free CSet"); tschatzl@6404: output.shouldNotContain("[Non-Young Free CSet"); tschatzl@6402: output.shouldHaveExitValue(0); tschatzl@6404: tschatzl@6404: pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", pliden@6413: "-XX:+UseStringDeduplication", tschatzl@6404: "-Xmx10M", tschatzl@6404: "-XX:+PrintGCDetails", tschatzl@6404: "-XX:+UnlockExperimentalVMOptions", tschatzl@6404: "-XX:G1LogLevel=finest", tschatzl@6404: GCTest.class.getName()); tschatzl@6404: tschatzl@6404: output = new OutputAnalyzer(pb.start()); tschatzl@6404: tschatzl@6405: output.shouldContain("[Redirty Cards"); tschatzl@6404: output.shouldContain("[Code Root Purge"); pliden@6413: output.shouldContain("[String Dedup Fixup"); tschatzl@6404: output.shouldContain("[Young Free CSet"); tschatzl@6404: output.shouldContain("[Non-Young Free CSet"); tschatzl@6406: tschatzl@6406: // also check evacuation failure messages once tschatzl@6406: output.shouldNotContain("[Evacuation Failure"); tschatzl@6406: output.shouldNotContain("[Recalculate Used"); tschatzl@6406: output.shouldNotContain("[Remove Self Forwards"); tschatzl@6406: output.shouldNotContain("[Restore RemSet"); tschatzl@6406: output.shouldHaveExitValue(0); tschatzl@6406: } tschatzl@6406: tschatzl@6406: private static void testWithToSpaceExhaustionLogs() throws Exception { tschatzl@6406: ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", tschatzl@6406: "-Xmx10M", tschatzl@6406: "-Xmn5M", tschatzl@6406: "-XX:+PrintGCDetails", tschatzl@6406: GCTestWithToSpaceExhaustion.class.getName()); tschatzl@6406: tschatzl@6406: OutputAnalyzer output = new OutputAnalyzer(pb.start()); tschatzl@6406: output.shouldContain("[Evacuation Failure"); tschatzl@6406: output.shouldNotContain("[Recalculate Used"); tschatzl@6406: output.shouldNotContain("[Remove Self Forwards"); tschatzl@6406: output.shouldNotContain("[Restore RemSet"); tschatzl@6404: output.shouldHaveExitValue(0); tschatzl@6404: tschatzl@6406: pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", tschatzl@6406: "-Xmx10M", tschatzl@6406: "-Xmn5M", tschatzl@6406: "-XX:+PrintGCDetails", tschatzl@6406: "-XX:+UnlockExperimentalVMOptions", tschatzl@6406: "-XX:G1LogLevel=finest", tschatzl@6406: GCTestWithToSpaceExhaustion.class.getName()); tschatzl@6406: tschatzl@6406: output = new OutputAnalyzer(pb.start()); tschatzl@6406: output.shouldContain("[Evacuation Failure"); tschatzl@6406: output.shouldContain("[Recalculate Used"); tschatzl@6406: output.shouldContain("[Remove Self Forwards"); tschatzl@6406: output.shouldContain("[Restore RemSet"); tschatzl@6406: output.shouldHaveExitValue(0); tschatzl@6402: } tschatzl@6402: tschatzl@6402: static class GCTest { tschatzl@6402: private static byte[] garbage; tschatzl@6402: public static void main(String [] args) { tschatzl@6402: System.out.println("Creating garbage"); tschatzl@6402: // create 128MB of garbage. This should result in at least one GC tschatzl@6402: for (int i = 0; i < 1024; i++) { tschatzl@6402: garbage = new byte[128 * 1024]; tschatzl@6402: } tschatzl@6402: System.out.println("Done"); tschatzl@6402: } tschatzl@6402: } tschatzl@6406: tschatzl@6406: static class GCTestWithToSpaceExhaustion { tschatzl@6406: private static byte[] garbage; tschatzl@6406: private static byte[] largeObject; tschatzl@6406: public static void main(String [] args) { tschatzl@6406: largeObject = new byte[5*1024*1024]; tschatzl@6406: System.out.println("Creating garbage"); tschatzl@6406: // create 128MB of garbage. This should result in at least one GC, tschatzl@6406: // some of them with to-space exhaustion. tschatzl@6406: for (int i = 0; i < 1024; i++) { tschatzl@6406: garbage = new byte[128 * 1024]; tschatzl@6406: } tschatzl@6406: System.out.println("Done"); tschatzl@6406: } tschatzl@6406: } tschatzl@6402: }