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