Skip to content
Permalink
Browse files
8260934: java/lang/StringBuilder/HugeCapacity.java fails without Comp…
…act Strings

Reviewed-by: iklam
  • Loading branch information
shipilev committed Feb 10, 2021
1 parent 752f92b commit ad54d8dd832b22485d7ac45958cc4c9bfd70fbd2
Showing with 12 additions and 5 deletions.
  1. +12 −5 test/jdk/java/lang/StringBuilder/HugeCapacity.java
@@ -27,14 +27,20 @@
* @summary Capacity should not get close to Integer.MAX_VALUE unless
* necessary
* @requires (sun.arch.data.model == "64" & os.maxMemory >= 6G)
* @run main/othervm -Xms5G -Xmx5G HugeCapacity
* @run main/othervm -Xms5G -Xmx5G -XX:+CompactStrings HugeCapacity true
* @run main/othervm -Xms5G -Xmx5G -XX:-CompactStrings HugeCapacity false
*/

public class HugeCapacity {
private static int failures = 0;

public static void main(String[] args) {
testLatin1();
if (args.length == 0) {
throw new IllegalArgumentException("Need the argument");
}
boolean isCompact = Boolean.parseBoolean(args[0]);

testLatin1(isCompact);
testUtf16();
testHugeInitialString();
testHugeInitialCharSequence();
@@ -43,11 +49,12 @@ public static void main(String[] args) {
}
}

private static void testLatin1() {
private static void testLatin1(boolean isCompact) {
try {
int divisor = isCompact ? 2 : 4;
StringBuilder sb = new StringBuilder();
sb.ensureCapacity(Integer.MAX_VALUE / 2);
sb.ensureCapacity(Integer.MAX_VALUE / 2 + 1);
sb.ensureCapacity(Integer.MAX_VALUE / divisor);
sb.ensureCapacity(Integer.MAX_VALUE / divisor + 1);
} catch (OutOfMemoryError oom) {
oom.printStackTrace();
failures++;

0 comments on commit ad54d8d

Please sign in to comment.