< prev index next >

test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOption.java

Print this page


  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  */
  23 package optionsvalidation;
  24 
  25 import com.sun.tools.attach.VirtualMachine;
  26 import com.sun.tools.attach.AttachOperationFailedException;
  27 import java.util.ArrayList;
  28 import java.util.Arrays;
  29 import java.util.HashSet;
  30 import java.util.List;
  31 import java.util.Set;
  32 import jdk.test.lib.management.DynamicVMOption;
  33 import jdk.test.lib.process.OutputAnalyzer;
  34 import jdk.test.lib.process.ProcessTools;
  35 import jdk.test.lib.dcmd.CommandExecutor;
  36 import jdk.test.lib.dcmd.JMXExecutor;

  37 import sun.tools.attach.HotSpotVirtualMachine;
  38 
  39 import static optionsvalidation.JVMOptionsUtils.failedMessage;
  40 import static optionsvalidation.JVMOptionsUtils.GCType;
  41 import static optionsvalidation.JVMOptionsUtils.printOutputContent;
  42 import static optionsvalidation.JVMOptionsUtils.VMType;
  43 
  44 public abstract class JVMOption {
  45 
  46     /**
  47      * Executor for JCMD
  48      */
  49     private final static CommandExecutor executor = new JMXExecutor();
  50 
  51     /**
  52      * Name of the tested parameter
  53      */
  54     protected String name;
  55 
  56     /**


 365 
 366     /**
 367      * Run java with passed parameter and check the result depending on the
 368      * 'valid' parameter
 369      *
 370      * @param param tested parameter passed to the JVM
 371      * @param valid indicates whether the JVM should fail or not
 372      * @return true - if test passed
 373      * @throws Exception if java process can not be started
 374      */
 375     private boolean runJavaWithParam(String optionValue, boolean valid) throws Exception {
 376         int exitCode = 0;
 377         boolean result = true;
 378         String errorMessage = null;
 379         String explicitGC = null;
 380         List<String> runJava = new ArrayList<>();
 381         OutputAnalyzer out = null;
 382 
 383         if (VMType != null) {
 384             runJava.add(VMType);











 385         }
 386 
 387         if (GCType != null &&
 388             !(prepend.contains("-XX:+UseConcMarkSweepGC") ||
 389               prepend.contains("-XX:+UseSerialGC") ||
 390               prepend.contains("-XX:+UseParallelGC") ||
 391               prepend.contains("-XX:+UseG1GC"))) {
 392             explicitGC = GCType;
 393         }
 394 
 395         if (explicitGC != null) {
 396             runJava.add(explicitGC);
 397         }
 398 
 399         runJava.addAll(prepend);
 400         runJava.add(optionValue);
 401         runJava.add(JVMStartup.class.getName());
 402 
 403         out = new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(runJava.toArray(new String[0])).start());
 404 




  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  */
  23 package optionsvalidation;
  24 
  25 import com.sun.tools.attach.VirtualMachine;
  26 import com.sun.tools.attach.AttachOperationFailedException;
  27 import java.util.ArrayList;
  28 import java.util.Arrays;
  29 import java.util.HashSet;
  30 import java.util.List;
  31 import java.util.Set;
  32 import jdk.test.lib.management.DynamicVMOption;
  33 import jdk.test.lib.process.OutputAnalyzer;
  34 import jdk.test.lib.process.ProcessTools;
  35 import jdk.test.lib.dcmd.CommandExecutor;
  36 import jdk.test.lib.dcmd.JMXExecutor;
  37 import jdk.test.lib.Platform;
  38 import sun.tools.attach.HotSpotVirtualMachine;
  39 
  40 import static optionsvalidation.JVMOptionsUtils.failedMessage;
  41 import static optionsvalidation.JVMOptionsUtils.GCType;
  42 import static optionsvalidation.JVMOptionsUtils.printOutputContent;
  43 import static optionsvalidation.JVMOptionsUtils.VMType;
  44 
  45 public abstract class JVMOption {
  46 
  47     /**
  48      * Executor for JCMD
  49      */
  50     private final static CommandExecutor executor = new JMXExecutor();
  51 
  52     /**
  53      * Name of the tested parameter
  54      */
  55     protected String name;
  56 
  57     /**


 366 
 367     /**
 368      * Run java with passed parameter and check the result depending on the
 369      * 'valid' parameter
 370      *
 371      * @param param tested parameter passed to the JVM
 372      * @param valid indicates whether the JVM should fail or not
 373      * @return true - if test passed
 374      * @throws Exception if java process can not be started
 375      */
 376     private boolean runJavaWithParam(String optionValue, boolean valid) throws Exception {
 377         int exitCode = 0;
 378         boolean result = true;
 379         String errorMessage = null;
 380         String explicitGC = null;
 381         List<String> runJava = new ArrayList<>();
 382         OutputAnalyzer out = null;
 383 
 384         if (VMType != null) {
 385             runJava.add(VMType);
 386         }
 387 
 388         // Run with a small heap to avoid excessive execution time
 389         long max = Runtime.getRuntime().maxMemory() / 1024 / 1024;
 390         if (max > 1024) {
 391           runJava.add("-Xmx1024m");
 392         }
 393 
 394         if (Platform.isDebugBuild()) {
 395           // Avoid excessive execution time.
 396           runJava.add("-XX:-ZapUnusedHeapArea");
 397         }
 398 
 399         if (GCType != null &&
 400             !(prepend.contains("-XX:+UseConcMarkSweepGC") ||
 401               prepend.contains("-XX:+UseSerialGC") ||
 402               prepend.contains("-XX:+UseParallelGC") ||
 403               prepend.contains("-XX:+UseG1GC"))) {
 404             explicitGC = GCType;
 405         }
 406 
 407         if (explicitGC != null) {
 408             runJava.add(explicitGC);
 409         }
 410 
 411         runJava.addAll(prepend);
 412         runJava.add(optionValue);
 413         runJava.add(JVMStartup.class.getName());
 414 
 415         out = new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(runJava.toArray(new String[0])).start());
 416 


< prev index next >