Skip to content

Commit ad54d8d

Browse files
committedFeb 10, 2021
8260934: java/lang/StringBuilder/HugeCapacity.java fails without Compact Strings
Reviewed-by: iklam
1 parent 752f92b commit ad54d8d

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,14 +27,20 @@
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 -Xms5G -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
testHugeInitialString();
4046
testHugeInitialCharSequence();
@@ -43,11 +49,12 @@ public static void main(String[] args) {
4349
}
4450
}
4551

46-
private static void testLatin1() {
52+
private static void testLatin1(boolean isCompact) {
4753
try {
54+
int divisor = isCompact ? 2 : 4;
4855
StringBuilder sb = new StringBuilder();
49-
sb.ensureCapacity(Integer.MAX_VALUE / 2);
50-
sb.ensureCapacity(Integer.MAX_VALUE / 2 + 1);
56+
sb.ensureCapacity(Integer.MAX_VALUE / divisor);
57+
sb.ensureCapacity(Integer.MAX_VALUE / divisor + 1);
5158
} catch (OutOfMemoryError oom) {
5259
oom.printStackTrace();
5360
failures++;

0 commit comments

Comments
 (0)
Please sign in to comment.