8204525: [TESTBUG] runtime/NMT/MallocStressTest.java ran out of java heap
authorhseigel
Mon, 26 Nov 2018 09:46:20 -0500
changeset 52681 6df06df9ae2e
parent 52680 ca9459361300
child 52682 c93e62e7fa3c
8204525: [TESTBUG] runtime/NMT/MallocStressTest.java ran out of java heap Summary: Handle OutOfMemoryError exception to prevent test aborting Reviewed-by: zgu, dholmes
test/hotspot/jtreg/runtime/NMT/MallocStressTest.java
--- a/test/hotspot/jtreg/runtime/NMT/MallocStressTest.java	Mon Nov 26 12:16:23 2018 +0100
+++ b/test/hotspot/jtreg/runtime/NMT/MallocStressTest.java	Mon Nov 26 09:46:20 2018 -0500
@@ -186,13 +186,19 @@
                 if (size == 0) size = 1;
                 long addr = MallocStressTest.whiteBox.NMTMallocWithPseudoStack(size, r);
                 if (addr != 0) {
-                    MallocMemory mem = new MallocMemory(addr, size);
-                    synchronized(MallocStressTest.mallocd_memory) {
-                        MallocStressTest.mallocd_memory.add(mem);
-                        MallocStressTest.mallocd_total += size;
+                    try {
+                        MallocMemory mem = new MallocMemory(addr, size);
+                        synchronized(MallocStressTest.mallocd_memory) {
+                            MallocStressTest.mallocd_memory.add(mem);
+                            MallocStressTest.mallocd_total += size;
+                        }
+                    } catch (OutOfMemoryError e) {
+                        // Don't include this malloc memory because it didn't
+                        // get recorded in mallocd_memory list.
+                        MallocStressTest.whiteBox.NMTFree(addr);
+                        break;
                     }
                 } else {
-                    System.out.println("Out of malloc memory");
                     break;
                 }
             }