37
38 import jdk.test.lib.process.OutputAnalyzer;
39 import jdk.test.lib.process.ProcessTools;
40 import java.util.regex.Pattern;
41 import java.util.regex.Matcher;
42
43 public class TestPrintReferences {
44 static String output;
45 static final String doubleRegex = "[0-9]+[.,][0-9]+";
46 static final String referenceProcessing = "Reference Processing";
47 static final String softReference = "SoftReference";
48 static final String weakReference = "WeakReference";
49 static final String finalReference = "FinalReference";
50 static final String phantomReference = "PhantomReference";
51 static final String phase1 = "Phase1";
52 static final String phase2 = "Phase2";
53 static final String phase3 = "Phase3";
54 static final String gcLogTimeRegex = ".* GC\\([0-9]+\\) ";
55
56 public static void main(String[] args) throws Exception {
57 ProcessBuilder pb_enabled = ProcessTools.createJavaProcessBuilder("-Xlog:gc+phases+ref=debug",
58 "-XX:+UseG1GC",
59 "-Xmx32M",
60 // Explicit thread setting is required to avoid using only 1 thread
61 "-XX:ParallelGCThreads=2",
62 GCTest.class.getName());
63 OutputAnalyzer output = new OutputAnalyzer(pb_enabled.start());
64
65 checkLogFormat(output);
66 checkLogValue(output);
67
68 output.shouldHaveExitValue(0);
69 }
70
71 static String indent(int count) {
72 return " {" + count + "}";
73 }
74
75 // Find the first Reference Processing log and check its format.
76 public static void checkLogFormat(OutputAnalyzer output) {
77 String countRegex = "[0-9]+";
78 String timeRegex = doubleRegex + "ms";
79 String totalRegex = gcLogTimeRegex + indent(4) + referenceProcessing + ": " + timeRegex + "\n";
80 String balanceRegex = gcLogTimeRegex + indent(8) + "Balance queues: " + timeRegex + "\n";
81 String softRefRegex = gcLogTimeRegex + indent(6) + softReference + ": " + timeRegex + "\n";
82 String weakRefRegex = gcLogTimeRegex + indent(6) + weakReference + ": " + timeRegex + "\n";
83 String finalRefRegex = gcLogTimeRegex + indent(6) + finalReference + ": " + timeRegex + "\n";
84 String phantomRefRegex = gcLogTimeRegex + indent(6) + phantomReference + ": " + timeRegex + "\n";
85 String refDetailRegex = gcLogTimeRegex + indent(8) + phase2 + ": " + timeRegex + "\n" +
86 gcLogTimeRegex + indent(8) + phase3 + ": " + timeRegex + "\n" +
87 gcLogTimeRegex + indent(8) + "Discovered: " + countRegex + "\n" +
88 gcLogTimeRegex + indent(8) + "Cleared: " + countRegex + "\n";
89 String softRefDetailRegex = gcLogTimeRegex + indent(8) + phase1 + ": " + timeRegex + "\n" + refDetailRegex;
90 String enqueueRegex = gcLogTimeRegex + indent(4) + "Reference Enqueuing: " + timeRegex + "\n";
91 String enqueueDetailRegex = gcLogTimeRegex + indent(6) + "Reference Counts: Soft: " + countRegex +
92 " Weak: " + countRegex + " Final: " + countRegex + " Phantom: " + countRegex + "\n";
93
94 output.shouldMatch(/* Total Reference processing time */
95 totalRegex +
96 /* SoftReference processing */
97 softRefRegex + balanceRegex + softRefDetailRegex +
98 /* WeakReference processing */
99 weakRefRegex + balanceRegex + refDetailRegex +
100 /* FinalReference processing */
|
37
38 import jdk.test.lib.process.OutputAnalyzer;
39 import jdk.test.lib.process.ProcessTools;
40 import java.util.regex.Pattern;
41 import java.util.regex.Matcher;
42
43 public class TestPrintReferences {
44 static String output;
45 static final String doubleRegex = "[0-9]+[.,][0-9]+";
46 static final String referenceProcessing = "Reference Processing";
47 static final String softReference = "SoftReference";
48 static final String weakReference = "WeakReference";
49 static final String finalReference = "FinalReference";
50 static final String phantomReference = "PhantomReference";
51 static final String phase1 = "Phase1";
52 static final String phase2 = "Phase2";
53 static final String phase3 = "Phase3";
54 static final String gcLogTimeRegex = ".* GC\\([0-9]+\\) ";
55
56 public static void main(String[] args) throws Exception {
57 test(true);
58 test(false);
59 }
60
61 static String indent(int count) {
62 return " {" + count + "}";
63 }
64
65 public static void test(boolean parallelRefProcEnabled) throws Exception {
66 ProcessBuilder pb_enabled = ProcessTools.createJavaProcessBuilder("-Xlog:gc+phases+ref=debug",
67 "-XX:+UseG1GC",
68 "-Xmx32M",
69 // Explicit thread setting is required to avoid using only 1 thread
70 "-XX:" + (parallelRefProcEnabled ? "+" : "-") + "ParallelRefProcEnabled",
71 "-XX:ParallelGCThreads=2",
72 GCTest.class.getName());
73 OutputAnalyzer output = new OutputAnalyzer(pb_enabled.start());
74
75 checkLogFormat(output, parallelRefProcEnabled);
76 checkLogValue(output);
77
78 output.shouldHaveExitValue(0);
79 }
80
81 // Find the first Reference Processing log and check its format.
82 public static void checkLogFormat(OutputAnalyzer output, boolean parallelRefProcEnabled) {
83 String countRegex = "[0-9]+";
84 String timeRegex = doubleRegex + "ms";
85 String totalRegex = gcLogTimeRegex + indent(4) + referenceProcessing + ": " + timeRegex + "\n";
86 String balanceRegex = parallelRefProcEnabled ? gcLogTimeRegex + indent(8) + "Balance queues: " + timeRegex + "\n" : "";
87 String softRefRegex = gcLogTimeRegex + indent(6) + softReference + ": " + timeRegex + "\n";
88 String weakRefRegex = gcLogTimeRegex + indent(6) + weakReference + ": " + timeRegex + "\n";
89 String finalRefRegex = gcLogTimeRegex + indent(6) + finalReference + ": " + timeRegex + "\n";
90 String phantomRefRegex = gcLogTimeRegex + indent(6) + phantomReference + ": " + timeRegex + "\n";
91 String refDetailRegex = gcLogTimeRegex + indent(8) + phase2 + ": " + timeRegex + "\n" +
92 gcLogTimeRegex + indent(8) + phase3 + ": " + timeRegex + "\n" +
93 gcLogTimeRegex + indent(8) + "Discovered: " + countRegex + "\n" +
94 gcLogTimeRegex + indent(8) + "Cleared: " + countRegex + "\n";
95 String softRefDetailRegex = gcLogTimeRegex + indent(8) + phase1 + ": " + timeRegex + "\n" + refDetailRegex;
96 String enqueueRegex = gcLogTimeRegex + indent(4) + "Reference Enqueuing: " + timeRegex + "\n";
97 String enqueueDetailRegex = gcLogTimeRegex + indent(6) + "Reference Counts: Soft: " + countRegex +
98 " Weak: " + countRegex + " Final: " + countRegex + " Phantom: " + countRegex + "\n";
99
100 output.shouldMatch(/* Total Reference processing time */
101 totalRegex +
102 /* SoftReference processing */
103 softRefRegex + balanceRegex + softRefDetailRegex +
104 /* WeakReference processing */
105 weakRefRegex + balanceRegex + refDetailRegex +
106 /* FinalReference processing */
|