CompilerQueueTest.java revision 7292:4522428f5220
1/*
2 * Copyright (c) 2014, 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 CompilerQueueTest
26 * @bug 8054889
27 * @library ..
28 * @build DcmdUtil CompilerQueueTest
29 * @run main CompilerQueueTest
30 * @run main/othervm -XX:-TieredCompilation CompilerQueueTest
31 * @run main/othervm -Xint CompilerQueueTest
32 * @summary Test of diagnostic command Compiler.queue
33 */
34
35import java.io.BufferedReader;
36import java.io.StringReader;
37
38public class CompilerQueueTest {
39
40    /**
41     * This test calls Jcmd (diagnostic command tool) Compiler.queue and
42     * then parses the output, making sure that the output look ok.
43     *
44     *
45     * Output example:
46     *
47     * Contents of C1 compile queue
48     * ----------------------------
49     * 73       3       java.lang.AbstractStringBuilder::append (50 bytes)
50     * 74       1       java.util.TreeMap::size (5 bytes)
51     * 75       3       java.lang.StringBuilder::append (8 bytes)
52     * 83       3       java.util.TreeMap$ValueIterator::next (8 bytes)
53     * 84       1       javax.management.MBeanFeatureInfo::getName (5 bytes)
54     * ----------------------------
55     * Contents of C2 compile queue
56     * ----------------------------
57     * Empty
58     * ----------------------------
59     *
60     **/
61
62    public static void main(String arg[]) throws Exception {
63
64        // Get output from dcmd (diagnostic command)
65        String result = DcmdUtil.executeDcmd("Compiler.queue");
66        BufferedReader r = new BufferedReader(new StringReader(result));
67
68        String str = r.readLine();
69
70        while (str != null) {
71            if (str.startsWith("Contents of C")) {
72                match(r.readLine(), "----------------------------");
73                str = r.readLine();
74                if (!str.equals("Empty")) {
75                    while (str.charAt(0) != '-') {
76                        validateMethodLine(str);
77                        str = r.readLine();
78                    }
79                } else {
80                    str = r.readLine();
81                }
82                match(str,"----------------------------");
83                str = r.readLine();
84            } else {
85                throw new Exception("Failed parsing dcmd queue, line: " + str);
86            }
87        }
88    }
89
90    private static void validateMethodLine(String str)  throws Exception {
91        // Skip until package/class name begins. Trim to remove whitespace that
92        // may differ.
93        String name = str.substring(14).trim();
94        int sep = name.indexOf("::");
95        if (sep == -1) {
96            throw new Exception("Failed dcmd queue, didn't find separator :: in: " + name);
97        }
98        try {
99            Class.forName(name.substring(0, sep));
100        } catch (ClassNotFoundException e) {
101            throw new Exception("Failed dcmd queue, Class for name: " + str);
102        }
103    }
104
105    public static void match(String line, String str) throws Exception {
106        if (!line.equals(str)) {
107            throw new Exception("String equals: " + line + ", " + str);
108        }
109    }
110}
111