hotspot/test/serviceability/dcmd/compiler/CodelistTest.java
changeset 28821 f7820f311663
parent 26941 96aa76b27b9c
child 29678 dd2f3932c21e
equal deleted inserted replaced
28820:1837a69c2a22 28821:f7820f311663
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test CodelistTest
    25  * @test CodelistTest
    26  * @bug 8054889
    26  * @bug 8054889
    27  * @library ..
    27  * @library /testlibrary
    28  * @build DcmdUtil MethodIdentifierParser CodelistTest
    28  * @build com.oracle.java.testlibrary.*
    29  * @run main CodelistTest
    29  * @build com.oracle.java.testlibrary.dcmd.*
       
    30  * @build MethodIdentifierParser
       
    31  * @run testng CodelistTest
    30  * @summary Test of diagnostic command Compiler.codelist
    32  * @summary Test of diagnostic command Compiler.codelist
    31  */
    33  */
    32 
    34 
    33 import java.io.BufferedReader;
    35 import org.testng.annotations.Test;
    34 import java.io.StringReader;
    36 import org.testng.Assert;
       
    37 
       
    38 import com.oracle.java.testlibrary.OutputAnalyzer;
       
    39 import com.oracle.java.testlibrary.dcmd.CommandExecutor;
       
    40 import com.oracle.java.testlibrary.dcmd.JMXExecutor;
       
    41 
    35 import java.lang.reflect.Method;
    42 import java.lang.reflect.Method;
    36 
    43 
    37 public class CodelistTest {
    44 public class CodelistTest {
    38 
    45 
    39     /**
    46     /**
    49      * 9 3 java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V [0x00007f7b49232010, 0x00007f7b492321a0 - 0x00007f7b49232510]
    56      * 9 3 java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V [0x00007f7b49232010, 0x00007f7b492321a0 - 0x00007f7b49232510]
    50      * 10 1 java.lang.Object.<init>()V [0x00007f7b49233e90, 0x00007f7b49233fe0 - 0x00007f7b49234118]
    57      * 10 1 java.lang.Object.<init>()V [0x00007f7b49233e90, 0x00007f7b49233fe0 - 0x00007f7b49234118]
    51      *
    58      *
    52      */
    59      */
    53 
    60 
    54     public static void main(String arg[]) throws Exception {
    61     public void run(CommandExecutor executor) {
    55         int ok   = 0;
    62         int ok   = 0;
    56         int fail = 0;
    63         int fail = 0;
    57 
    64 
    58         // Get output from dcmd (diagnostic command)
    65         // Get output from dcmd (diagnostic command)
    59         String result = DcmdUtil.executeDcmd("Compiler.codelist");
    66         OutputAnalyzer output = executor.execute("Compiler.codelist");
    60         BufferedReader r = new BufferedReader(new StringReader(result));
       
    61 
    67 
    62         // Grab a method name from the output
    68         // Grab a method name from the output
    63         String line;
       
    64         int count = 0;
    69         int count = 0;
    65 
    70 
    66         while((line = r.readLine()) != null) {
    71         for (String line : output.asLines()) {
    67             count++;
    72             count++;
    68 
    73 
    69             String[] parts = line.split(" ");
    74             String[] parts = line.split(" ");
    70             // int compileID = Integer.parseInt(parts[0]);
    75             // int compileID = Integer.parseInt(parts[0]);
    71             // int compileLevel = Integer.parseInt(parts[1]);
    76             // int compileLevel = Integer.parseInt(parts[1]);
    81             if (methodPrintedInLogFormat.contains("MethodHandle")) {
    86             if (methodPrintedInLogFormat.contains("MethodHandle")) {
    82                 continue;
    87                 continue;
    83             }
    88             }
    84 
    89 
    85             MethodIdentifierParser mf = new MethodIdentifierParser(methodPrintedInLogFormat);
    90             MethodIdentifierParser mf = new MethodIdentifierParser(methodPrintedInLogFormat);
    86             Method m;
    91             Method m = null;
    87             try {
    92             try {
    88                 m = mf.getMethod();
    93                 m = mf.getMethod();
    89             } catch (NoSuchMethodException e) {
    94             } catch (NoSuchMethodException e) {
    90                 m = null;
    95                 m = null;
       
    96             } catch (ClassNotFoundException e) {
       
    97                 Assert.fail("Test error: Caught unexpected exception", e);
    91             }
    98             }
    92             if (m == null) {
    99             if (m == null) {
    93                 throw new Exception("Test failed on: " + methodPrintedInLogFormat);
   100                 Assert.fail("Test failed on: " + methodPrintedInLogFormat);
    94             }
   101             }
    95             if (count > 10) {
   102             if (count > 10) {
    96                 // Testing 10 entries is enough. Lets not waste time.
   103                 // Testing 10 entries is enough. Lets not waste time.
    97                 break;
   104                 break;
    98             }
   105             }
    99         }
   106         }
   100     }
   107     }
       
   108 
       
   109     @Test
       
   110     public void jmx() {
       
   111         run(new JMXExecutor());
       
   112     }
   101 }
   113 }