< prev index next >

test/gc/logging/TestPrintReferences.java

Print this page
rev 13328 : [mq]: webrev.0b
rev 13329 : [mq]: webrev.1
rev 13330 : imported patch webrev.2
rev 13331 : imported patch webrev.3b

*** 1,7 **** /* ! * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 29,61 **** * @library /test/lib * @modules java.base/jdk.internal.misc * java.management */ import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.ProcessTools; public class TestPrintReferences { public static void main(String[] args) throws Exception { ! ProcessBuilder pb_enabled = ! ProcessTools.createJavaProcessBuilder("-Xlog:gc+ref=debug", "-Xmx10M", GCTest.class.getName()); OutputAnalyzer output = new OutputAnalyzer(pb_enabled.start()); ! String countRegex = "[0-9]+ refs"; String timeRegex = "[0-9]+[.,][0-9]+ms"; ! ! output.shouldMatch(".* GC\\([0-9]+\\) SoftReference " + timeRegex + "\n" + ! ".* GC\\([0-9]+\\) WeakReference " + timeRegex + "\n" + ! ".* GC\\([0-9]+\\) FinalReference " + timeRegex + "\n" + ! ".* GC\\([0-9]+\\) PhantomReference " + timeRegex + "\n" + ! ".* GC\\([0-9]+\\) JNI Weak Reference " + timeRegex + "\n" + ! ".* GC\\([0-9]+\\) Ref Counts: Soft: [0-9]+ Weak: [0-9]+ Final: [0-9]+ Phantom: [0-9]+\n"); output.shouldHaveExitValue(0); } static class GCTest { public static void main(String [] args) { ! System.gc(); } } } --- 29,103 ---- * @library /test/lib * @modules java.base/jdk.internal.misc * java.management */ + import java.lang.ref.SoftReference; + import java.util.ArrayList; + import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.ProcessTools; public class TestPrintReferences { public static void main(String[] args) throws Exception { ! ProcessBuilder pb_enabled = ProcessTools.createJavaProcessBuilder("-Xlog:gc+phases+ref=debug", ! "-XX:+UseG1GC", ! "-Xmx10M", ! GCTest.class.getName()); OutputAnalyzer output = new OutputAnalyzer(pb_enabled.start()); ! String indent_4 = " "; ! String indent_6 = " "; ! String indent_8 = " "; ! String gcLogTimeRegex = ".* GC\\([0-9]+\\) "; ! String countRegex = "[0-9]+"; String timeRegex = "[0-9]+[.,][0-9]+ms"; ! String totalRegex = gcLogTimeRegex + indent_4 + "Reference Processing: " + timeRegex + "\n"; ! String balanceRegex = gcLogTimeRegex + indent_8 + "Balance queues: " + timeRegex + "\n"; ! String softRefRegex = gcLogTimeRegex + indent_6 + "SoftReference: " + timeRegex + "\n"; ! String weakRefRegex = gcLogTimeRegex + indent_6 + "WeakReference: " + timeRegex + "\n"; ! String finalRefRegex = gcLogTimeRegex + indent_6 + "FinalReference: " + timeRegex + "\n"; ! String phantomRefRegex = gcLogTimeRegex + indent_6 + "PhantomReference: " + timeRegex + "\n"; ! String refDetailRegex = gcLogTimeRegex + indent_8 + "Phase2: " + timeRegex + "\n" + ! gcLogTimeRegex + indent_8 + "Phase3: " + timeRegex + "\n" + ! gcLogTimeRegex + indent_8 + "Discovered: " + countRegex + "\n" + ! gcLogTimeRegex + indent_8 + "Cleared: " + countRegex + "\n"; ! String softRefDetailRegex = gcLogTimeRegex + indent_8 + "Phase1: " + timeRegex + "\n" + refDetailRegex; ! String enqueueRegex = gcLogTimeRegex + indent_4 + "Reference Enqueuing: " + timeRegex + "\n"; ! String enqueueDetailRegex = gcLogTimeRegex + indent_6 + "Reference Counts: Soft: " + countRegex + ! " Weak: " + countRegex + " Final: " + countRegex + " Phantom: " + countRegex + "\n"; ! ! output.shouldMatch(/* Total Reference processing time */ ! totalRegex + ! /* SoftReference processing */ ! softRefRegex + balanceRegex + softRefDetailRegex + ! /* WeakReference processing */ ! weakRefRegex + balanceRegex + refDetailRegex + ! /* FinalReference processing */ ! finalRefRegex + balanceRegex + refDetailRegex + ! /* PhantomReference processing */ ! phantomRefRegex + balanceRegex + refDetailRegex + ! /* Total Enqueuing time */ ! enqueueRegex + ! /* Enqueued Stats */ ! enqueueDetailRegex ! ); output.shouldHaveExitValue(0); } static class GCTest { + static final int M = 1024 * 1024; + public static void main(String [] args) { ! ! ArrayList arrSoftRefs = new ArrayList(); ! ! // Populate to triger GC and then Reference related logs will be printed. ! for (int i = 0; i < 10; i++) { ! byte[] tmp = new byte[M]; ! ! arrSoftRefs.add(new SoftReference(tmp)); ! } } } }
< prev index next >