< prev index next >

test/gc/g1/TestGCLogMessages.java

Print this page
rev 7854 : imported patch 8027962-per-phase-timing-measurements-for-strong-roots-processing
rev 7855 : [mq]: 8027962-bengt-suggestions


  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 8027962
  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     private class LogMessageWithLevel {
  38         String message;
  39         int level;
  40 
  41         public LogMessageWithLevel(String message, int level) {
  42             this.message = message;
  43             this.level = level;
  44         }
  45     };
  46 
  47     LogMessageWithLevel messages[] = new LogMessageWithLevel[] {
  48         // Ext Root Scan
  49         new LogMessageWithLevel("Thread Roots (ms)", 3),
  50         new LogMessageWithLevel("StringTable Roots (ms)", 3),
  51         new LogMessageWithLevel("Universe Roots (ms)", 3),
  52         new LogMessageWithLevel("JNI Handles Roots (ms)", 3),
  53         new LogMessageWithLevel("ObjectSynchronizer Roots (ms)", 3),
  54         new LogMessageWithLevel("FlatProfiler Roots", 3),
  55         new LogMessageWithLevel("Management Roots", 3),
  56         new LogMessageWithLevel("SystemDictionary Roots", 3),
  57         new LogMessageWithLevel("CLDG Roots", 3),
  58         new LogMessageWithLevel("JVMTI Roots", 3),
  59         new LogMessageWithLevel("CodeCache Roots", 3),
  60         new LogMessageWithLevel("Filter SATB Roots", 3),
  61         new LogMessageWithLevel("CM RefProcessor Roots", 3),
  62         new LogMessageWithLevel("Wait For Strong CLD", 3),
  63         new LogMessageWithLevel("Weak CLD Roots", 3),
  64         // Redirty Cards
  65         new LogMessageWithLevel("Redirty Cards", 2),
  66         new LogMessageWithLevel("Parallel Redirty", 3),
  67         new LogMessageWithLevel("Redirtied Cards", 3),
  68         // Misc Top-level
  69         new LogMessageWithLevel("Code Root Purge", 2),
  70         new LogMessageWithLevel("String Dedup Fixup", 2),
  71         // Free CSet
  72         new LogMessageWithLevel("Young Free CSet", 3),
  73         new LogMessageWithLevel("Non-Young Free CSet", 3),
  74         // Humongous Eager Reclaim
  75         new LogMessageWithLevel("Humongous Reclaim", 2),
  76         new LogMessageWithLevel("Humongous Register", 2),
  77     };
  78 
  79     void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], int level) throws Exception {
  80         for (LogMessageWithLevel l : messages) {
  81             if (level >= l.level) {
  82                 output.shouldContain(l.message);
  83             } else {
  84                 output.shouldNotContain(l.message);


  85             }
  86         }
  87     }
  88 
  89     public static void main(String[] args) throws Exception {
  90         new TestGCLogMessages().testNormalLogs();
  91         new TestGCLogMessages().testWithToSpaceExhaustionLogs();
  92     }
  93 
  94     private void testNormalLogs() throws Exception {
  95 
  96         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
  97                                                                   "-Xmx10M",
  98                                                                   GCTest.class.getName());
  99 
 100         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 101         checkMessagesAtLevel(output, messages, 0);
 102         output.shouldHaveExitValue(0);
 103 
 104         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 105                                                    "-XX:+UseStringDeduplication",
 106                                                    "-Xmx10M",
 107                                                    "-XX:+PrintGCDetails",
 108                                                    GCTest.class.getName());
 109 
 110         output = new OutputAnalyzer(pb.start());
 111         checkMessagesAtLevel(output, messages, 2);
 112 
 113         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 114                                                    "-XX:+UseStringDeduplication",
 115                                                    "-Xmx10M",
 116                                                    "-XX:+PrintGCDetails",
 117                                                    "-XX:+UnlockExperimentalVMOptions",
 118                                                    "-XX:G1LogLevel=finest",
 119                                                    GCTest.class.getName());
 120 
 121         output = new OutputAnalyzer(pb.start());
 122         checkMessagesAtLevel(output, messages, 3);
 123         output.shouldHaveExitValue(0);
 124     }
 125 
 126     LogMessageWithLevel exhFailureMessages[] = new LogMessageWithLevel[] {
 127         new LogMessageWithLevel("Evacuation Failure", 2),
 128         new LogMessageWithLevel("Recalculate Used", 3),
 129         new LogMessageWithLevel("Remove Self Forwards", 3),
 130         new LogMessageWithLevel("Restore RemSet", 3),
 131     };
 132 
 133     private void testWithToSpaceExhaustionLogs() throws Exception {
 134         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 135                                                                   "-Xmx32M",
 136                                                                   "-Xmn16M",
 137                                                                   "-XX:+PrintGCDetails",
 138                                                                   GCTestWithToSpaceExhaustion.class.getName());
 139 
 140         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 141         checkMessagesAtLevel(output, exhFailureMessages, 2);
 142         output.shouldHaveExitValue(0);
 143 
 144         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 145                                                    "-Xmx32M",
 146                                                    "-Xmn16M",
 147                                                    "-XX:+PrintGCDetails",
 148                                                    "-XX:+UnlockExperimentalVMOptions",
 149                                                    "-XX:G1LogLevel=finest",
 150                                                    GCTestWithToSpaceExhaustion.class.getName());
 151 
 152         output = new OutputAnalyzer(pb.start());
 153         checkMessagesAtLevel(output, exhFailureMessages, 3);
 154         output.shouldHaveExitValue(0);
 155     }
 156 
 157     static class GCTest {
 158         private static byte[] garbage;
 159         public static void main(String [] args) {
 160             System.out.println("Creating garbage");
 161             // create 128MB of garbage. This should result in at least one GC
 162             for (int i = 0; i < 1024; i++) {
 163                 garbage = new byte[128 * 1024];
 164             }
 165             System.out.println("Done");
 166         }
 167     }
 168 
 169     static class GCTestWithToSpaceExhaustion {
 170         private static byte[] garbage;
 171         private static byte[] largeObject;
 172         public static void main(String [] args) {
 173             largeObject = new byte[16*1024*1024];


  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 8027962
  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 
  38     private enum Level {
  39         OFF, FINER, FINEST;
  40         public boolean lessOrEqualTo(Level other) {
  41             return this.compareTo(other) < 0;
  42         }
  43     }
  44 
  45     private class LogMessageWithLevel {
  46         String message;
  47         Level level;
  48 
  49         public LogMessageWithLevel(String message, Level level) {
  50             this.message = message;
  51             this.level = level;
  52         }
  53     };
  54 
  55     private LogMessageWithLevel allLogMessages[] = new LogMessageWithLevel[] {
  56         // Ext Root Scan
  57         new LogMessageWithLevel("Thread Roots (ms)", Level.FINEST),
  58         new LogMessageWithLevel("StringTable Roots (ms)", Level.FINEST),
  59         new LogMessageWithLevel("Universe Roots (ms)", Level.FINEST),
  60         new LogMessageWithLevel("JNI Handles Roots (ms)", Level.FINEST),
  61         new LogMessageWithLevel("ObjectSynchronizer Roots (ms)", Level.FINEST),
  62         new LogMessageWithLevel("FlatProfiler Roots", Level.FINEST),
  63         new LogMessageWithLevel("Management Roots", Level.FINEST),
  64         new LogMessageWithLevel("SystemDictionary Roots", Level.FINEST),
  65         new LogMessageWithLevel("CLDG Roots", Level.FINEST),
  66         new LogMessageWithLevel("JVMTI Roots", Level.FINEST),
  67         new LogMessageWithLevel("CodeCache Roots", Level.FINEST),
  68         new LogMessageWithLevel("Filter SATB Roots", Level.FINEST),
  69         new LogMessageWithLevel("CM RefProcessor Roots", Level.FINEST),
  70         new LogMessageWithLevel("Wait For Strong CLD", Level.FINEST),
  71         new LogMessageWithLevel("Weak CLD Roots", Level.FINEST),
  72         // Redirty Cards
  73         new LogMessageWithLevel("Redirty Cards", Level.FINER),
  74         new LogMessageWithLevel("Parallel Redirty", Level.FINEST),
  75         new LogMessageWithLevel("Redirtied Cards", Level.FINEST),
  76         // Misc Top-level
  77         new LogMessageWithLevel("Code Root Purge", Level.FINER),
  78         new LogMessageWithLevel("String Dedup Fixup", Level.FINER),
  79         // Free CSet
  80         new LogMessageWithLevel("Young Free CSet", Level.FINEST),
  81         new LogMessageWithLevel("Non-Young Free CSet", Level.FINEST),
  82         // Humongous Eager Reclaim
  83         new LogMessageWithLevel("Humongous Reclaim", Level.FINER),
  84         new LogMessageWithLevel("Humongous Register", Level.FINER),
  85     };
  86 
  87     void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
  88         for (LogMessageWithLevel l : messages) {
  89             if (level.lessOrEqualTo(l.level)) {


  90                 output.shouldNotContain(l.message);
  91             } else {
  92                 output.shouldContain(l.message);
  93             }
  94         }
  95     }
  96 
  97     public static void main(String[] args) throws Exception {
  98         new TestGCLogMessages().testNormalLogs();
  99         new TestGCLogMessages().testWithToSpaceExhaustionLogs();
 100     }
 101 
 102     private void testNormalLogs() throws Exception {
 103 
 104         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 105                                                                   "-Xmx10M",
 106                                                                   GCTest.class.getName());
 107 
 108         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 109         checkMessagesAtLevel(output, allLogMessages, Level.OFF);
 110         output.shouldHaveExitValue(0);
 111 
 112         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 113                                                    "-XX:+UseStringDeduplication",
 114                                                    "-Xmx10M",
 115                                                    "-XX:+PrintGCDetails",
 116                                                    GCTest.class.getName());
 117 
 118         output = new OutputAnalyzer(pb.start());
 119         checkMessagesAtLevel(output, allLogMessages, Level.FINER);
 120 
 121         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 122                                                    "-XX:+UseStringDeduplication",
 123                                                    "-Xmx10M",
 124                                                    "-XX:+PrintGCDetails",
 125                                                    "-XX:+UnlockExperimentalVMOptions",
 126                                                    "-XX:G1LogLevel=finest",
 127                                                    GCTest.class.getName());
 128 
 129         output = new OutputAnalyzer(pb.start());
 130         checkMessagesAtLevel(output, allLogMessages, Level.FINEST);
 131         output.shouldHaveExitValue(0);
 132     }
 133 
 134     LogMessageWithLevel exhFailureMessages[] = new LogMessageWithLevel[] {
 135         new LogMessageWithLevel("Evacuation Failure", Level.FINER),
 136         new LogMessageWithLevel("Recalculate Used", Level.FINEST),
 137         new LogMessageWithLevel("Remove Self Forwards", Level.FINEST),
 138         new LogMessageWithLevel("Restore RemSet", Level.FINEST),
 139     };
 140 
 141     private void testWithToSpaceExhaustionLogs() throws Exception {
 142         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 143                                                                   "-Xmx32M",
 144                                                                   "-Xmn16M",
 145                                                                   "-XX:+PrintGCDetails",
 146                                                                   GCTestWithToSpaceExhaustion.class.getName());
 147 
 148         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 149         checkMessagesAtLevel(output, exhFailureMessages, Level.FINER);
 150         output.shouldHaveExitValue(0);
 151 
 152         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 153                                                    "-Xmx32M",
 154                                                    "-Xmn16M",
 155                                                    "-XX:+PrintGCDetails",
 156                                                    "-XX:+UnlockExperimentalVMOptions",
 157                                                    "-XX:G1LogLevel=finest",
 158                                                    GCTestWithToSpaceExhaustion.class.getName());
 159 
 160         output = new OutputAnalyzer(pb.start());
 161         checkMessagesAtLevel(output, exhFailureMessages, Level.FINEST);
 162         output.shouldHaveExitValue(0);
 163     }
 164 
 165     static class GCTest {
 166         private static byte[] garbage;
 167         public static void main(String [] args) {
 168             System.out.println("Creating garbage");
 169             // create 128MB of garbage. This should result in at least one GC
 170             for (int i = 0; i < 1024; i++) {
 171                 garbage = new byte[128 * 1024];
 172             }
 173             System.out.println("Done");
 174         }
 175     }
 176 
 177     static class GCTestWithToSpaceExhaustion {
 178         private static byte[] garbage;
 179         private static byte[] largeObject;
 180         public static void main(String [] args) {
 181             largeObject = new byte[16*1024*1024];
< prev index next >