1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test TestPrintReferences
26 * @bug 8136991
27 * @summary Validate the reference processing logging
28 * @key gc
29 * @library /test/lib
30 * @modules java.base/jdk.internal.misc
31 * java.management
32 */
33
34 import jdk.test.lib.process.OutputAnalyzer;
35 import jdk.test.lib.process.ProcessTools;
36
37 public class TestPrintReferences {
38 public static void main(String[] args) throws Exception {
39 ProcessBuilder pb_enabled =
40 ProcessTools.createJavaProcessBuilder("-Xlog:gc+ref=debug", "-Xmx10M", GCTest.class.getName());
41 OutputAnalyzer output = new OutputAnalyzer(pb_enabled.start());
42
43 String countRegex = "[0-9]+ refs";
44 String timeRegex = "[0-9]+[.,][0-9]+ms";
45
46 output.shouldMatch(".* GC\\([0-9]+\\) SoftReference " + timeRegex + "\n" +
47 ".* GC\\([0-9]+\\) WeakReference " + timeRegex + "\n" +
48 ".* GC\\([0-9]+\\) FinalReference " + timeRegex + "\n" +
49 ".* GC\\([0-9]+\\) PhantomReference " + timeRegex + "\n" +
50 ".* GC\\([0-9]+\\) JNI Weak Reference " + timeRegex + "\n" +
51 ".* GC\\([0-9]+\\) Ref Counts: Soft: [0-9]+ Weak: [0-9]+ Final: [0-9]+ Phantom: [0-9]+\n");
52
53 output.shouldHaveExitValue(0);
54 }
55
56 static class GCTest {
57 public static void main(String [] args) {
58 System.gc();
59 }
60 }
61 }
|
1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test TestPrintReferences
26 * @bug 8136991
27 * @summary Validate the reference processing logging
28 * @key gc
29 * @library /test/lib
30 * @modules java.base/jdk.internal.misc
31 * java.management
32 */
33
34 import jdk.test.lib.process.OutputAnalyzer;
35 import jdk.test.lib.process.ProcessTools;
36
37 public class TestPrintReferences {
38 public static void main(String[] args) throws Exception {
39 ProcessBuilder pb_enabled =
40 ProcessTools.createJavaProcessBuilder("-Xlog:gc+ref=debug", "-Xmx32M", GCTest.class.getName());
41 OutputAnalyzer output = new OutputAnalyzer(pb_enabled.start());
42
43 String gcLogTimeRegex = ".* GC\\([0-9]+\\)";
44 String countRegex = "[0-9]+";
45 String timeRegex = "[0-9]+[.,][0-9]+ms\n";
46 String refDetailRegex = gcLogTimeRegex + " Phase2: " + timeRegex +
47 gcLogTimeRegex + " Phase3: " + timeRegex +
48 gcLogTimeRegex + " Cleared: " + countRegex + "\n" +
49 gcLogTimeRegex + " Discovered: " + countRegex + "\n";
50 String softRefDetailRegex = gcLogTimeRegex + " Phase1: " + timeRegex +
51 refDetailRegex;
52
53 output.shouldMatch(/* SoftReference processing */
54 gcLogTimeRegex + " SoftReference " + timeRegex + softRefDetailRegex +
55 /* WeakReference processing */
56 gcLogTimeRegex + " WeakReference " + timeRegex + refDetailRegex +
57 /* FinalReference processing */
58 gcLogTimeRegex + " FinalReference " + timeRegex + refDetailRegex +
59 /* PhantomReference processing */
60 gcLogTimeRegex + " PhantomReference " + timeRegex + refDetailRegex +
61 /* JNI Weak Reference processing */
62 gcLogTimeRegex + " JNI Weak Reference " + timeRegex +
63 /* Enqueue Reference Lists */
64 gcLogTimeRegex + " Enqueue reference lists " + timeRegex +
65 /* Enqueued Stats */
66 gcLogTimeRegex + " Ref Counts: Soft: " + countRegex + " Weak: " + countRegex +
67 " Final: " + countRegex + " Phantom: " + countRegex
68 );
69
70 output.shouldHaveExitValue(0);
71 }
72
73 static class GCTest {
74 public static void main(String [] args) {
75 System.gc();
76 }
77 }
78 }
|