1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
|
/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package nsk.share.gc;
import nsk.share.*;
/**
* Parser for GC tests' arguments.
* <p>
* <code>ArgumentHandler</code> handles specific command line arguments
* related to way of execution of a test in addition to general arguments
* recognized by {@link ArgumentParser <code>ArgumentParser</code>}.
* <p>
* Following is the list of specific options for <code>ArgumentHandler</code>:
* <ul>
* <li><code>-iterations="<i>value</i>"</code>, where <i>value</i> must either
* be "infinity", or an integer number, greater than 0. This parameter
* specifies the number of iterations to run the testcase. If the value is
* "infinity", then the test will be run for at least <code>gcTimeout</code>
* minutes. Otherwise, the testcase will be repeated for
* <code>iterations</code> times.
* <li><code>-gcTimeout="<i>value</i>"</code>, where <i>value</i> must be an
* integer number, greater than 0. If <i>infinity</i> is set to
* <code>iterations</code>, then the test consider <code>gcTimeout</code>
* argument to run the test for at least specified number of minutes.
* <li><code>-threads="<i>value</i>"</code>, where <i>value</i> must be an
* integer number, greater than 0. A user may specify the number of threads
* to start in the test with that paramenter. However, a test may ignore
* this value, if it does know the number of threads to start. It
* depends on a test: read its README file.
* <li><code>-memoryEater="<i>value</i>"</code>, where <i>value</i> must be
* either "single", or "multi" string. This argument specifies if a single
* thread should be used to eat the whole heap or not. If "multi" string is
* assigned to <code>-memoryEater</code>, then a number of threads will be
* started to eat the heap. The number is equal to number of available
* processors plus 1.
* <li><code>-largeClassesPath="<i>value</i>"</code>, where <i>value</i> is a
* directory to load large classes from.
* <li><code>-fieldsLimitation="<i>value</i>"</code>, where <i>value</i> must
* be either "over", or "under" string. This argument specifies what classes
* should be loaded from <code>largeClassesPath</code> directory. If
* <i>over</i> is set, then the classes that have number of fileds over
* JVM limitation should be loaded, otherwise -- classes that have number
* of fileds under limitation.
* </ul>
* @see ArgumentParser
*/
public class ArgumentHandler extends ArgumentParser {
// Define all possible arguments
private final static String ITERATIONS = "iterations";
private final static String AGGREGATION_DEPTH = "aggregationDepth";
private final static String GC_TIMEOUT = "gcTimeout";
private final static String THREADS = "threads";
private final static String MEM_EATER = "memoryEater";
private final static String LARGE_CLASSES_PATH = "largeClassesPath";
private final static String FIELDS_LIMITATION = "fieldsLimitation";
// An acceptible value for ITERATIONS
private final static String INFINITY = "infinity";
// Acceptible values for MEM_EATER
private final static String ME_SINGLE = "single";
private final static String ME_MULTI = "multi";
// Acceptible values for FIELDS_LIMITATION
private final static String FL_OVER = "over";
private final static String FL_UNDER = "under";
/**
* Keep a copy of raw command-line arguments and parse them;
* but throw an exception on parsing error.
*
* @param args Array of the raw command-line arguments.
*
* @throws BadOption If unknown option or illegal option value found
*
* @see ArgumentParser
*/
public ArgumentHandler(String args[]) {
super(args);
}
/**
* Returns number of iterations.
* <p>
* If <code>-iterations="<i>infinity</i>"</code>, the method returns -1.
* If the argument is not set, the method returns 1. Otherwise, the
* specified number is returned.
*
* @return number of iterations.
*
*/
public int getIterations() {
String value = options.getProperty(ITERATIONS, "1");
if (INFINITY.equals(value))
return -1;
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
throw new TestBug("Not an integer value of \"" + ITERATIONS
+ "\" argument: " + value);
}
}
/**
* Returns the depth of object aggregation.
* <p>
* If the argument is not set, the method returns 0. Otherwise, the
* specified number is returned.
*
* @return number of aggregation depth.
*
*/
public int getAggregationDepth() {
String value = options.getProperty(AGGREGATION_DEPTH, "0");
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
throw new TestBug("Not an integer value of \"" + AGGREGATION_DEPTH
+ "\" argument: " + value);
}
}
/**
* Returns number of minutes to run the test.
* <p>
* @return number of minutes to run the test.
*
*/
public int getGCTimeout() {
String value = options.getProperty(GC_TIMEOUT);
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
throw new TestBug("\"" + GC_TIMEOUT + "\" argument is not defined "
+ "or is not integer: " + value);
}
}
/**
* Returns a directory to load large classes from.
* <p>
* @return a directory to load large classes from.
*
*/
public String getLargeClassesPath() {
return options.getProperty(LARGE_CLASSES_PATH);
}
/**
* Returns number of threads to start in a test. If <code>threads</code>
* is not set, the method returns specified number of threads.
* <p>
* @param defaultValue default value, if <code>threads</code> is not set.
* @return number of threads to start in a test.
*
*/
public int getThreads(int defaultValue) {
String value = options.getProperty(THREADS);
if (value == null)
return defaultValue;
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
throw new TestBug("Not an integer value of \"" + THREADS
+ "\" argument: " + value);
}
}
/**
* Returns true if single thread should be used to eat the whole heap,
* false otherwise.
*
* @return true if single thread should be used to eat the whole heap,
* false otherwise.
*
*/
public boolean isSingleMemoryEater() {
String value = options.getProperty(MEM_EATER);
if (value == null)
return true;
else if (value.equals(ME_SINGLE))
return true;
else if (value.equals(ME_MULTI))
return false;
else
throw new TestBug("Value for \"" + MEM_EATER + "\" must be either "
+ ME_SINGLE + ", or " + ME_MULTI);
}
/**
* Returns true if classes with number of fileds over limitation should be
* loaded, false otherwise.
*
* @return true if classes with number of fileds over limitation should be
* loaded, false otherwise.
*
*/
public boolean isOverFieldsLimitation() {
String value = options.getProperty(FIELDS_LIMITATION);
if (value == null)
return false;
else if (value.equals(FL_OVER))
return true;
else if (value.equals(FL_UNDER))
return false;
else
throw new TestBug("Value for \"" + FIELDS_LIMITATION + "\" must be "
+ "either " + FL_OVER + ", or " + FL_UNDER);
}
/**
* Checks if an option is allowed and has proper value.
* This method is invoked by <code>parseArguments()</code>
*
* @param option option name
* @param value string representation of value
* (could be an empty string too)
* null if this option has no value
* @return <i>true</i> if option is allowed and has proper value,
* <i>false</i> if option is not admissible
*
* @throws <i>BadOption</i> if option has an illegal value
*
* @see #parseArguments()
*/
protected boolean checkOption(String option, String value) {
// Define iterations
if (option.equals(ITERATIONS)) {
if (INFINITY.equals(value))
return true;
try {
int number = Integer.parseInt(value);
if (number < 1)
throw new BadOption(option + ": value must be greater than "
+ "zero.");
} catch (NumberFormatException e) {
throw new BadOption("Value for option \"" + option + "\" must "
+ "be integer or \"" + INFINITY + "\": "
+ value);
}
return true;
}
// Define timeout
if (option.equals(GC_TIMEOUT)) {
try {
int number = Integer.parseInt(value);
if (number < 0)
throw new BadOption(option + ": value must be a positive "
+ "integer");
} catch (NumberFormatException e) {
throw new BadOption("Value for option \"" + option + "\" must "
+ "be integer: " + value);
}
return true;
}
// Define threads
if (option.equals(THREADS)) {
try {
int number = Integer.parseInt(value);
if (number < 0)
throw new BadOption(option + ": value must be a positive "
+ "integer");
} catch (NumberFormatException e) {
throw new BadOption("Value for option \"" + option + "\" must "
+ "be integer: " + value);
}
return true;
}
// Define path to large classes
if (option.equals(LARGE_CLASSES_PATH))
return true;
// Define memory eater
if (option.equals(MEM_EATER)) {
if ( (ME_SINGLE.equals(value)) || (ME_MULTI.equals(value)) )
return true;
else
throw new BadOption("Value for option \"" + option + "\" must "
+ "be either " + ME_SINGLE + ", or "
+ ME_MULTI + ": " + value);
}
// Define fields limitation
if (option.equals(FIELDS_LIMITATION)) {
if ( (FL_OVER.equals(value)) || (FL_UNDER.equals(value)) )
return true;
else
throw new BadOption("Value for option \"" + option + "\" must "
+ "be either " + FL_OVER + ", or "
+ FL_UNDER + ": " + value);
}
// Define aggregationDepth
if (option.equals(AGGREGATION_DEPTH)) {
try {
int number = Integer.parseInt(value);
if (number < 0)
throw new BadOption(option + ": value must be a positive "
+ "integer");
} catch (NumberFormatException e) {
throw new BadOption("Value for option \"" + option + "\" must "
+ "be integer: " + value);
}
return true;
}
return super.checkOption(option, value);
}
/**
* Checks if the values of all options are consistent.
* This method is invoked by <code>parseArguments()</code>
*
* @throws <i>BadOption</i> if options have inconsistent values
*
* @see ArgumentParser#parseArguments()
*/
protected void checkOptions() {
super.checkOptions();
}
} // ArgumentHandler
|