Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/java2d/marlin/ArrayCacheSizeTest.java
41149 views
1
/*
2
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import sun.java2d.marlin.ArrayCacheConst;
25
26
/*
27
* @test
28
* @bug 8144445
29
* @summary Check the ArrayCache getNewLargeSize() method
30
* @run main ArrayCacheSizeTest
31
* @modules java.desktop/sun.java2d.marlin
32
*/
33
public class ArrayCacheSizeTest {
34
35
public static void main(String[] args) {
36
testNewSize();
37
testNewLargeSize();
38
}
39
40
private static void testNewSize() {
41
testNewSize(0, 1);
42
testNewSize(0, 100000);
43
44
testNewSize(4096, 4097);
45
testNewSize(4096 * 16, 4096 * 16 + 1);
46
47
testNewSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);
48
49
testNewSize(4096 * 4096 * 4, Integer.MAX_VALUE);
50
51
testNewSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);
52
53
testNewSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1);
54
testNewSizeExpectAIOB(1, -1);
55
testNewSizeExpectAIOB(Integer.MAX_VALUE, -1);
56
}
57
58
private static void testNewSizeExpectAIOB(final int curSize,
59
final int needSize) {
60
try {
61
testNewSize(curSize, needSize);
62
throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");
63
} catch (ArrayIndexOutOfBoundsException aiobe) {
64
System.out.println("ArrayIndexOutOfBoundsException expected.");
65
} catch (RuntimeException re) {
66
throw re;
67
} catch (Throwable th) {
68
throw new RuntimeException("Unexpected exception", th);
69
}
70
}
71
72
private static void testNewSize(final int curSize,
73
final int needSize) {
74
75
int size = ArrayCacheConst.getNewSize(curSize, needSize);
76
77
System.out.println("getNewSize(" + curSize + ", " + needSize
78
+ ") = " + size);
79
80
if (size < 0 || size < needSize) {
81
throw new IllegalStateException("Invalid getNewSize("
82
+ curSize + ", " + needSize + ") = " + size + " !");
83
}
84
}
85
86
private static void testNewLargeSize() {
87
testNewLargeSize(0, 1);
88
testNewLargeSize(0, 100000);
89
90
testNewLargeSize(4096, 4097);
91
testNewLargeSize(4096 * 16, 4096 * 16 + 1);
92
93
testNewLargeSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);
94
95
testNewLargeSize(4096 * 4096 * 4, Integer.MAX_VALUE);
96
97
testNewLargeSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);
98
99
testNewLargeSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1L);
100
testNewLargeSizeExpectAIOB(1, -1L);
101
testNewLargeSizeExpectAIOB(Integer.MAX_VALUE, -1L);
102
}
103
104
private static void testNewLargeSizeExpectAIOB(final long curSize,
105
final long needSize) {
106
try {
107
testNewLargeSize(curSize, needSize);
108
throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");
109
} catch (ArrayIndexOutOfBoundsException aiobe) {
110
System.out.println("ArrayIndexOutOfBoundsException expected.");
111
} catch (RuntimeException re) {
112
throw re;
113
} catch (Throwable th) {
114
throw new RuntimeException("Unexpected exception", th);
115
}
116
}
117
118
private static void testNewLargeSize(final long curSize,
119
final long needSize) {
120
121
long size = ArrayCacheConst.getNewLargeSize(curSize, needSize);
122
123
System.out.println("getNewLargeSize(" + curSize + ", " + needSize
124
+ ") = " + size);
125
126
if (size < 0 || size < needSize || size > Integer.MAX_VALUE) {
127
throw new IllegalStateException("Invalid getNewLargeSize("
128
+ curSize + ", " + needSize + ") = " + size + " !");
129
}
130
}
131
132
}
133
134