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 /testlibrary 28 * @ignore 8069160 29 * @build com.oracle.java.testlibrary.* 30 * @build com.oracle.java.testlibrary.dcmd.* 31 * @run testng CompilerQueueTest 32 * @run testng/othervm -XX:-TieredCompilation CompilerQueueTest 33 * @run testng/othervm -Xint CompilerQueueTest 34 * @summary Test of diagnostic command Compiler.queue 35 */ 36 37 import com.oracle.java.testlibrary.OutputAnalyzer; 38 import com.oracle.java.testlibrary.dcmd.CommandExecutor; 39 import com.oracle.java.testlibrary.dcmd.JMXExecutor; 40 import org.testng.annotations.Test; 41 42 import java.util.Iterator; 43 44 public class CompilerQueueTest { 45 46 /** 47 * This test calls Jcmd (diagnostic command tool) Compiler.queue and 48 * then parses the output, making sure that the output look ok. 49 * 50 * 51 * Output example: 52 * 53 * Contents of C1 compile queue 54 * ---------------------------- 55 * 73 3 java.lang.AbstractStringBuilder::append (50 bytes) 56 * 74 1 java.util.TreeMap::size (5 bytes) 57 * 75 3 java.lang.StringBuilder::append (8 bytes) 58 * 83 3 java.util.TreeMap$ValueIterator::next (8 bytes) 59 * 84 1 javax.management.MBeanFeatureInfo::getName (5 bytes) 60 * ---------------------------- 61 * Contents of C2 compile queue 62 * ---------------------------- 63 * Empty 64 * ---------------------------- 65 * 66 **/ 67 68 public void run(CommandExecutor executor) { 69 70 // Get output from dcmd (diagnostic command) 71 OutputAnalyzer output = executor.execute("Compiler.queue"); 72 Iterator<String> lines = output.asLines().iterator(); 73 74 while (lines.hasNext()) { 75 String str = lines.next(); 76 if (str.startsWith("Contents of C")) { 77 match(lines.next(), "----------------------------"); 78 str = lines.next(); 79 if (!str.equals("Empty")) { 80 while (str.charAt(0) != '-') { 81 validateMethodLine(str); 82 str = lines.next(); 83 } 84 } else { 85 str = lines.next(); 86 } 87 match(str,"----------------------------"); 88 } else { 89 throw new RuntimeException("Failed parsing dcmd queue, line: " + str); 90 } 91 } 92 } 93 94 private static void validateMethodLine(String str) { 95 // Skip until package/class name begins. Trim to remove whitespace that 96 // may differ. 97 String name = str.substring(14).trim(); 98 int sep = name.indexOf("::"); 99 if (sep == -1) { 100 throw new RuntimeException("Failed dcmd queue, didn't find separator :: in: " + name); 101 } 102 try { 103 Class.forName(name.substring(0, sep)); 104 } catch (ClassNotFoundException e) { 105 throw new RuntimeException("Failed dcmd queue, Class for name: " + str); 106 } 107 } 108 109 public static void match(String line, String str) { 110 if (!line.equals(str)) { 111 throw new RuntimeException("String equals: " + line + ", " + str); 112 } 113 } 114 115 @Test 116 public void jmx() { 117 run(new JMXExecutor()); 118 } 119 }