< prev index next >

test/serviceability/dcmd/compiler/CodelistTest.java

Print this page
rev 7754 : 8071908: Port internal Diagnostic Command tests and test framework to jtreg
Reviewed-by:


   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 CodelistTest
  26  * @bug 8054889
  27  * @library ..
  28  * @build DcmdUtil MethodIdentifierParser CodelistTest
  29  * @run main CodelistTest


  30  * @summary Test of diagnostic command Compiler.codelist
  31  */
  32 





  33 import java.io.BufferedReader;
  34 import java.io.StringReader;
  35 import java.lang.reflect.Method;

  36 
  37 public class CodelistTest {
  38 
  39     /**
  40      * This test calls Jcmd (diagnostic command tool) Compiler.codelist and then parses the output,
  41      * making sure that the first methods in the list is valid by reflection.
  42      *
  43      * Output example:
  44      *
  45      * 6 0 java.lang.System.arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V [0x00007f7b49200910, 0x00007f7b49200aa0 - 0x00007f7b49200d30]
  46      * 2 3 java.lang.String.indexOf(II)I [0x00007f7b49200d90, 0x00007f7b49200f60 - 0x00007f7b49201490]
  47      * 7 3 java.lang.Math.min(II)I [0x00007f7b4922f010, 0x00007f7b4922f180 - 0x00007f7b4922f338]
  48      * 8 3 java.lang.String.equals(Ljava/lang/Object;)Z [0x00007f7b4922fb10, 0x00007f7b4922fd40 - 0x00007f7b49230698]
  49      * 9 3 java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V [0x00007f7b49232010, 0x00007f7b492321a0 - 0x00007f7b49232510]
  50      * 10 1 java.lang.Object.<init>()V [0x00007f7b49233e90, 0x00007f7b49233fe0 - 0x00007f7b49234118]
  51      *
  52      */
  53 
  54     public static void main(String arg[]) throws Exception {
  55         int ok   = 0;
  56         int fail = 0;
  57 
  58         // Get output from dcmd (diagnostic command)
  59         String result = DcmdUtil.executeDcmd("Compiler.codelist");
  60         BufferedReader r = new BufferedReader(new StringReader(result));
  61 
  62         // Grab a method name from the output
  63         String line;
  64         int count = 0;
  65 
  66         while((line = r.readLine()) != null) {
  67             count++;
  68 
  69             String[] parts = line.split(" ");
  70             // int compileID = Integer.parseInt(parts[0]);
  71             // int compileLevel = Integer.parseInt(parts[1]);
  72             String methodPrintedInLogFormat = parts[2];
  73 
  74             // skip inits, clinits and methodHandles - they can not be reflected
  75             if (methodPrintedInLogFormat.contains("<init>")) {
  76                 continue;
  77             }
  78             if (methodPrintedInLogFormat.contains("<clinit>")) {
  79                 continue;
  80             }
  81             if (methodPrintedInLogFormat.contains("MethodHandle")) {
  82                 continue;
  83             }
  84 
  85             MethodIdentifierParser mf = new MethodIdentifierParser(methodPrintedInLogFormat);
  86             Method m;
  87             try {
  88                 m = mf.getMethod();
  89             } catch (NoSuchMethodException e) {
  90                 m = null;


  91             }
  92             if (m == null) {
  93                 throw new Exception("Test failed on: " + methodPrintedInLogFormat);
  94             }
  95             if (count > 10) {
  96                 // Testing 10 entries is enough. Lets not waste time.
  97                 break;
  98             }
  99         }





 100     }
 101 }


   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 CodelistTest
  26  * @bug 8054889
  27  * @library /testlibrary
  28  * @build com.oracle.java.testlibrary.*
  29  * @build com.oracle.java.testlibrary.dcmd.*
  30  * @build MethodIdentifierParser
  31  * @run testng CodelistTest
  32  * @summary Test of diagnostic command Compiler.codelist
  33  */
  34 
  35 import com.oracle.java.testlibrary.OutputAnalyzer;
  36 import com.oracle.java.testlibrary.dcmd.CommandExecutor;
  37 import com.oracle.java.testlibrary.dcmd.JMXExecutor;
  38 import org.testng.annotations.Test;
  39 
  40 import java.io.BufferedReader;
  41 import java.io.StringReader;
  42 import java.lang.reflect.Method;
  43 import java.util.Iterator;
  44 
  45 public class CodelistTest {
  46 
  47     /**
  48      * This test calls Jcmd (diagnostic command tool) Compiler.codelist and then parses the output,
  49      * making sure that the first methods in the list is valid by reflection.
  50      *
  51      * Output example:
  52      *
  53      * 6 0 java.lang.System.arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V [0x00007f7b49200910, 0x00007f7b49200aa0 - 0x00007f7b49200d30]
  54      * 2 3 java.lang.String.indexOf(II)I [0x00007f7b49200d90, 0x00007f7b49200f60 - 0x00007f7b49201490]
  55      * 7 3 java.lang.Math.min(II)I [0x00007f7b4922f010, 0x00007f7b4922f180 - 0x00007f7b4922f338]
  56      * 8 3 java.lang.String.equals(Ljava/lang/Object;)Z [0x00007f7b4922fb10, 0x00007f7b4922fd40 - 0x00007f7b49230698]
  57      * 9 3 java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V [0x00007f7b49232010, 0x00007f7b492321a0 - 0x00007f7b49232510]
  58      * 10 1 java.lang.Object.<init>()V [0x00007f7b49233e90, 0x00007f7b49233fe0 - 0x00007f7b49234118]
  59      *
  60      */
  61 
  62     public void run(CommandExecutor executor) {
  63         int ok   = 0;
  64         int fail = 0;
  65 
  66         // Get output from dcmd (diagnostic command)
  67         OutputAnalyzer output = executor.execute("Compiler.codelist");
  68         //Iterator<String> lines = output.asLines().iterator();
  69 
  70         // Grab a method name from the output

  71         int count = 0;
  72 
  73         for (String line : output.asLines()) {
  74             count++;
  75 
  76             String[] parts = line.split(" ");
  77             // int compileID = Integer.parseInt(parts[0]);
  78             // int compileLevel = Integer.parseInt(parts[1]);
  79             String methodPrintedInLogFormat = parts[2];
  80 
  81             // skip inits, clinits and methodHandles - they can not be reflected
  82             if (methodPrintedInLogFormat.contains("<init>")) {
  83                 continue;
  84             }
  85             if (methodPrintedInLogFormat.contains("<clinit>")) {
  86                 continue;
  87             }
  88             if (methodPrintedInLogFormat.contains("MethodHandle")) {
  89                 continue;
  90             }
  91 
  92             MethodIdentifierParser mf = new MethodIdentifierParser(methodPrintedInLogFormat);
  93             Method m;
  94             try {
  95                 m = mf.getMethod();
  96             } catch (NoSuchMethodException e) {
  97                 m = null;
  98             } catch (ClassNotFoundException e) {
  99                 throw new RuntimeException("Test error: Caught unexpected exception", e);
 100             }
 101             if (m == null) {
 102                 throw new RuntimeException("Test failed on: " + methodPrintedInLogFormat);
 103             }
 104             if (count > 10) {
 105                 // Testing 10 entries is enough. Lets not waste time.
 106                 break;
 107             }
 108         }
 109     }
 110 
 111     @Test
 112     public void jmx() {
 113         run(new JMXExecutor());
 114     }
 115 }
< prev index next >