test/gc/g1/TestGCLogMessages.java

changeset 7660
3ca53859c3c7
parent 7010
a3953c777565
child 7828
cbc7c4c9e11c
     1.1 --- a/test/gc/g1/TestGCLogMessages.java	Mon Dec 01 15:24:56 2014 +0100
     1.2 +++ b/test/gc/g1/TestGCLogMessages.java	Thu Mar 19 15:25:54 2015 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2014, 2015 Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -23,7 +23,7 @@
    1.11  
    1.12  /*
    1.13   * @test TestGCLogMessages
    1.14 - * @bug 8035406 8027295 8035398 8019342 8027959
    1.15 + * @bug 8035406 8027295 8035398 8019342 8027959 8027962
    1.16   * @summary Ensure that the PrintGCDetails output for a minor GC with G1
    1.17   * includes the expected necessary messages.
    1.18   * @key gc
    1.19 @@ -34,128 +34,158 @@
    1.20  import com.oracle.java.testlibrary.OutputAnalyzer;
    1.21  
    1.22  public class TestGCLogMessages {
    1.23 -  public static void main(String[] args) throws Exception {
    1.24 -    testNormalLogs();
    1.25 -    testWithToSpaceExhaustionLogs();
    1.26 -  }
    1.27  
    1.28 -  private static void testNormalLogs() throws Exception {
    1.29 +    private enum Level {
    1.30 +        OFF, FINER, FINEST;
    1.31 +        public boolean lessOrEqualTo(Level other) {
    1.32 +            return this.compareTo(other) < 0;
    1.33 +        }
    1.34 +    }
    1.35  
    1.36 -    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
    1.37 -                                                              "-Xmx10M",
    1.38 -                                                              GCTest.class.getName());
    1.39 +    private class LogMessageWithLevel {
    1.40 +        String message;
    1.41 +        Level level;
    1.42  
    1.43 -    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    1.44 +        public LogMessageWithLevel(String message, Level level) {
    1.45 +            this.message = message;
    1.46 +            this.level = level;
    1.47 +        }
    1.48 +    };
    1.49  
    1.50 -    output.shouldNotContain("[Redirty Cards");
    1.51 -    output.shouldNotContain("[Parallel Redirty");
    1.52 -    output.shouldNotContain("[Redirtied Cards");
    1.53 -    output.shouldNotContain("[Code Root Purge");
    1.54 -    output.shouldNotContain("[String Dedup Fixup");
    1.55 -    output.shouldNotContain("[Young Free CSet");
    1.56 -    output.shouldNotContain("[Non-Young Free CSet");
    1.57 -    output.shouldNotContain("[Humongous Reclaim");
    1.58 -    output.shouldHaveExitValue(0);
    1.59 +    private LogMessageWithLevel allLogMessages[] = new LogMessageWithLevel[] {
    1.60 +        // Ext Root Scan
    1.61 +        new LogMessageWithLevel("Thread Roots (ms)", Level.FINEST),
    1.62 +        new LogMessageWithLevel("StringTable Roots (ms)", Level.FINEST),
    1.63 +        new LogMessageWithLevel("Universe Roots (ms)", Level.FINEST),
    1.64 +        new LogMessageWithLevel("JNI Handles Roots (ms)", Level.FINEST),
    1.65 +        new LogMessageWithLevel("ObjectSynchronizer Roots (ms)", Level.FINEST),
    1.66 +        new LogMessageWithLevel("FlatProfiler Roots", Level.FINEST),
    1.67 +        new LogMessageWithLevel("Management Roots", Level.FINEST),
    1.68 +        new LogMessageWithLevel("SystemDictionary Roots", Level.FINEST),
    1.69 +        new LogMessageWithLevel("CLDG Roots", Level.FINEST),
    1.70 +        new LogMessageWithLevel("JVMTI Roots", Level.FINEST),
    1.71 +        new LogMessageWithLevel("CodeCache Roots", Level.FINEST),
    1.72 +        new LogMessageWithLevel("SATB Filtering", Level.FINEST),
    1.73 +        new LogMessageWithLevel("CM RefProcessor Roots", Level.FINEST),
    1.74 +        new LogMessageWithLevel("Wait For Strong CLD", Level.FINEST),
    1.75 +        new LogMessageWithLevel("Weak CLD Roots", Level.FINEST),
    1.76 +        // Redirty Cards
    1.77 +        new LogMessageWithLevel("Redirty Cards", Level.FINER),
    1.78 +        new LogMessageWithLevel("Parallel Redirty", Level.FINEST),
    1.79 +        new LogMessageWithLevel("Redirtied Cards", Level.FINEST),
    1.80 +        // Misc Top-level
    1.81 +        new LogMessageWithLevel("Code Root Purge", Level.FINER),
    1.82 +        new LogMessageWithLevel("String Dedup Fixup", Level.FINER),
    1.83 +        // Free CSet
    1.84 +        new LogMessageWithLevel("Young Free CSet", Level.FINEST),
    1.85 +        new LogMessageWithLevel("Non-Young Free CSet", Level.FINEST),
    1.86 +        // Humongous Eager Reclaim
    1.87 +        new LogMessageWithLevel("Humongous Reclaim", Level.FINER),
    1.88 +    };
    1.89  
    1.90 -    pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
    1.91 -                                               "-XX:+UseStringDeduplication",
    1.92 -                                               "-Xmx10M",
    1.93 -                                               "-XX:+PrintGCDetails",
    1.94 -                                               GCTest.class.getName());
    1.95 +    void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
    1.96 +        for (LogMessageWithLevel l : messages) {
    1.97 +            if (level.lessOrEqualTo(l.level)) {
    1.98 +                output.shouldNotContain(l.message);
    1.99 +            } else {
   1.100 +                output.shouldContain(l.message);
   1.101 +            }
   1.102 +        }
   1.103 +    }
   1.104  
   1.105 -    output = new OutputAnalyzer(pb.start());
   1.106 +    public static void main(String[] args) throws Exception {
   1.107 +        new TestGCLogMessages().testNormalLogs();
   1.108 +        new TestGCLogMessages().testWithToSpaceExhaustionLogs();
   1.109 +    }
   1.110  
   1.111 -    output.shouldContain("[Redirty Cards");
   1.112 -    output.shouldNotContain("[Parallel Redirty");
   1.113 -    output.shouldNotContain("[Redirtied Cards");
   1.114 -    output.shouldContain("[Code Root Purge");
   1.115 -    output.shouldContain("[String Dedup Fixup");
   1.116 -    output.shouldNotContain("[Young Free CSet");
   1.117 -    output.shouldNotContain("[Non-Young Free CSet");
   1.118 -    output.shouldContain("[Humongous Reclaim");
   1.119 -    output.shouldNotContain("[Humongous Total");
   1.120 -    output.shouldNotContain("[Humongous Candidate");
   1.121 -    output.shouldNotContain("[Humongous Reclaimed");
   1.122 -    output.shouldHaveExitValue(0);
   1.123 +    private void testNormalLogs() throws Exception {
   1.124  
   1.125 -    pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
   1.126 -                                               "-XX:+UseStringDeduplication",
   1.127 -                                               "-Xmx10M",
   1.128 -                                               "-XX:+PrintGCDetails",
   1.129 -                                               "-XX:+UnlockExperimentalVMOptions",
   1.130 -                                               "-XX:G1LogLevel=finest",
   1.131 -                                               GCTest.class.getName());
   1.132 +        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
   1.133 +                                                                  "-Xmx10M",
   1.134 +                                                                  GCTest.class.getName());
   1.135  
   1.136 -    output = new OutputAnalyzer(pb.start());
   1.137 +        OutputAnalyzer output = new OutputAnalyzer(pb.start());
   1.138 +        checkMessagesAtLevel(output, allLogMessages, Level.OFF);
   1.139 +        output.shouldHaveExitValue(0);
   1.140  
   1.141 -    output.shouldContain("[Redirty Cards");
   1.142 -    output.shouldContain("[Parallel Redirty");
   1.143 -    output.shouldContain("[Redirtied Cards");
   1.144 -    output.shouldContain("[Code Root Purge");
   1.145 -    output.shouldContain("[String Dedup Fixup");
   1.146 -    output.shouldContain("[Young Free CSet");
   1.147 -    output.shouldContain("[Non-Young Free CSet");
   1.148 -    output.shouldContain("[Humongous Reclaim");
   1.149 -    output.shouldContain("[Humongous Total");
   1.150 -    output.shouldContain("[Humongous Candidate");
   1.151 -    output.shouldContain("[Humongous Reclaimed");
   1.152 -    output.shouldHaveExitValue(0);
   1.153 -  }
   1.154 +        pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
   1.155 +                                                   "-XX:+UseStringDeduplication",
   1.156 +                                                   "-Xmx10M",
   1.157 +                                                   "-XX:+PrintGCDetails",
   1.158 +                                                   GCTest.class.getName());
   1.159  
   1.160 -  private static void testWithToSpaceExhaustionLogs() throws Exception {
   1.161 -    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
   1.162 -                                               "-Xmx10M",
   1.163 -                                               "-Xmn5M",
   1.164 -                                               "-XX:+PrintGCDetails",
   1.165 -                                               GCTestWithToSpaceExhaustion.class.getName());
   1.166 +        output = new OutputAnalyzer(pb.start());
   1.167 +        checkMessagesAtLevel(output, allLogMessages, Level.FINER);
   1.168  
   1.169 -    OutputAnalyzer output = new OutputAnalyzer(pb.start());
   1.170 -    output.shouldContain("[Evacuation Failure");
   1.171 -    output.shouldNotContain("[Recalculate Used");
   1.172 -    output.shouldNotContain("[Remove Self Forwards");
   1.173 -    output.shouldNotContain("[Restore RemSet");
   1.174 -    output.shouldHaveExitValue(0);
   1.175 +        pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
   1.176 +                                                   "-XX:+UseStringDeduplication",
   1.177 +                                                   "-Xmx10M",
   1.178 +                                                   "-XX:+PrintGCDetails",
   1.179 +                                                   "-XX:+UnlockExperimentalVMOptions",
   1.180 +                                                   "-XX:G1LogLevel=finest",
   1.181 +                                                   GCTest.class.getName());
   1.182  
   1.183 -    pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
   1.184 -                                               "-Xmx10M",
   1.185 -                                               "-Xmn5M",
   1.186 -                                               "-XX:+PrintGCDetails",
   1.187 -                                               "-XX:+UnlockExperimentalVMOptions",
   1.188 -                                               "-XX:G1LogLevel=finest",
   1.189 -                                               GCTestWithToSpaceExhaustion.class.getName());
   1.190 +        output = new OutputAnalyzer(pb.start());
   1.191 +        checkMessagesAtLevel(output, allLogMessages, Level.FINEST);
   1.192 +        output.shouldHaveExitValue(0);
   1.193 +    }
   1.194  
   1.195 -    output = new OutputAnalyzer(pb.start());
   1.196 -    output.shouldContain("[Evacuation Failure");
   1.197 -    output.shouldContain("[Recalculate Used");
   1.198 -    output.shouldContain("[Remove Self Forwards");
   1.199 -    output.shouldContain("[Restore RemSet");
   1.200 -    output.shouldHaveExitValue(0);
   1.201 -  }
   1.202 +    LogMessageWithLevel exhFailureMessages[] = new LogMessageWithLevel[] {
   1.203 +        new LogMessageWithLevel("Evacuation Failure", Level.FINER),
   1.204 +        new LogMessageWithLevel("Recalculate Used", Level.FINEST),
   1.205 +        new LogMessageWithLevel("Remove Self Forwards", Level.FINEST),
   1.206 +        new LogMessageWithLevel("Restore RemSet", Level.FINEST),
   1.207 +    };
   1.208  
   1.209 -  static class GCTest {
   1.210 -    private static byte[] garbage;
   1.211 -    public static void main(String [] args) {
   1.212 -      System.out.println("Creating garbage");
   1.213 -      // create 128MB of garbage. This should result in at least one GC
   1.214 -      for (int i = 0; i < 1024; i++) {
   1.215 -        garbage = new byte[128 * 1024];
   1.216 -      }
   1.217 -      System.out.println("Done");
   1.218 +    private void testWithToSpaceExhaustionLogs() throws Exception {
   1.219 +        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
   1.220 +                                                                  "-Xmx32M",
   1.221 +                                                                  "-Xmn16M",
   1.222 +                                                                  "-XX:+PrintGCDetails",
   1.223 +                                                                  GCTestWithToSpaceExhaustion.class.getName());
   1.224 +
   1.225 +        OutputAnalyzer output = new OutputAnalyzer(pb.start());
   1.226 +        checkMessagesAtLevel(output, exhFailureMessages, Level.FINER);
   1.227 +        output.shouldHaveExitValue(0);
   1.228 +
   1.229 +        pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
   1.230 +                                                   "-Xmx32M",
   1.231 +                                                   "-Xmn16M",
   1.232 +                                                   "-XX:+PrintGCDetails",
   1.233 +                                                   "-XX:+UnlockExperimentalVMOptions",
   1.234 +                                                   "-XX:G1LogLevel=finest",
   1.235 +                                                   GCTestWithToSpaceExhaustion.class.getName());
   1.236 +
   1.237 +        output = new OutputAnalyzer(pb.start());
   1.238 +        checkMessagesAtLevel(output, exhFailureMessages, Level.FINEST);
   1.239 +        output.shouldHaveExitValue(0);
   1.240      }
   1.241 -  }
   1.242  
   1.243 -  static class GCTestWithToSpaceExhaustion {
   1.244 -    private static byte[] garbage;
   1.245 -    private static byte[] largeObject;
   1.246 -    public static void main(String [] args) {
   1.247 -      largeObject = new byte[5*1024*1024];
   1.248 -      System.out.println("Creating garbage");
   1.249 -      // create 128MB of garbage. This should result in at least one GC,
   1.250 -      // some of them with to-space exhaustion.
   1.251 -      for (int i = 0; i < 1024; i++) {
   1.252 -        garbage = new byte[128 * 1024];
   1.253 -      }
   1.254 -      System.out.println("Done");
   1.255 +    static class GCTest {
   1.256 +        private static byte[] garbage;
   1.257 +        public static void main(String [] args) {
   1.258 +            System.out.println("Creating garbage");
   1.259 +            // create 128MB of garbage. This should result in at least one GC
   1.260 +            for (int i = 0; i < 1024; i++) {
   1.261 +                garbage = new byte[128 * 1024];
   1.262 +            }
   1.263 +            System.out.println("Done");
   1.264 +        }
   1.265      }
   1.266 -  }
   1.267 +
   1.268 +    static class GCTestWithToSpaceExhaustion {
   1.269 +        private static byte[] garbage;
   1.270 +        private static byte[] largeObject;
   1.271 +        public static void main(String [] args) {
   1.272 +            largeObject = new byte[16*1024*1024];
   1.273 +            System.out.println("Creating garbage");
   1.274 +            // create 128MB of garbage. This should result in at least one GC,
   1.275 +            // some of them with to-space exhaustion.
   1.276 +            for (int i = 0; i < 1024; i++) {
   1.277 +                garbage = new byte[128 * 1024];
   1.278 +            }
   1.279 +            System.out.println("Done");
   1.280 +        }
   1.281 +    }
   1.282  }
   1.283 +

mercurial