8043476: java/util/BitSet/BSMethods.java failed with: java.lang.OutOfMemoryError: Java heap space
authorigerasim
Mon, 26 May 2014 19:59:28 +0400
changeset 24571 e1cabb2a72ed
parent 24570 73964a8ec72d
child 24572 5c9e5961d21c
8043476: java/util/BitSet/BSMethods.java failed with: java.lang.OutOfMemoryError: Java heap space Reviewed-by: alanb
jdk/test/java/util/BitSet/BSMethods.java
--- a/jdk/test/java/util/BitSet/BSMethods.java	Mon May 26 15:52:40 2014 +0100
+++ b/jdk/test/java/util/BitSet/BSMethods.java	Mon May 26 19:59:28 2014 +0400
@@ -26,6 +26,7 @@
  *      4979017 4979028 4979031 5030267 6222207 8040806
  * @summary Test the operation of the methods of BitSet class
  * @author Mike McCloskey, Martin Buchholz
+ * @run main/othervm BSMethods
  */
 
 import java.util.*;
@@ -897,15 +898,20 @@
     private static void testToString() {
         check(new BitSet().toString().equals("{}"));
         check(makeSet(2,3,42,43,234).toString().equals("{2, 3, 42, 43, 234}"));
-        try {
-            check(makeSet(Integer.MAX_VALUE-1).toString().equals(
-                    "{" + (Integer.MAX_VALUE-1) + "}"));
-            check(makeSet(Integer.MAX_VALUE).toString().equals(
-                    "{" + Integer.MAX_VALUE + "}"));
-            check(makeSet(0, 1, Integer.MAX_VALUE-1, Integer.MAX_VALUE).toString().equals(
-                    "{0, 1, " + (Integer.MAX_VALUE-1) + ", " + Integer.MAX_VALUE + "}"));
-        } catch (IndexOutOfBoundsException exc) {
-            fail("toString() with indices near MAX_VALUE");
+
+        final long MB = 1024*1024;
+        if (Runtime.getRuntime().maxMemory() >= 512*MB) {
+            // only run it if we have enough memory
+            try {
+                check(makeSet(Integer.MAX_VALUE-1).toString().equals(
+                        "{" + (Integer.MAX_VALUE-1) + "}"));
+                check(makeSet(Integer.MAX_VALUE).toString().equals(
+                        "{" + Integer.MAX_VALUE + "}"));
+                check(makeSet(0, 1, Integer.MAX_VALUE-1, Integer.MAX_VALUE).toString().equals(
+                        "{0, 1, " + (Integer.MAX_VALUE-1) + ", " + Integer.MAX_VALUE + "}"));
+            } catch (IndexOutOfBoundsException exc) {
+                fail("toString() with indices near MAX_VALUE");
+            }
         }
     }