< prev index next >
test/jdk/java/util/Locale/SoftKeys.java
Print this page
rev 49197 : 8199009: test/jdk/java/util/Locale/SoftKeys.java fails with OutOfMemoryError
Reviewed-by: naoto
*** 33,52 ****
--- 33,61 ----
public class SoftKeys {
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) {
+ 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 makes it impractically hard to
+ // reproduce NPE issues that could arise when references are being
+ // cleared. Do a System.gc() to try to reclaim enough memory to not
+ // throw an OOME again in the jtreg wrapper.
+ System.gc();
+ }
}
private static String langForInt(int val) {
StringBuilder buf = new StringBuilder(4);
buf.append(CHARS[(val >> 12) & 0xF]);
< prev index next >