8260934: java/lang/StringBuilder/HugeCapacity.java fails without Compact Strings

Reviewed-by: iklam
This commit is contained in:
Aleksey Shipilev 2021-02-10 07:32:53 +00:00
parent 752f92bc10
commit ad54d8dd83

@ -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 class HugeCapacity {
}
}
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++;