8199009: test/jdk/java/util/Locale/SoftKeys.java fails with OutOfMemoryError
authorredestad
Sat, 10 Mar 2018 02:58:39 +0100
changeset 49202 b6fb84357542
parent 49201 e59941f7247d
child 49203 3a225d9cabe1
child 56276 ee5e58456be5
8199009: test/jdk/java/util/Locale/SoftKeys.java fails with OutOfMemoryError Reviewed-by: psandoz, naoto
test/jdk/java/util/Locale/SoftKeys.java
--- a/test/jdk/java/util/Locale/SoftKeys.java	Fri Mar 09 19:20:19 2018 +0100
+++ b/test/jdk/java/util/Locale/SoftKeys.java	Sat Mar 10 02:58:39 2018 +0100
@@ -35,15 +35,25 @@
     private static final char[] CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
 
     public static void main(String[] args) {
-        // With 4 characters in "language", we'll fill up a 16M heap quickly,
-        // causing full GCs and SoftReference reclamation. Repeat at least two
-        // times to verify no NPEs appear when looking up Locale's whose
-        // softly referenced data in sun.util.locale.BaseLocale$Key might have
-        // been cleared.
-        for (int i = 0; i < 2; i++) {
-            for (int j = 0; j < 512*1024; j++) {
-                new Locale(langForInt(j), "", "");
+        try {
+            // With 4 characters in "language", we'll fill up a 16M heap quickly,
+            // causing full GCs and SoftReference reclamation. Repeat at least two
+            // times to verify no NPEs appear when looking up Locale's whose
+            // softly referenced data in sun.util.locale.BaseLocale$Key might have
+            // been cleared.
+            for (int i = 0; i < 2; i++) {
+                for (int j = 0; j < 512*1024; j++) {
+                    new Locale(langForInt(j), "", "");
+                }
             }
+        } catch (OutOfMemoryError e) {
+            // Can happen on some system configurations, and while increasing heap
+            // size would allow GC to keep up, it also makes it impractically hard
+            // to reproduce NPE issues that could arise when references are being
+            // cleared.
+
+            // Do a System.gc() to not throw an OOME again in the jtreg wrapper.
+            System.gc();
         }
     }