Merge
authorddmitriev
Wed, 17 Feb 2016 12:44:41 +0000
changeset 36176 fe3a8d7c73e9
parent 36174 481391df586b (current diff)
parent 36175 0f5b32ce95fc (diff)
child 36177 b2b76aba8e42
Merge
--- a/hotspot/test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java	Wed Feb 17 11:11:47 2016 +0100
+++ b/hotspot/test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java	Wed Feb 17 12:44:41 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, 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
@@ -84,6 +84,13 @@
         setAllowedExitCodes("SharedMiscCodeSize", 2);
 
         /*
+         * JDK-8145204
+         * Temporarily remove testing of max range for ParGCArrayScanChunk because
+         * JVM can hang when ParGCArrayScanChunk=4294967296 and ParallelGC is used
+         */
+        excludeTestMaxRange("ParGCArrayScanChunk");
+
+        /*
          * Remove CICompilerCount from testing because currently it can hang system
          */
         excludeTestMaxRange("CICompilerCount");
--- a/hotspot/test/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOption.java	Wed Feb 17 11:11:47 2016 +0100
+++ b/hotspot/test/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOption.java	Wed Feb 17 12:44:41 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, 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
@@ -37,6 +37,7 @@
 import sun.tools.attach.HotSpotVirtualMachine;
 
 import static optionsvalidation.JVMOptionsUtils.failedMessage;
+import static optionsvalidation.JVMOptionsUtils.GCType;
 import static optionsvalidation.JVMOptionsUtils.printOutputContent;
 import static optionsvalidation.JVMOptionsUtils.VMType;
 
@@ -374,17 +375,21 @@
     private boolean runJavaWithParam(String optionValue, boolean valid) throws Exception {
         int exitCode;
         boolean result = true;
-        String value = optionValue.substring(optionValue.lastIndexOf("=") + 1);
-        String fullOptionString = prependString.toString() + optionValue;
+        String errorMessage = null;
         List<String> runJava = new ArrayList<>();
         OutputAnalyzer out;
 
         if (VMType != null) {
             runJava.add(VMType);
         }
+
+        if (GCType != null) {
+            runJava.add(GCType);
+        }
+
         runJava.addAll(prepend);
         runJava.add(optionValue);
-        runJava.add(JVMOptionsUtils.class.getName());
+        runJava.add(JVMStartup.class.getName());
 
         out = new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(runJava.toArray(new String[0])).start());
 
@@ -392,40 +397,37 @@
 
         if (out.getOutput().contains("A fatal error has been detected by the Java Runtime Environment")) {
             /* Always consider "fatal error" in output as fail */
-            failedMessage(name, fullOptionString, valid, "JVM output reports a fatal error. JVM exited with code " + exitCode + "!");
-            printOutputContent(out);
-            result = false;
+            errorMessage = "JVM output reports a fatal error. JVM exited with code " + exitCode + "!";
         } else if (valid == true) {
             if (!allowedExitCodes.contains(exitCode)) {
-                failedMessage(name, fullOptionString, valid, "JVM exited with unexpected error code = " + exitCode);
-                printOutputContent(out);
-                result = false;
+                errorMessage = "JVM exited with unexpected error code = " + exitCode;
             } else if ((exitCode != 0) && (out.getOutput().isEmpty() == true)) {
-                failedMessage(name, fullOptionString, valid, "JVM exited with error(exitcode == " + exitCode +
-                        "), but with empty stdout and stderr. Description of error is needed!");
-                result = false;
+                errorMessage = "JVM exited with error(exitcode == " + exitCode + "), but with empty stdout and stderr. " +
+                       "Description of error is needed!";
             } else if (out.getOutput().contains("is outside the allowed range")) {
-                failedMessage(name, fullOptionString, valid, "JVM output contains \"is outside the allowed range\"");
-                printOutputContent(out);
-                result = false;
+                errorMessage = "JVM output contains \"is outside the allowed range\"";
             }
         } else {
             // valid == false
+            String value = optionValue.substring(optionValue.lastIndexOf("=") + 1);
+            String errorMessageCommandLineValue = getErrorMessageCommandLine(value);
             if (exitCode == 0) {
-                failedMessage(name, fullOptionString, valid, "JVM successfully exit");
-                result = false;
+                errorMessage = "JVM successfully exit";
             } else if (exitCode != 1) {
-                failedMessage(name, fullOptionString, valid, "JVM exited with code "
-                        + exitCode + " which not equal to 1");
-                result = false;
-            } else if (!out.getOutput().contains(getErrorMessageCommandLine(value))) {
-                failedMessage(name, fullOptionString, valid, "JVM output does not contain "
-                        + "expected output \"" + getErrorMessageCommandLine(value) + "\"");
-                printOutputContent(out);
-                result = false;
+                errorMessage = "JVM exited with code " + exitCode + " which not equal to 1";
+            } else if (!out.getOutput().contains(errorMessageCommandLineValue)) {
+                errorMessage = "JVM output does not contain expected output \"" + errorMessageCommandLineValue + "\"";
             }
         }
 
+        if (errorMessage != null) {
+            String fullOptionString = String.format("%s %s %s %s",
+                    VMType == null ? "" : VMType, GCType == null ? "" : GCType, prependString.toString(), optionValue).trim().replaceAll("  +", " ");
+            failedMessage(name, fullOptionString, valid, errorMessage);
+            printOutputContent(out);
+            result = false;
+        }
+
         System.out.println("");
 
         return result;
--- a/hotspot/test/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOptionsUtils.java	Wed Feb 17 11:11:47 2016 +0100
+++ b/hotspot/test/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOptionsUtils.java	Wed Feb 17 12:44:41 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, 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
@@ -27,6 +27,8 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -50,6 +52,9 @@
     /* Used to start the JVM with the same type as current */
     static String VMType;
 
+    /* Used to start the JVM with the same GC type as current */
+    static String GCType;
+
     private static Map<String, JVMOption> optionsAsMap;
 
     static {
@@ -64,6 +69,27 @@
         } else {
             VMType = null;
         }
+
+        List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
+
+        GCType = null;
+
+        for (GarbageCollectorMXBean gcMxBean : gcMxBeans) {
+            switch (gcMxBean.getName()) {
+                case "ConcurrentMarkSweep":
+                    GCType = "-XX:+UseConcMarkSweepGC";
+                    break;
+                case "MarkSweepCompact":
+                    GCType = "-XX:+UseSerialGC";
+                    break;
+                case "PS Scavenge":
+                    GCType = "-XX:+UseParallelGC";
+                    break;
+                case "G1 Old Generation":
+                    GCType = "-XX:+UseG1GC";
+                    break;
+            }
+        }
     }
 
     public static boolean fitsRange(String optionName, BigDecimal number) throws Exception {
@@ -443,6 +469,10 @@
         if (VMType != null) {
             runJava.add(VMType);
         }
+
+        if (GCType != null) {
+            runJava.add(GCType);
+        }
         runJava.add(PRINT_FLAGS_RANGES);
         runJava.add("-version");
 
@@ -534,9 +564,4 @@
     public static Map<String, JVMOption> getOptionsWithRangeAsMap(String... additionalArgs) throws Exception {
         return getOptionsWithRangeAsMap(origin -> true, additionalArgs);
     }
-
-    /* Simple method to test that java start-up. Used for testing options. */
-    public static void main(String[] args) {
-        System.out.print("Java start-up!");
-    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMStartup.java	Wed Feb 17 12:44:41 2016 +0000
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016, 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 optionsvalidation;
+
+import java.lang.ref.WeakReference;
+
+class JVMStartup {
+    private static volatile WeakReference<Object> weakRef;
+
+    private static synchronized void createWeakRef() {
+        Object o = new Object();
+        weakRef = new WeakReference<>(o);
+    }
+
+    /* Simple method to test that java start-up. Used for testing options. */
+    public static void main(String[] args) throws Exception {
+        byte[] garbage = new byte[8192];
+        int i = 0;
+        createWeakRef();
+        do {
+            garbage = new byte[8192];
+            i++;
+            /* Initiate GC after 5 iterations */
+            if (i > 5) {
+                System.gc();
+            }
+        } while(weakRef.get() != null);
+        System.out.println("Java start-up!");
+    }
+}