test/gc/g1/TestGCLogMessages.java

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7893
a5b77ac78ad2
parent 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
tschatzl@7893 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
jmasa@6950 25 * @test TestGCLogMessages
tschatzl@7828 26 * @bug 8035406 8027295 8035398 8019342 8027959 8048179 8027962
aoqi@0 27 * @summary Ensure that the PrintGCDetails output for a minor GC with G1
aoqi@0 28 * includes the expected necessary messages.
aoqi@0 29 * @key gc
aoqi@0 30 * @library /testlibrary
aoqi@0 31 */
aoqi@0 32
aoqi@0 33 import com.oracle.java.testlibrary.ProcessTools;
aoqi@0 34 import com.oracle.java.testlibrary.OutputAnalyzer;
aoqi@0 35
aoqi@0 36 public class TestGCLogMessages {
aoqi@0 37
brutisso@7660 38 private enum Level {
brutisso@7660 39 OFF, FINER, FINEST;
brutisso@7660 40 public boolean lessOrEqualTo(Level other) {
brutisso@7660 41 return this.compareTo(other) < 0;
brutisso@7660 42 }
brutisso@7660 43 }
aoqi@0 44
brutisso@7660 45 private class LogMessageWithLevel {
brutisso@7660 46 String message;
brutisso@7660 47 Level level;
aoqi@0 48
brutisso@7660 49 public LogMessageWithLevel(String message, Level level) {
brutisso@7660 50 this.message = message;
brutisso@7660 51 this.level = level;
brutisso@7660 52 }
brutisso@7660 53 };
aoqi@0 54
brutisso@7660 55 private LogMessageWithLevel allLogMessages[] = new LogMessageWithLevel[] {
brutisso@7660 56 // Ext Root Scan
brutisso@7660 57 new LogMessageWithLevel("Thread Roots (ms)", Level.FINEST),
brutisso@7660 58 new LogMessageWithLevel("StringTable Roots (ms)", Level.FINEST),
brutisso@7660 59 new LogMessageWithLevel("Universe Roots (ms)", Level.FINEST),
brutisso@7660 60 new LogMessageWithLevel("JNI Handles Roots (ms)", Level.FINEST),
brutisso@7660 61 new LogMessageWithLevel("ObjectSynchronizer Roots (ms)", Level.FINEST),
brutisso@7660 62 new LogMessageWithLevel("FlatProfiler Roots", Level.FINEST),
brutisso@7660 63 new LogMessageWithLevel("Management Roots", Level.FINEST),
brutisso@7660 64 new LogMessageWithLevel("SystemDictionary Roots", Level.FINEST),
brutisso@7660 65 new LogMessageWithLevel("CLDG Roots", Level.FINEST),
brutisso@7660 66 new LogMessageWithLevel("JVMTI Roots", Level.FINEST),
brutisso@7660 67 new LogMessageWithLevel("CodeCache Roots", Level.FINEST),
brutisso@7660 68 new LogMessageWithLevel("SATB Filtering", Level.FINEST),
brutisso@7660 69 new LogMessageWithLevel("CM RefProcessor Roots", Level.FINEST),
brutisso@7660 70 new LogMessageWithLevel("Wait For Strong CLD", Level.FINEST),
brutisso@7660 71 new LogMessageWithLevel("Weak CLD Roots", Level.FINEST),
brutisso@7660 72 // Redirty Cards
brutisso@7660 73 new LogMessageWithLevel("Redirty Cards", Level.FINER),
brutisso@7660 74 new LogMessageWithLevel("Parallel Redirty", Level.FINEST),
brutisso@7660 75 new LogMessageWithLevel("Redirtied Cards", Level.FINEST),
brutisso@7660 76 // Misc Top-level
brutisso@7660 77 new LogMessageWithLevel("Code Root Purge", Level.FINER),
brutisso@7660 78 new LogMessageWithLevel("String Dedup Fixup", Level.FINER),
brutisso@7660 79 // Free CSet
brutisso@7660 80 new LogMessageWithLevel("Young Free CSet", Level.FINEST),
brutisso@7660 81 new LogMessageWithLevel("Non-Young Free CSet", Level.FINEST),
brutisso@7660 82 // Humongous Eager Reclaim
brutisso@7660 83 new LogMessageWithLevel("Humongous Reclaim", Level.FINER),
tschatzl@7828 84 new LogMessageWithLevel("Humongous Register", Level.FINER),
brutisso@7660 85 };
aoqi@0 86
brutisso@7660 87 void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
brutisso@7660 88 for (LogMessageWithLevel l : messages) {
brutisso@7660 89 if (level.lessOrEqualTo(l.level)) {
brutisso@7660 90 output.shouldNotContain(l.message);
brutisso@7660 91 } else {
brutisso@7660 92 output.shouldContain(l.message);
brutisso@7660 93 }
brutisso@7660 94 }
brutisso@7660 95 }
aoqi@0 96
brutisso@7660 97 public static void main(String[] args) throws Exception {
brutisso@7660 98 new TestGCLogMessages().testNormalLogs();
brutisso@7660 99 new TestGCLogMessages().testWithToSpaceExhaustionLogs();
brutisso@7660 100 }
aoqi@0 101
brutisso@7660 102 private void testNormalLogs() throws Exception {
aoqi@0 103
brutisso@7660 104 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
brutisso@7660 105 "-Xmx10M",
brutisso@7660 106 GCTest.class.getName());
aoqi@0 107
brutisso@7660 108 OutputAnalyzer output = new OutputAnalyzer(pb.start());
brutisso@7660 109 checkMessagesAtLevel(output, allLogMessages, Level.OFF);
brutisso@7660 110 output.shouldHaveExitValue(0);
aoqi@0 111
brutisso@7660 112 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
brutisso@7660 113 "-XX:+UseStringDeduplication",
brutisso@7660 114 "-Xmx10M",
brutisso@7660 115 "-XX:+PrintGCDetails",
brutisso@7660 116 GCTest.class.getName());
aoqi@0 117
brutisso@7660 118 output = new OutputAnalyzer(pb.start());
brutisso@7660 119 checkMessagesAtLevel(output, allLogMessages, Level.FINER);
aoqi@0 120
brutisso@7660 121 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
brutisso@7660 122 "-XX:+UseStringDeduplication",
brutisso@7660 123 "-Xmx10M",
brutisso@7660 124 "-XX:+PrintGCDetails",
brutisso@7660 125 "-XX:+UnlockExperimentalVMOptions",
brutisso@7660 126 "-XX:G1LogLevel=finest",
brutisso@7660 127 GCTest.class.getName());
aoqi@0 128
brutisso@7660 129 output = new OutputAnalyzer(pb.start());
brutisso@7660 130 checkMessagesAtLevel(output, allLogMessages, Level.FINEST);
brutisso@7660 131 output.shouldHaveExitValue(0);
brutisso@7660 132 }
aoqi@0 133
brutisso@7660 134 LogMessageWithLevel exhFailureMessages[] = new LogMessageWithLevel[] {
brutisso@7660 135 new LogMessageWithLevel("Evacuation Failure", Level.FINER),
brutisso@7660 136 new LogMessageWithLevel("Recalculate Used", Level.FINEST),
brutisso@7660 137 new LogMessageWithLevel("Remove Self Forwards", Level.FINEST),
brutisso@7660 138 new LogMessageWithLevel("Restore RemSet", Level.FINEST),
brutisso@7660 139 };
aoqi@0 140
brutisso@7660 141 private void testWithToSpaceExhaustionLogs() throws Exception {
brutisso@7660 142 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
brutisso@7660 143 "-Xmx32M",
brutisso@7660 144 "-Xmn16M",
brutisso@7660 145 "-XX:+PrintGCDetails",
brutisso@7660 146 GCTestWithToSpaceExhaustion.class.getName());
brutisso@7660 147
brutisso@7660 148 OutputAnalyzer output = new OutputAnalyzer(pb.start());
brutisso@7660 149 checkMessagesAtLevel(output, exhFailureMessages, Level.FINER);
brutisso@7660 150 output.shouldHaveExitValue(0);
brutisso@7660 151
brutisso@7660 152 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
brutisso@7660 153 "-Xmx32M",
brutisso@7660 154 "-Xmn16M",
brutisso@7660 155 "-XX:+PrintGCDetails",
brutisso@7660 156 "-XX:+UnlockExperimentalVMOptions",
brutisso@7660 157 "-XX:G1LogLevel=finest",
brutisso@7660 158 GCTestWithToSpaceExhaustion.class.getName());
brutisso@7660 159
brutisso@7660 160 output = new OutputAnalyzer(pb.start());
brutisso@7660 161 checkMessagesAtLevel(output, exhFailureMessages, Level.FINEST);
brutisso@7660 162 output.shouldHaveExitValue(0);
aoqi@0 163 }
aoqi@0 164
brutisso@7660 165 static class GCTest {
brutisso@7660 166 private static byte[] garbage;
brutisso@7660 167 public static void main(String [] args) {
brutisso@7660 168 System.out.println("Creating garbage");
brutisso@7660 169 // create 128MB of garbage. This should result in at least one GC
brutisso@7660 170 for (int i = 0; i < 1024; i++) {
brutisso@7660 171 garbage = new byte[128 * 1024];
brutisso@7660 172 }
brutisso@7660 173 System.out.println("Done");
brutisso@7660 174 }
aoqi@0 175 }
brutisso@7660 176
brutisso@7660 177 static class GCTestWithToSpaceExhaustion {
brutisso@7660 178 private static byte[] garbage;
brutisso@7660 179 private static byte[] largeObject;
brutisso@7660 180 public static void main(String [] args) {
brutisso@7660 181 largeObject = new byte[16*1024*1024];
brutisso@7660 182 System.out.println("Creating garbage");
brutisso@7660 183 // create 128MB of garbage. This should result in at least one GC,
brutisso@7660 184 // some of them with to-space exhaustion.
brutisso@7660 185 for (int i = 0; i < 1024; i++) {
brutisso@7660 186 garbage = new byte[128 * 1024];
brutisso@7660 187 }
brutisso@7660 188 System.out.println("Done");
brutisso@7660 189 }
brutisso@7660 190 }
aoqi@0 191 }
brutisso@7660 192

mercurial