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 * @build DcmdUtil CompilerQueueTest 28 * @run main CompilerQueueTest 29 * @summary testing of Dcmd Compiler.queue 30 * @author nils.eliasson@oracle.com 31 */ 32 33 import java.io.BufferedReader; 34 import java.io.StringReader; 35 36 public class CompilerQueueTest { 37 38 /** 39 * This test calls Jcmd Compiler.queue and then parses the output, 40 * making sure that the output look ok. To get a stable verifiable output 41 * we prevent the Compiler from adding or removing tasks, then 42 * add one manually, and finally check that it looks ok. 43 */ 44 45 /** 46 * Contents of C1 compile queue 47 * ---------------------------- 48 * 73 3 java.lang.AbstractStringBuilder::append (50 bytes) 49 * 74 1 java.util.TreeMap::size (5 bytes) 50 * 75 3 java.lang.StringBuilder::append (8 bytes) 51 * 83 3 java.util.TreeMap$ValueIterator::next (8 bytes) 52 * 84 1 javax.management.MBeanFeatureInfo::getName (5 bytes) 53 * ---------------------------- 54 * Contents of C2 compile queue 55 * ---------------------------- 56 * Empty 57 * ---------------------------- 58 **/ 59 60 public static void main(String arg[]) throws Exception { 61 62 // Find in output from dcmd 63 String result = DcmdUtil.executeDcmd("Compiler.queue"); 64 BufferedReader r = new BufferedReader(new StringReader(result)); 65 66 String line; 67 match(r.readLine(), "Contents of C1 compile queue"); 68 match(r.readLine(), "----------------------------"); 69 String str = r.readLine(); 70 if (!str.equals("Empty")) { 71 while (str.charAt(0) != '-') { 72 validateMethodLine(str); 73 str = r.readLine(); 74 } 75 } else { 76 str = r.readLine(); 77 } 78 79 match(str, "----------------------------"); 80 match(r.readLine(), "Contents of C2 compile queue"); 81 match(r.readLine(), "----------------------------"); 82 str = r.readLine(); 83 if (!str.equals("Empty")) { 84 while (str.charAt(0) != '-') { 85 validateMethodLine(str); 86 str = r.readLine(); 87 } 88 } else { 89 str = r.readLine(); 90 } 91 match(str, "----------------------------"); 92 } 93 94 private static void validateMethodLine(String str) throws Exception { 95 String name = str.substring(19); 96 int sep = name.indexOf("::"); 97 try { 98 Class.forName(name.substring(0, sep)); 99 } catch (ClassNotFoundException e) { 100 throw new Exception("Failed parsing dcmd queue"); 101 } 102 } 103 104 public static void match(String line, String str) throws Exception { 105 if (!line.equals(str)) { 106 throw new Exception("String equals: " + line + ", " + str); 107 } 108 } 109 }