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 */
7
8 import java.math.BigInteger;
9
10 import sun.hotspot.parser.DiagnosticCommand;
11 import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType;
12 import sun.hotspot.WhiteBox;
13
14 public class ParserTest {
15 WhiteBox wb;
16
17 public ParserTest() throws Exception {
18 wb = WhiteBox.getWhiteBox();
19
20 testNanoTime();
21 testJLong();
22 testBool();
23 testMemorySize();
24 }
25
26 public static void main(String... args) throws Exception {
27 new ParserTest();
28 }
29
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};
36
37 BigInteger bi = new BigInteger("7");
38 //These should work
39 parse(name, bi.toString(), name + "=7ns", args);
40
41 bi = bi.multiply(BigInteger.valueOf(1000));
42 parse(name, bi.toString(), name + "=7us", args);
78
79 //shouldFail(name + "=12m", args); <-- should fail, doesn't
80 }
81
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};
88
89 parse(name, "true", name + "=true", args);
90 parse(name, "false", name + "=false", args);
91 parse(name, "true", name, args);
92
93 //Empty commandline to parse, tests default value
94 //of the parameter "name"
95 parse(name, "false", "", args);
96 }
97
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};
105
106 BigInteger bi = new BigInteger("7");
107 parse(name, bi.toString(), name + "=7b", args);
108
109 bi = bi.multiply(BigInteger.valueOf(1024));
110 parse(name, bi.toString(), name + "=7k", args);
111
112 bi = bi.multiply(BigInteger.valueOf(1024));
113 parse(name, bi.toString(), name + "=7m", args);
114
115 bi = bi.multiply(BigInteger.valueOf(1024));
116 parse(name, bi.toString(), name + "=7g", args);
117 parse(name, defaultValue, "", args);
|
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 */
7
8 import java.math.BigInteger;
9
10 import sun.hotspot.parser.DiagnosticCommand;
11 import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType;
12 import sun.hotspot.WhiteBox;
13
14 public class ParserTest {
15 WhiteBox wb;
16
17 public ParserTest() throws Exception {
18 wb = WhiteBox.getWhiteBox();
19
20 testNanoTime();
21 testJLong();
22 testBool();
23 testQuotes();
24 testMemorySize();
25 }
26
27 public static void main(String... args) throws Exception {
28 new ParserTest();
29 }
30
31 public void testNanoTime() throws Exception {
32 String name = "name";
33 DiagnosticCommand arg = new DiagnosticCommand(name,
34 "desc", DiagnosticArgumentType.NANOTIME,
35 false, "0");
36 DiagnosticCommand[] args = {arg};
37
38 BigInteger bi = new BigInteger("7");
39 //These should work
40 parse(name, bi.toString(), name + "=7ns", args);
41
42 bi = bi.multiply(BigInteger.valueOf(1000));
43 parse(name, bi.toString(), name + "=7us", args);
79
80 //shouldFail(name + "=12m", args); <-- should fail, doesn't
81 }
82
83 public void testBool() throws Exception {
84 String name = "name";
85 DiagnosticCommand arg = new DiagnosticCommand(name,
86 "desc", DiagnosticArgumentType.BOOLEAN,
87 false, "false");
88 DiagnosticCommand[] args = {arg};
89
90 parse(name, "true", name + "=true", args);
91 parse(name, "false", name + "=false", args);
92 parse(name, "true", name, args);
93
94 //Empty commandline to parse, tests default value
95 //of the parameter "name"
96 parse(name, "false", "", args);
97 }
98
99 public void testQuotes() throws Exception {
100 String name = "name";
101 DiagnosticCommand arg1 = new DiagnosticCommand(name,
102 "desc", DiagnosticArgumentType.STRING,
103 false, null);
104 DiagnosticCommand arg2 = new DiagnosticCommand("arg",
105 "desc", DiagnosticArgumentType.STRING,
106 false, null);
107 DiagnosticCommand[] args = {arg1, arg2};
108
109 // try with a quoted value
110 parse(name, "Recording 1", name + "=\"Recording 1\"", args);
111 // try with a quoted argument
112 parse(name, "myrec", "\"" + name + "\"" + "=myrec", args);
113 // try with both a quoted value and a quoted argument
114 parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\"", args);
115
116 // now the same thing but with other arguments after
117
118 // try with a quoted value
119 parse(name, "Recording 1", name + "=\"Recording 1\",arg=value", args);
120 // try with a quoted argument
121 parse(name, "myrec", "\"" + name + "\"" + "=myrec,arg=value", args);
122 // try with both a quoted value and a quoted argument
123 parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\",arg=value", args);
124 }
125
126 public void testMemorySize() throws Exception {
127 String name = "name";
128 String defaultValue = "1024";
129 DiagnosticCommand arg = new DiagnosticCommand(name,
130 "desc", DiagnosticArgumentType.MEMORYSIZE,
131 false, defaultValue);
132 DiagnosticCommand[] args = {arg};
133
134 BigInteger bi = new BigInteger("7");
135 parse(name, bi.toString(), name + "=7b", args);
136
137 bi = bi.multiply(BigInteger.valueOf(1024));
138 parse(name, bi.toString(), name + "=7k", args);
139
140 bi = bi.multiply(BigInteger.valueOf(1024));
141 parse(name, bi.toString(), name + "=7m", args);
142
143 bi = bi.multiply(BigInteger.valueOf(1024));
144 parse(name, bi.toString(), name + "=7g", args);
145 parse(name, defaultValue, "", args);
|