--- a/test/jdk/java/lang/StringBuilder/HugeCapacity.java Wed Feb 06 00:20:37 2019 +0100
+++ b/test/jdk/java/lang/StringBuilder/HugeCapacity.java Tue Feb 05 17:05:40 2019 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,10 +23,11 @@
/**
* @test
- * @bug 8149330
+ * @bug 8149330 8218227
* @summary Capacity should not get close to Integer.MAX_VALUE unless
* necessary
- * @run main/othervm -Xmx5G HugeCapacity
+ * @requires os.maxMemory >= 6G
+ * @run main/othervm -Xms5G -Xmx5G HugeCapacity
* @ignore This test has huge memory requirements
*/
@@ -36,6 +37,8 @@
public static void main(String[] args) {
testLatin1();
testUtf16();
+ testHugeInitialString();
+ testHugeInitialCharSequence();
if (failures > 0) {
throw new RuntimeException(failures + " tests failed");
}
@@ -63,4 +66,37 @@
failures++;
}
}
+
+ private static void testHugeInitialString() {
+ try {
+ String str = "Z".repeat(Integer.MAX_VALUE - 8);
+ StringBuilder sb = new StringBuilder(str);
+ } catch (OutOfMemoryError ignore) {
+ } catch (Throwable unexpected) {
+ unexpected.printStackTrace();
+ failures++;
+ }
+ }
+
+ private static void testHugeInitialCharSequence() {
+ try {
+ CharSequence seq = new MyHugeCharSeq();
+ StringBuilder sb = new StringBuilder(seq);
+ } catch (OutOfMemoryError ignore) {
+ } catch (Throwable unexpected) {
+ unexpected.printStackTrace();
+ failures++;
+ }
+ }
+
+ private static class MyHugeCharSeq implements CharSequence {
+ public char charAt(int i) {
+ throw new UnsupportedOperationException();
+ }
+ public int length() { return Integer.MAX_VALUE; }
+ public CharSequence subSequence(int st, int e) {
+ throw new UnsupportedOperationException();
+ }
+ public String toString() { return ""; }
+ }
}