< prev index next >

test/hotspot/jtreg/serviceability/sa/TestJmapCore.java

Print this page

        

@@ -21,14 +21,14 @@
  * questions.
  */
 
 /*
  * @test TestJmapCore
- * @summary Test verifies that jhsdb jmap could generate heap dump from core
+ * @summary Test verifies that jhsdb jmap could generate heap dump from core when heap is full
  * @modules java.base/jdk.internal.misc
  * @library /test/lib
- * @run driver TestJmapCore
+ * @run driver/timeout=240 TestJmapCore run heap
  */
 
 import jdk.test.lib.Asserts;
 import jdk.test.lib.JDKToolFinder;
 import jdk.test.lib.JDKToolLauncher;

@@ -37,31 +37,40 @@
 import jdk.test.lib.hprof.HprofParser;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 
 import java.io.File;
-import java.util.Arrays;
-import java.util.stream.Collectors;
 
 public class TestJmapCore {
     static final String pidSeparator = ":KILLED_PID";
 
+    public static String HEAP_OOME = "heap";
+    public static String METASPACE_OOME = "metaspace";
+
+
     public static void main(String[] args) throws Throwable {
         if (args.length == 1) {
-            // If any arguments are set prints pid so main process coud find corefile
+            // If 1 argument is set prints pid so main process could find corefile
             System.out.println(ProcessHandle.current().pid() + pidSeparator);
             try {
+                if (args[0].equals(HEAP_OOME)) {
                 Object[] oa = new Object[Integer.MAX_VALUE / 2];
                 for(int i = 0; i < oa.length; i++) {
                     oa[i] = new Object[Integer.MAX_VALUE / 2];
                 }
+                } else {
+                    GeneratingClassLoader loader = new GeneratingClassLoader();
+                    for (int i = 0; ; i++) {
+                        loader.loadClass(loader.getClassName(i));
+                    }
+                }
                 throw new Error("OOME not triggered");
             } catch (OutOfMemoryError err) {
                 return;
             }
         }
-        test();
+        test(args[1]);
     }
 
     // Test tries to run java with ulimit unlimited if it is possible
     static boolean useDefaultUlimit() {
         if (Platform.isWindows()) {

@@ -73,14 +82,14 @@
         } catch (Throwable t) {
             return true;
         }
     }
 
-    static void test() throws Throwable {
+    static void test(String type) throws Throwable {
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-XX:+CreateCoredumpOnCrash",
-                "-XX:+CrashOnOutOfMemoryError", "-XX:-TransmitErrorReport",
-                TestJmapCore.class.getName(), "throwOOME");
+                "-XX:MaxMetaspaceSize=64m", "-XX:+CrashOnOutOfMemoryError", "-XX:-TransmitErrorReport",
+                TestJmapCore.class.getName(), type);
 
         boolean useDefaultUlimit = useDefaultUlimit();
         System.out.println("Run test with ulimit: " + (useDefaultUlimit ? "default" : "unlimited"));
         OutputAnalyzer output = useDefaultUlimit
             ? ProcessTools.executeProcess(pb)
< prev index next >