Skip to content

Commit 513732d

Browse files
committed
8260934: java/lang/StringBuilder/HugeCapacity.java fails without Compact Strings
Reviewed-by: phh Backport-of: ad54d8d
1 parent 817254d commit 513732d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

test/jdk/java/lang/StringBuilder/HugeCapacity.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,32 @@
2727
* @summary Capacity should not get close to Integer.MAX_VALUE unless
2828
* necessary
2929
* @requires (sun.arch.data.model == "64" & os.maxMemory >= 6G)
30-
* @run main/othervm -Xmx5G HugeCapacity
30+
* @run main/othervm -Xms5G -Xmx5G -XX:+CompactStrings HugeCapacity true
31+
* @run main/othervm -Xms5G -Xmx5G -XX:-CompactStrings HugeCapacity false
3132
*/
3233

3334
public class HugeCapacity {
3435
private static int failures = 0;
3536

3637
public static void main(String[] args) {
37-
testLatin1();
38+
if (args.length == 0) {
39+
throw new IllegalArgumentException("Need the argument");
40+
}
41+
boolean isCompact = Boolean.parseBoolean(args[0]);
42+
43+
testLatin1(isCompact);
3844
testUtf16();
3945
if (failures > 0) {
4046
throw new RuntimeException(failures + " tests failed");
4147
}
4248
}
4349

44-
private static void testLatin1() {
50+
private static void testLatin1(boolean isCompact) {
4551
try {
52+
int divisor = isCompact ? 2 : 4;
4653
StringBuilder sb = new StringBuilder();
47-
sb.ensureCapacity(Integer.MAX_VALUE / 2);
48-
sb.ensureCapacity(Integer.MAX_VALUE / 2 + 1);
54+
sb.ensureCapacity(Integer.MAX_VALUE / divisor);
55+
sb.ensureCapacity(Integer.MAX_VALUE / divisor + 1);
4956
} catch (OutOfMemoryError oom) {
5057
oom.printStackTrace();
5158
failures++;

0 commit comments

Comments
 (0)