test/hotspot/jtreg/gc/logging/TestMetaSpaceLog.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54638 9b8926bf85c1
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    31 import java.util.regex.Matcher;
    31 import java.util.regex.Matcher;
    32 
    32 
    33 import jdk.test.lib.Asserts;
    33 import jdk.test.lib.Asserts;
    34 import jdk.test.lib.process.OutputAnalyzer;
    34 import jdk.test.lib.process.OutputAnalyzer;
    35 import jdk.test.lib.process.ProcessTools;
    35 import jdk.test.lib.process.ProcessTools;
    36 import jtreg.SkippedException;
       
    37 import sun.hotspot.gc.GC;
       
    38 import sun.hotspot.WhiteBox;
    36 import sun.hotspot.WhiteBox;
    39 
    37 
    40 /*
    38 /*
    41  * @test TestMetaSpaceLog
    39  * @test TestMetaSpaceLog
    42  * @bug 8211123
    40  * @bug 8211123
    43  * @summary Ensure that the Metaspace is updated in the log
    41  * @summary Ensure that the Metaspace is updated in the log
    44  * @key gc
    42  * @key gc
    45  * @library /test/lib
    43  * @library /test/lib
    46  * @modules java.base/jdk.internal.misc
    44  * @modules java.base/jdk.internal.misc
    47  *          java.management
    45  *          java.management
       
    46  * @requires vm.gc != "Epsilon"
       
    47  * @requires vm.gc != "Z"
       
    48  * @requires vm.gc != "Shenandoah"
    48  *
    49  *
    49  * @compile TestMetaSpaceLog.java
    50  * @compile TestMetaSpaceLog.java
    50  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
    51  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
    51  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI gc.logging.TestMetaSpaceLog
    52  * @run driver gc.logging.TestMetaSpaceLog
    52  */
    53  */
    53 
    54 
    54 public class TestMetaSpaceLog {
    55 public class TestMetaSpaceLog {
    55   private static Pattern metaSpaceRegexp;
    56   private static Pattern metaSpaceRegexp;
    56 
    57 
    58     // Do this once here.
    59     // Do this once here.
    59     metaSpaceRegexp = Pattern.compile(".*Metaspace: ([0-9]+).*->([0-9]+).*");
    60     metaSpaceRegexp = Pattern.compile(".*Metaspace: ([0-9]+).*->([0-9]+).*");
    60   }
    61   }
    61 
    62 
    62   public static void main(String[] args) throws Exception {
    63   public static void main(String[] args) throws Exception {
    63     boolean noneGCSupported = true;
    64     testMetaSpaceUpdate();
    64 
       
    65     if (GC.Parallel.isSupported()) {
       
    66       noneGCSupported = false;
       
    67       testMetaSpaceUpdate("UseParallelGC");
       
    68     }
       
    69     if (GC.G1.isSupported()) {
       
    70       noneGCSupported = false;
       
    71       testMetaSpaceUpdate("UseG1GC");
       
    72     }
       
    73     if (GC.ConcMarkSweep.isSupported()) {
       
    74       noneGCSupported = false;
       
    75       testMetaSpaceUpdate("UseConcMarkSweepGC");
       
    76     }
       
    77     if (GC.Serial.isSupported()) {
       
    78       noneGCSupported = false;
       
    79       testMetaSpaceUpdate("UseSerialGC");
       
    80     }
       
    81     if (noneGCSupported) {
       
    82       throw new SkippedException("Skipping test because none of Parallel/G1/ConcMarkSweep/Serial is supported.");
       
    83     }
       
    84   }
    65   }
    85 
    66 
    86   private static void verifyContainsMetaSpaceUpdate(OutputAnalyzer output) {
    67   private static void verifyContainsMetaSpaceUpdate(OutputAnalyzer output) {
    87     // At least one metaspace line from GC should show GC being collected.
    68     // At least one metaspace line from GC should show GC being collected.
    88     boolean foundCollectedMetaSpace = output.asLines().stream()
    69     boolean foundCollectedMetaSpace = output.asLines().stream()
    97     long before = Long.parseLong(m.group(1));
    78     long before = Long.parseLong(m.group(1));
    98     long after  = Long.parseLong(m.group(2));
    79     long after  = Long.parseLong(m.group(2));
    99     return before > after;
    80     return before > after;
   100   }
    81   }
   101 
    82 
   102   private static void testMetaSpaceUpdate(String gcFlag) throws Exception {
    83   private static void testMetaSpaceUpdate() throws Exception {
   103     // Propagate test.src for the jar file.
    84     // Propagate test.src for the jar file.
   104     String testSrc= "-Dtest.src=" + System.getProperty("test.src", ".");
    85     String testSrc= "-Dtest.src=" + System.getProperty("test.src", ".");
   105 
    86 
   106     System.err.println("Testing with GC Flag: " + gcFlag);
       
   107     ProcessBuilder pb =
    87     ProcessBuilder pb =
   108       ProcessTools.createJavaProcessBuilder(
    88       ProcessTools.createJavaProcessBuilder(
   109           "-XX:+" + gcFlag,
    89           true,
   110           "-Xlog:gc*",
    90           "-Xlog:gc*",
   111           "-Xbootclasspath/a:.",
    91           "-Xbootclasspath/a:.",
   112           "-XX:+UnlockDiagnosticVMOptions",
    92           "-XX:+UnlockDiagnosticVMOptions",
   113           "-XX:+WhiteBoxAPI",
    93           "-XX:+WhiteBoxAPI",
   114           "-Xmx1000M",
    94           "-Xmx1000M",
   148     }
   128     }
   149 
   129 
   150     public static void loadClass(WhiteBox wb) {
   130     public static void loadClass(WhiteBox wb) {
   151       try {
   131       try {
   152         URLClassLoader ucl = new URLClassLoader(urls);
   132         URLClassLoader ucl = new URLClassLoader(urls);
   153         Class.forName("case00", false, ucl);
   133         ucl.loadClass("case00");
   154       } catch (Exception e) {
   134       } catch (Exception e) {
   155         e.printStackTrace();
   135         e.printStackTrace();
   156       }
   136       }
   157     }
   137     }
   158   }
   138   }