< prev index next >

test/hotspot/jtreg/gc/logging/TestMetaSpaceLog.java

Print this page




  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 package gc.logging;
  26 
  27 import java.io.File;
  28 import java.net.URL;
  29 import java.net.URLClassLoader;
  30 import java.util.regex.Pattern;
  31 import java.util.regex.Matcher;
  32 
  33 import jdk.test.lib.Asserts;
  34 import jdk.test.lib.process.OutputAnalyzer;
  35 import jdk.test.lib.process.ProcessTools;


  36 import sun.hotspot.WhiteBox;
  37 
  38 /*
  39  * @test TestMetaSpaceLog
  40  * @bug 8211123
  41  * @summary Ensure that the Metaspace is updated in the log
  42  * @key gc
  43  * @library /test/lib
  44  * @modules java.base/jdk.internal.misc
  45  *          java.management
  46  * @requires vm.gc != "Epsilon"
  47  * @requires vm.gc != "Z"
  48  * @requires vm.gc != "Shenandoah"
  49  *
  50  * @compile TestMetaSpaceLog.java
  51  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  52  * @run driver gc.logging.TestMetaSpaceLog
  53  */
  54 
  55 public class TestMetaSpaceLog {
  56   private static Pattern metaSpaceRegexp;
  57 
  58   static {
  59     // Do this once here.
  60     metaSpaceRegexp = Pattern.compile(".*Metaspace: ([0-9]+).*->([0-9]+).*");
  61   }
  62 
  63   public static void main(String[] args) throws Exception {
  64     testMetaSpaceUpdate();




















  65   }
  66 
  67   private static void verifyContainsMetaSpaceUpdate(OutputAnalyzer output) {
  68     // At least one metaspace line from GC should show GC being collected.
  69     boolean foundCollectedMetaSpace = output.asLines().stream()
  70         .filter(s -> s.contains("[gc,metaspace"))
  71         .anyMatch(TestMetaSpaceLog::check);
  72     Asserts.assertTrue(foundCollectedMetaSpace);
  73   }
  74 
  75   private static boolean check(String line) {
  76     Matcher m = metaSpaceRegexp.matcher(line);
  77     Asserts.assertTrue(m.matches(), "Unexpected line for metaspace logging: " + line);
  78     long before = Long.parseLong(m.group(1));
  79     long after  = Long.parseLong(m.group(2));
  80     return before > after;
  81   }
  82 
  83   private static void testMetaSpaceUpdate() throws Exception {
  84     // Propagate test.src for the jar file.
  85     String testSrc= "-Dtest.src=" + System.getProperty("test.src", ".");
  86 

  87     ProcessBuilder pb =
  88       ProcessTools.createJavaProcessBuilder(
  89           true,
  90           "-Xlog:gc*",
  91           "-Xbootclasspath/a:.",
  92           "-XX:+UnlockDiagnosticVMOptions",
  93           "-XX:+WhiteBoxAPI",
  94           "-Xmx1000M",
  95           "-Xms1000M",
  96           testSrc, StressMetaSpace.class.getName());
  97 
  98     OutputAnalyzer output = null;
  99     try {
 100       output = new OutputAnalyzer(pb.start());
 101       verifyContainsMetaSpaceUpdate(output);
 102     } catch (Exception e) {
 103       // For error diagnosis: print and throw.
 104       e.printStackTrace();
 105       output.reportDiagnosticSummary();
 106       throw e;
 107     }
 108   }
 109 




  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 package gc.logging;
  26 
  27 import java.io.File;
  28 import java.net.URL;
  29 import java.net.URLClassLoader;
  30 import java.util.regex.Pattern;
  31 import java.util.regex.Matcher;
  32 
  33 import jdk.test.lib.Asserts;
  34 import jdk.test.lib.process.OutputAnalyzer;
  35 import jdk.test.lib.process.ProcessTools;
  36 import jtreg.SkippedException;
  37 import sun.hotspot.gc.GC;
  38 import sun.hotspot.WhiteBox;
  39 
  40 /*
  41  * @test TestMetaSpaceLog
  42  * @bug 8211123
  43  * @summary Ensure that the Metaspace is updated in the log
  44  * @key gc
  45  * @library /test/lib
  46  * @modules java.base/jdk.internal.misc
  47  *          java.management



  48  *
  49  * @compile TestMetaSpaceLog.java
  50  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  51  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI gc.logging.TestMetaSpaceLog
  52  */
  53 
  54 public class TestMetaSpaceLog {
  55   private static Pattern metaSpaceRegexp;
  56 
  57   static {
  58     // Do this once here.
  59     metaSpaceRegexp = Pattern.compile(".*Metaspace: ([0-9]+).*->([0-9]+).*");
  60   }
  61 
  62   public static void main(String[] args) throws Exception {
  63     boolean noneGCSupported = true;
  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   }
  85 
  86   private static void verifyContainsMetaSpaceUpdate(OutputAnalyzer output) {
  87     // At least one metaspace line from GC should show GC being collected.
  88     boolean foundCollectedMetaSpace = output.asLines().stream()
  89         .filter(s -> s.contains("[gc,metaspace"))
  90         .anyMatch(TestMetaSpaceLog::check);
  91     Asserts.assertTrue(foundCollectedMetaSpace);
  92   }
  93 
  94   private static boolean check(String line) {
  95     Matcher m = metaSpaceRegexp.matcher(line);
  96     Asserts.assertTrue(m.matches(), "Unexpected line for metaspace logging: " + line);
  97     long before = Long.parseLong(m.group(1));
  98     long after  = Long.parseLong(m.group(2));
  99     return before > after;
 100   }
 101 
 102   private static void testMetaSpaceUpdate(String gcFlag) throws Exception {
 103     // Propagate test.src for the jar file.
 104     String testSrc= "-Dtest.src=" + System.getProperty("test.src", ".");
 105 
 106     System.err.println("Testing with GC Flag: " + gcFlag);
 107     ProcessBuilder pb =
 108       ProcessTools.createJavaProcessBuilder(
 109           "-XX:+" + gcFlag,
 110           "-Xlog:gc*",
 111           "-Xbootclasspath/a:.",
 112           "-XX:+UnlockDiagnosticVMOptions",
 113           "-XX:+WhiteBoxAPI",
 114           "-Xmx1000M",
 115           "-Xms1000M",
 116           testSrc, StressMetaSpace.class.getName());
 117 
 118     OutputAnalyzer output = null;
 119     try {
 120       output = new OutputAnalyzer(pb.start());
 121       verifyContainsMetaSpaceUpdate(output);
 122     } catch (Exception e) {
 123       // For error diagnosis: print and throw.
 124       e.printStackTrace();
 125       output.reportDiagnosticSummary();
 126       throw e;
 127     }
 128   }
 129 


< prev index next >