hotspot/test/serviceability/dcmd/compiler/CodeCacheTest.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 CodeCacheTest
    25  * @test CodeCacheTest
    26  * @bug 8054889
    26  * @bug 8054889
    27  * @library ..
    27  * @library /testlibrary
    28  * @build DcmdUtil CodeCacheTest
    28  * @build com.oracle.java.testlibrary.*
    29  * @run main/othervm -XX:+SegmentedCodeCache CodeCacheTest
    29  * @build com.oracle.java.testlibrary.dcmd.*
    30  * @run main/othervm -XX:-SegmentedCodeCache CodeCacheTest
    30  * @run testng/othervm -XX:+SegmentedCodeCache CodeCacheTest
    31  * @run main/othervm -Xint -XX:+SegmentedCodeCache CodeCacheTest
    31  * @run testng/othervm -XX:-SegmentedCodeCache CodeCacheTest
       
    32  * @run testng/othervm -Xint -XX:+SegmentedCodeCache CodeCacheTest
    32  * @summary Test of diagnostic command Compiler.codecache
    33  * @summary Test of diagnostic command Compiler.codecache
    33  */
    34  */
    34 
    35 
    35 import java.io.BufferedReader;
    36 import org.testng.annotations.Test;
    36 import java.io.StringReader;
    37 import org.testng.Assert;
    37 import java.lang.reflect.Method;
    38 
       
    39 import com.oracle.java.testlibrary.OutputAnalyzer;
       
    40 import com.oracle.java.testlibrary.dcmd.CommandExecutor;
       
    41 import com.oracle.java.testlibrary.dcmd.JMXExecutor;
       
    42 
       
    43 import java.util.Iterator;
    38 import java.util.regex.Matcher;
    44 import java.util.regex.Matcher;
    39 import java.util.regex.Pattern;
    45 import java.util.regex.Pattern;
    40 
    46 
    41 public class CodeCacheTest {
    47 public class CodeCacheTest {
    42 
    48 
    70     static Pattern line4 = Pattern.compile(" compilation: (.*)");
    76     static Pattern line4 = Pattern.compile(" compilation: (.*)");
    71 
    77 
    72     private static boolean getFlagBool(String flag, String where) {
    78     private static boolean getFlagBool(String flag, String where) {
    73       Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where);
    79       Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where);
    74       if (!m.find()) {
    80       if (!m.find()) {
    75         throw new RuntimeException("Could not find value for flag " + flag + " in output string");
    81         Assert.fail("Could not find value for flag " + flag + " in output string");
    76       }
    82       }
    77       return m.group(1).equals("true");
    83       return m.group(1).equals("true");
    78     }
    84     }
    79 
    85 
    80     private static int getFlagInt(String flag, String where) {
    86     private static int getFlagInt(String flag, String where) {
    81       Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
    87       Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
    82       if (!m.find()) {
    88       if (!m.find()) {
    83         throw new RuntimeException("Could not find value for flag " + flag + " in output string");
    89         Assert.fail("Could not find value for flag " + flag + " in output string");
    84       }
    90       }
    85       String match = m.group();
    91       String match = m.group();
    86       return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));
    92       return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));
    87     }
    93     }
    88 
    94 
    89     public static void main(String arg[]) throws Exception {
    95     public void run(CommandExecutor executor) {
    90         // Get number of code cache segments
    96         // Get number of code cache segments
    91         int segmentsCount = 0;
    97         int segmentsCount = 0;
    92         String flags = DcmdUtil.executeDcmd("VM.flags", "-all");
    98         String flags = executor.execute("VM.flags -all").getOutput();
    93         if (!getFlagBool("SegmentedCodeCache", flags) || !getFlagBool("UseCompiler", flags)) {
    99         if (!getFlagBool("SegmentedCodeCache", flags) || !getFlagBool("UseCompiler", flags)) {
    94           // No segmentation
   100           // No segmentation
    95           segmentsCount = 1;
   101           segmentsCount = 1;
    96         } else if (getFlagBool("TieredCompilation", flags) && getFlagInt("TieredStopAtLevel", flags) > 1) {
   102         } else if (getFlagBool("TieredCompilation", flags) && getFlagInt("TieredStopAtLevel", flags) > 1) {
    97           // Tiered compilation: use all segments
   103           // Tiered compilation: use all segments
   100           // No TieredCompilation: only non-nmethod and non-profiled segment
   106           // No TieredCompilation: only non-nmethod and non-profiled segment
   101           segmentsCount = 2;
   107           segmentsCount = 2;
   102         }
   108         }
   103 
   109 
   104         // Get output from dcmd (diagnostic command)
   110         // Get output from dcmd (diagnostic command)
   105         String result = DcmdUtil.executeDcmd("Compiler.codecache");
   111         OutputAnalyzer output = executor.execute("Compiler.codecache");
   106         BufferedReader r = new BufferedReader(new StringReader(result));
   112         Iterator<String> lines = output.asLines().iterator();
   107 
   113 
   108         // Validate code cache segments
   114         // Validate code cache segments
   109         String line;
   115         String line;
   110         Matcher m;
   116         Matcher m;
   111         for (int s = 0; s < segmentsCount; ++s) {
   117         for (int s = 0; s < segmentsCount; ++s) {
   112           // Validate first line
   118           // Validate first line
   113           line = r.readLine();
   119           line = lines.next();
   114           m = line1.matcher(line);
   120           m = line1.matcher(line);
   115           if (m.matches()) {
   121           if (m.matches()) {
   116               for (int i = 2; i <= 5; i++) {
   122               for (int i = 2; i <= 5; i++) {
   117                   int val = Integer.parseInt(m.group(i));
   123                   int val = Integer.parseInt(m.group(i));
   118                   if (val < 0) {
   124                   if (val < 0) {
   119                       throw new Exception("Failed parsing dcmd codecache output");
   125                       Assert.fail("Failed parsing dcmd codecache output");
   120                   }
   126                   }
   121               }
   127               }
   122           } else {
   128           } else {
   123               throw new Exception("Regexp 1 failed");
   129               Assert.fail("Regexp 1 failed to match line: " + line);
   124           }
   130           }
   125 
   131 
   126           // Validate second line
   132           // Validate second line
   127           line = r.readLine();
   133           line = lines.next();
   128           m = line2.matcher(line);
   134           m = line2.matcher(line);
   129           if (m.matches()) {
   135           if (m.matches()) {
   130               String start = m.group(1);
   136               String start = m.group(1);
   131               String mark  = m.group(2);
   137               String mark  = m.group(2);
   132               String top   = m.group(3);
   138               String top   = m.group(3);
   133 
   139 
   134               // Lexical compare of hex numbers to check that they look sane.
   140               // Lexical compare of hex numbers to check that they look sane.
   135               if (start.compareTo(mark) > 1) {
   141               if (start.compareTo(mark) > 1) {
   136                   throw new Exception("Failed parsing dcmd codecache output");
   142                   Assert.fail("Failed parsing dcmd codecache output");
   137               }
   143               }
   138               if (mark.compareTo(top) > 1) {
   144               if (mark.compareTo(top) > 1) {
   139                   throw new Exception("Failed parsing dcmd codecache output");
   145                   Assert.fail("Failed parsing dcmd codecache output");
   140               }
   146               }
   141           } else {
   147           } else {
   142               throw new Exception("Regexp 2 failed line: " + line);
   148               Assert.fail("Regexp 2 failed to match line: " + line);
   143           }
   149           }
   144         }
   150         }
   145 
   151 
   146         // Validate third line
   152         // Validate third line
   147         line = r.readLine();
   153         line = lines.next();
   148         m = line3.matcher(line);
   154         m = line3.matcher(line);
   149         if (m.matches()) {
   155         if (m.matches()) {
   150             int blobs = Integer.parseInt(m.group(1));
   156             int blobs = Integer.parseInt(m.group(1));
   151             if (blobs <= 0) {
   157             if (blobs <= 0) {
   152                 throw new Exception("Failed parsing dcmd codecache output");
   158                 Assert.fail("Failed parsing dcmd codecache output");
   153             }
   159             }
   154             int nmethods = Integer.parseInt(m.group(2));
   160             int nmethods = Integer.parseInt(m.group(2));
   155             if (nmethods < 0) {
   161             if (nmethods < 0) {
   156                 throw new Exception("Failed parsing dcmd codecache output");
   162                 Assert.fail("Failed parsing dcmd codecache output");
   157             }
   163             }
   158             int adapters = Integer.parseInt(m.group(3));
   164             int adapters = Integer.parseInt(m.group(3));
   159             if (adapters <= 0) {
   165             if (adapters <= 0) {
   160                 throw new Exception("Failed parsing dcmd codecache output");
   166                 Assert.fail("Failed parsing dcmd codecache output");
   161             }
   167             }
   162             if (blobs < (nmethods + adapters)) {
   168             if (blobs < (nmethods + adapters)) {
   163                 throw new Exception("Failed parsing dcmd codecache output");
   169                 Assert.fail("Failed parsing dcmd codecache output");
   164             }
   170             }
   165         } else {
   171         } else {
   166             throw new Exception("Regexp 3 failed");
   172             Assert.fail("Regexp 3 failed to match line: " + line);
   167         }
   173         }
   168 
   174 
   169         // Validate fourth line
   175         // Validate fourth line
   170         line = r.readLine();
   176         line = lines.next();
   171         m = line4.matcher(line);
   177         m = line4.matcher(line);
   172         if (!m.matches()) {
   178         if (!m.matches()) {
   173             throw new Exception("Regexp 4 failed");
   179             Assert.fail("Regexp 4 failed to match line: " + line);
   174         }
   180         }
   175     }
   181     }
       
   182 
       
   183     @Test
       
   184     public void jmx() {
       
   185         run(new JMXExecutor());
       
   186     }
   176 }
   187 }