author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 36217 | jdk/test/java/lang/StringBuilder/HugeCapacity.java@cc64f9fb2062 |
child 53653 | 868611f0adc3 |
permissions | -rw-r--r-- |
36217
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
1 |
/* |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
4 |
* |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
8 |
* |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
13 |
* accompanied this code). |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
14 |
* |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
18 |
* |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
21 |
* questions. |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
22 |
*/ |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
23 |
|
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
24 |
/** |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
25 |
* @test |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
26 |
* @bug 8149330 |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
27 |
* @summary Capacity should not get close to Integer.MAX_VALUE unless |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
28 |
* necessary |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
29 |
* @run main/othervm -Xmx5G HugeCapacity |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
30 |
* @ignore This test has huge memory requirements |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
31 |
*/ |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
32 |
|
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
33 |
public class HugeCapacity { |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
34 |
private static int failures = 0; |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
35 |
|
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
36 |
public static void main(String[] args) { |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
37 |
testLatin1(); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
38 |
testUtf16(); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
39 |
if (failures > 0) { |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
40 |
throw new RuntimeException(failures + " tests failed"); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
41 |
} |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
42 |
} |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
43 |
|
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
44 |
private static void testLatin1() { |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
45 |
try { |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
46 |
StringBuilder sb = new StringBuilder(); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
47 |
sb.ensureCapacity(Integer.MAX_VALUE / 2); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
48 |
sb.ensureCapacity(Integer.MAX_VALUE / 2 + 1); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
49 |
} catch (OutOfMemoryError oom) { |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
50 |
oom.printStackTrace(); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
51 |
failures++; |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
52 |
} |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
53 |
} |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
54 |
|
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
55 |
private static void testUtf16() { |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
56 |
try { |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
57 |
StringBuilder sb = new StringBuilder(); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
58 |
sb.append('\u042b'); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
59 |
sb.ensureCapacity(Integer.MAX_VALUE / 4); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
60 |
sb.ensureCapacity(Integer.MAX_VALUE / 4 + 1); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
61 |
} catch (OutOfMemoryError oom) { |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
62 |
oom.printStackTrace(); |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
63 |
failures++; |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
64 |
} |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
65 |
} |
cc64f9fb2062
8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary
igerasim
parents:
diff
changeset
|
66 |
} |