test/serviceability/ParserTest.java

Fri, 23 Mar 2012 11:16:05 -0400

author
coleenp
date
Fri, 23 Mar 2012 11:16:05 -0400
changeset 3682
fc9d8850ab8b
parent 3681
51612f0c0a79
child 3905
5a1f452f8f90
permissions
-rw-r--r--

7150058: Allocate symbols from null boot loader to an arena for NMT
Summary: Move symbol allocation to an arena so NMT doesn't have to track them at startup.
Reviewed-by: never, kamg, zgu

     1 /*
     2  * @test ParserTest
     3  * @summary verify that whitebox functions can be linked and executed
     4  * @run compile -J-XX:+UnlockDiagnosticVMOptions -J-XX:+WhiteBoxAPI ParserTest.java
     5  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ParserTest
     6  */
     8 import java.math.BigInteger;
    10 import sun.hotspot.parser.DiagnosticCommand;
    11 import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType;
    12 import sun.hotspot.WhiteBox;
    14 public class ParserTest {
    15     WhiteBox wb;
    17     public ParserTest() throws Exception {
    18         wb = WhiteBox.getWhiteBox();
    20         testNanoTime();
    21         testJLong();
    22         testBool();
    23         testMemorySize();
    24     }
    26     public static void main(String... args) throws Exception  {
    27          new ParserTest();
    28     }
    30     public void testNanoTime() throws Exception {
    31         String name = "name";
    32         DiagnosticCommand arg = new DiagnosticCommand(name,
    33                 "desc", DiagnosticArgumentType.NANOTIME,
    34                 false, "0");
    35         DiagnosticCommand[] args = {arg};
    37         BigInteger bi = new BigInteger("7");
    38         //These should work
    39         parse(name, bi.toString(), name + "=7ns", args);
    41         bi = bi.multiply(BigInteger.valueOf(1000));
    42         parse(name, bi.toString(), name + "=7us", args);
    44         bi = bi.multiply(BigInteger.valueOf(1000));
    45         parse(name, bi.toString(), name + "=7ms", args);
    47         bi = bi.multiply(BigInteger.valueOf(1000));
    48         parse(name, bi.toString(), name + "=7s", args);
    50         bi = bi.multiply(BigInteger.valueOf(60));
    51         parse(name, bi.toString() , name + "=7m", args);
    53         bi = bi.multiply(BigInteger.valueOf(60));
    54         parse(name, bi.toString() , name + "=7h", args);
    56         bi = bi.multiply(BigInteger.valueOf(24));
    57         parse(name, bi.toString() , name + "=7d", args);
    59         parse(name, "0", name + "=0", args);
    61         shouldFail(name + "=7xs", args);
    62         shouldFail(name + "=7mms", args);
    63         shouldFail(name + "=7f", args);
    64         //Currently, only value 0 is allowed without unit
    65         shouldFail(name + "=7", args);
    66     }
    68     public void testJLong() throws Exception {
    69         String name = "name";
    70         DiagnosticCommand arg = new DiagnosticCommand(name,
    71                 "desc", DiagnosticArgumentType.JLONG,
    72                 false, "0");
    73         DiagnosticCommand[] args = {arg};
    75         wb.parseCommandLine(name + "=10", args);
    76         parse(name, "10", name + "=10", args);
    77         parse(name, "-5", name + "=-5", args);
    79         //shouldFail(name + "=12m", args); <-- should fail, doesn't
    80     }
    82     public void testBool() throws Exception {
    83         String name = "name";
    84         DiagnosticCommand arg = new DiagnosticCommand(name,
    85                 "desc", DiagnosticArgumentType.BOOLEAN,
    86                 false, "false");
    87         DiagnosticCommand[] args = {arg};
    89         parse(name, "true", name + "=true", args);
    90         parse(name, "false", name + "=false", args);
    91         parse(name, "true", name, args);
    93         //Empty commandline to parse, tests default value
    94         //of the parameter "name"
    95         parse(name, "false", "", args);
    96     }
    98     public void testMemorySize() throws Exception {
    99         String name = "name";
   100         String defaultValue = "1024";
   101         DiagnosticCommand arg = new DiagnosticCommand(name,
   102                 "desc", DiagnosticArgumentType.MEMORYSIZE,
   103                 false, defaultValue);
   104         DiagnosticCommand[] args = {arg};
   106         BigInteger bi = new BigInteger("7");
   107         parse(name, bi.toString(), name + "=7b", args);
   109         bi = bi.multiply(BigInteger.valueOf(1024));
   110         parse(name, bi.toString(), name + "=7k", args);
   112         bi = bi.multiply(BigInteger.valueOf(1024));
   113         parse(name, bi.toString(), name + "=7m", args);
   115         bi = bi.multiply(BigInteger.valueOf(1024));
   116         parse(name, bi.toString(), name + "=7g", args);
   117         parse(name, defaultValue, "", args);
   119         //shouldFail(name + "=7gg", args); <---- should fail, doesn't
   120         //shouldFail(name + "=7t", args);  <----- should fail, doesn't
   121     }
   123     public void parse(String searchName, String expectedValue,
   124             String cmdLine, DiagnosticCommand[] argumentTypes) throws Exception {
   125         //parseCommandLine will return an object array that looks like
   126         //{<name of parsed object>, <of parsed object> ... }
   127         Object[] res = wb.parseCommandLine(cmdLine, argumentTypes);
   128         for (int i = 0; i < res.length-1; i+=2) {
   129             String parsedName = (String) res[i];
   130             if (searchName.equals(parsedName)) {
   131                 String parsedValue = (String) res[i+1];
   132                 if (expectedValue.equals(parsedValue)) {
   133                     return;
   134                 } else {
   135                     throw new Exception("Parsing of cmdline '" + cmdLine + "' failed!\n"
   136                             + searchName + " parsed as " + parsedValue
   137                             + "! Expected: " + expectedValue);
   138                 }
   139             }
   140         }
   141         throw new Exception(searchName + " not found as a parsed Argument!");
   142     }
   144     private void shouldFail(String argument, DiagnosticCommand[] argumentTypes) throws Exception {
   145         try {
   146             wb.parseCommandLine(argument, argumentTypes);
   147             throw new Exception("Parser accepted argument: " + argument);
   148         } catch (IllegalArgumentException e) {
   149             //expected
   150         }
   151     }
   152 }

mercurial