hotspot/test/gc/g1/TestGCLogMessages.java
changeset 23455 e541bff96524
parent 23454 13a3b426f64d
child 23472 35e93890ed88
equal deleted inserted replaced
23454:13a3b426f64d 23455:e541bff96524
    33 import com.oracle.java.testlibrary.ProcessTools;
    33 import com.oracle.java.testlibrary.ProcessTools;
    34 import com.oracle.java.testlibrary.OutputAnalyzer;
    34 import com.oracle.java.testlibrary.OutputAnalyzer;
    35 
    35 
    36 public class TestGCLogMessages {
    36 public class TestGCLogMessages {
    37   public static void main(String[] args) throws Exception {
    37   public static void main(String[] args) throws Exception {
       
    38     testNormalLogs();
       
    39     testWithToSpaceExhaustionLogs();
       
    40   }
       
    41 
       
    42   private static void testNormalLogs() throws Exception {
    38 
    43 
    39     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
    44     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
    40                                                               "-Xmx10M",
    45                                                               "-Xmx10M",
    41                                                               GCTest.class.getName());
    46                                                               GCTest.class.getName());
    42 
    47 
    72 
    77 
    73     output.shouldContain("[Redirty Cards");
    78     output.shouldContain("[Redirty Cards");
    74     output.shouldContain("[Code Root Purge");
    79     output.shouldContain("[Code Root Purge");
    75     output.shouldContain("[Young Free CSet");
    80     output.shouldContain("[Young Free CSet");
    76     output.shouldContain("[Non-Young Free CSet");
    81     output.shouldContain("[Non-Young Free CSet");
       
    82 
       
    83     // also check evacuation failure messages once
       
    84     output.shouldNotContain("[Evacuation Failure");
       
    85     output.shouldNotContain("[Recalculate Used");
       
    86     output.shouldNotContain("[Remove Self Forwards");
       
    87     output.shouldNotContain("[Restore RemSet");
       
    88     output.shouldHaveExitValue(0);
       
    89   }
       
    90 
       
    91   private static void testWithToSpaceExhaustionLogs() throws Exception {
       
    92     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
       
    93                                                "-Xmx10M",
       
    94                                                "-Xmn5M",
       
    95                                                "-XX:+PrintGCDetails",
       
    96                                                GCTestWithToSpaceExhaustion.class.getName());
       
    97 
       
    98     OutputAnalyzer output = new OutputAnalyzer(pb.start());
       
    99     output.shouldContain("[Evacuation Failure");
       
   100     output.shouldNotContain("[Recalculate Used");
       
   101     output.shouldNotContain("[Remove Self Forwards");
       
   102     output.shouldNotContain("[Restore RemSet");
    77     output.shouldHaveExitValue(0);
   103     output.shouldHaveExitValue(0);
    78 
   104 
       
   105     pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
       
   106                                                "-Xmx10M",
       
   107                                                "-Xmn5M",
       
   108                                                "-XX:+PrintGCDetails",
       
   109                                                "-XX:+UnlockExperimentalVMOptions",
       
   110                                                "-XX:G1LogLevel=finest",
       
   111                                                GCTestWithToSpaceExhaustion.class.getName());
       
   112 
       
   113     output = new OutputAnalyzer(pb.start());
       
   114     output.shouldContain("[Evacuation Failure");
       
   115     output.shouldContain("[Recalculate Used");
       
   116     output.shouldContain("[Remove Self Forwards");
       
   117     output.shouldContain("[Restore RemSet");
       
   118     output.shouldHaveExitValue(0);
    79   }
   119   }
    80 
   120 
    81   static class GCTest {
   121   static class GCTest {
    82     private static byte[] garbage;
   122     private static byte[] garbage;
    83     public static void main(String [] args) {
   123     public static void main(String [] args) {
    87         garbage = new byte[128 * 1024];
   127         garbage = new byte[128 * 1024];
    88       }
   128       }
    89       System.out.println("Done");
   129       System.out.println("Done");
    90     }
   130     }
    91   }
   131   }
       
   132 
       
   133   static class GCTestWithToSpaceExhaustion {
       
   134     private static byte[] garbage;
       
   135     private static byte[] largeObject;
       
   136     public static void main(String [] args) {
       
   137       largeObject = new byte[5*1024*1024];
       
   138       System.out.println("Creating garbage");
       
   139       // create 128MB of garbage. This should result in at least one GC,
       
   140       // some of them with to-space exhaustion.
       
   141       for (int i = 0; i < 1024; i++) {
       
   142         garbage = new byte[128 * 1024];
       
   143       }
       
   144       System.out.println("Done");
       
   145     }
       
   146   }
    92 }
   147 }