test/serviceability/ParserTest.java

Mon, 28 Jul 2014 15:06:38 -0700

author
fzhinkin
date
Mon, 28 Jul 2014 15:06:38 -0700
changeset 6997
dbb05f6d93c4
parent 6717
09f19d3de485
child 6876
710a3c8b516e
permissions
-rw-r--r--

8051344: JVM crashed in Compile::start() during method parsing w/ UseRTMDeopt turned on
Summary: call rtm_deopt() only if there were no compilation bailouts before.
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 2012, 2013, 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  */
    24 /*
    25  * @test
    26  * @summary Test that the diagnostic command arguemnt parser works
    27  * @library /testlibrary /testlibrary/whitebox
    28  * @build ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.parser.*
    29  * @run main ClassFileInstaller sun.hotspot.WhiteBox
    30  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ParserTest
    31  */
    33 import java.math.BigInteger;
    35 import sun.hotspot.parser.DiagnosticCommand;
    36 import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType;
    37 import sun.hotspot.WhiteBox;
    39 public class ParserTest {
    40     WhiteBox wb;
    42     public ParserTest() throws Exception {
    43         wb = WhiteBox.getWhiteBox();
    45         testNanoTime();
    46         testJLong();
    47         testBool();
    48         testQuotes();
    49         testMemorySize();
    50     }
    52     public static void main(String... args) throws Exception  {
    53          new ParserTest();
    54     }
    56     public void testNanoTime() throws Exception {
    57         String name = "name";
    58         DiagnosticCommand arg = new DiagnosticCommand(name,
    59                 "desc", DiagnosticArgumentType.NANOTIME,
    60                 false, "0");
    61         DiagnosticCommand[] args = {arg};
    63         BigInteger bi = new BigInteger("7");
    64         //These should work
    65         parse(name, bi.toString(), name + "=7ns", args);
    67         bi = bi.multiply(BigInteger.valueOf(1000));
    68         parse(name, bi.toString(), name + "=7us", args);
    70         bi = bi.multiply(BigInteger.valueOf(1000));
    71         parse(name, bi.toString(), name + "=7ms", args);
    73         bi = bi.multiply(BigInteger.valueOf(1000));
    74         parse(name, bi.toString(), name + "=7s", args);
    76         bi = bi.multiply(BigInteger.valueOf(60));
    77         parse(name, bi.toString() , name + "=7m", args);
    79         bi = bi.multiply(BigInteger.valueOf(60));
    80         parse(name, bi.toString() , name + "=7h", args);
    82         bi = bi.multiply(BigInteger.valueOf(24));
    83         parse(name, bi.toString() , name + "=7d", args);
    85         parse(name, "0", name + "=0", args);
    87         shouldFail(name + "=7xs", args);
    88         shouldFail(name + "=7mms", args);
    89         shouldFail(name + "=7f", args);
    90         //Currently, only value 0 is allowed without unit
    91         shouldFail(name + "=7", args);
    92     }
    94     public void testJLong() throws Exception {
    95         String name = "name";
    96         DiagnosticCommand arg = new DiagnosticCommand(name,
    97                 "desc", DiagnosticArgumentType.JLONG,
    98                 false, "0");
    99         DiagnosticCommand[] args = {arg};
   101         wb.parseCommandLine(name + "=10", args);
   102         parse(name, "10", name + "=10", args);
   103         parse(name, "-5", name + "=-5", args);
   105         //shouldFail(name + "=12m", args); <-- should fail, doesn't
   106     }
   108     public void testBool() throws Exception {
   109         String name = "name";
   110         DiagnosticCommand arg = new DiagnosticCommand(name,
   111                 "desc", DiagnosticArgumentType.BOOLEAN,
   112                 false, "false");
   113         DiagnosticCommand[] args = {arg};
   115         parse(name, "true", name + "=true", args);
   116         parse(name, "false", name + "=false", args);
   117         parse(name, "true", name, args);
   119         //Empty commandline to parse, tests default value
   120         //of the parameter "name"
   121         parse(name, "false", "", args);
   122     }
   124     public void testQuotes() throws Exception {
   125         String name = "name";
   126         DiagnosticCommand arg1 = new DiagnosticCommand(name,
   127                 "desc", DiagnosticArgumentType.STRING,
   128                 false, null);
   129         DiagnosticCommand arg2 = new DiagnosticCommand("arg",
   130                 "desc", DiagnosticArgumentType.STRING,
   131                 false, null);
   132         DiagnosticCommand[] args = {arg1, arg2};
   134         // try with a quoted value
   135         parse(name, "Recording 1", name + "=\"Recording 1\"", args);
   136         // try with a quoted argument
   137         parse(name, "myrec", "\"" + name + "\"" + "=myrec", args);
   138         // try with both a quoted value and a quoted argument
   139         parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\"", args);
   141         // now the same thing but with other arguments after
   143         // try with a quoted value
   144         parse(name, "Recording 1", name + "=\"Recording 1\",arg=value", args);
   145         // try with a quoted argument
   146         parse(name, "myrec", "\"" + name + "\"" + "=myrec,arg=value", args);
   147         // try with both a quoted value and a quoted argument
   148         parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\",arg=value", args);
   149     }
   151     public void testMemorySize() throws Exception {
   152         String name = "name";
   153         String defaultValue = "1024";
   154         DiagnosticCommand arg = new DiagnosticCommand(name,
   155                 "desc", DiagnosticArgumentType.MEMORYSIZE,
   156                 false, defaultValue);
   157         DiagnosticCommand[] args = {arg};
   159         BigInteger bi = new BigInteger("7");
   160         parse(name, bi.toString(), name + "=7b", args);
   162         bi = bi.multiply(BigInteger.valueOf(1024));
   163         parse(name, bi.toString(), name + "=7k", args);
   165         bi = bi.multiply(BigInteger.valueOf(1024));
   166         parse(name, bi.toString(), name + "=7m", args);
   168         bi = bi.multiply(BigInteger.valueOf(1024));
   169         parse(name, bi.toString(), name + "=7g", args);
   170         parse(name, defaultValue, "", args);
   172         //shouldFail(name + "=7gg", args); <---- should fail, doesn't
   173         //shouldFail(name + "=7t", args);  <----- should fail, doesn't
   174     }
   176     public void parse(String searchName, String expectedValue,
   177             String cmdLine, DiagnosticCommand[] argumentTypes) throws Exception {
   178         //parseCommandLine will return an object array that looks like
   179         //{<name of parsed object>, <of parsed object> ... }
   180         Object[] res = wb.parseCommandLine(cmdLine, argumentTypes);
   181         for (int i = 0; i < res.length-1; i+=2) {
   182             String parsedName = (String) res[i];
   183             if (searchName.equals(parsedName)) {
   184                 String parsedValue = (String) res[i+1];
   185                 if (expectedValue.equals(parsedValue)) {
   186                     return;
   187                 } else {
   188                     throw new Exception("Parsing of cmdline '" + cmdLine + "' failed!\n"
   189                             + searchName + " parsed as " + parsedValue
   190                             + "! Expected: " + expectedValue);
   191                 }
   192             }
   193         }
   194         throw new Exception(searchName + " not found as a parsed Argument!");
   195     }
   197     private void shouldFail(String argument, DiagnosticCommand[] argumentTypes) throws Exception {
   198         try {
   199             wb.parseCommandLine(argument, argumentTypes);
   200             throw new Exception("Parser accepted argument: " + argument);
   201         } catch (IllegalArgumentException e) {
   202             //expected
   203         }
   204     }
   205 }

mercurial