Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/java2d/marlin/ArrayCacheSizeTest.java
38838 views
1
/*
2
* Copyright (c) 2015, 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.ArrayCache;
25
26
/**
27
* @test
28
* @bug 8144445
29
* @summary Check the ArrayCache getNewLargeSize() method
30
* @run main ArrayCacheSizeTest
31
*/
32
public class ArrayCacheSizeTest {
33
34
public static void main(String[] args) {
35
testNewSize();
36
testNewLargeSize();
37
}
38
39
private static void testNewSize() {
40
testNewSize(0, 1);
41
testNewSize(0, 100000);
42
43
testNewSize(4096, 4097);
44
testNewSize(4096 * 16, 4096 * 16 + 1);
45
46
testNewSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);
47
48
testNewSize(4096 * 4096 * 4, Integer.MAX_VALUE);
49
50
testNewSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);
51
52
testNewSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1);
53
testNewSizeExpectAIOB(1, -1);
54
testNewSizeExpectAIOB(Integer.MAX_VALUE, -1);
55
}
56
57
private static void testNewSizeExpectAIOB(final int curSize,
58
final int needSize) {
59
try {
60
testNewSize(curSize, needSize);
61
throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");
62
} catch (ArrayIndexOutOfBoundsException aiobe) {
63
System.out.println("ArrayIndexOutOfBoundsException expected.");
64
} catch (RuntimeException re) {
65
throw re;
66
} catch (Throwable th) {
67
throw new RuntimeException("Unexpected exception", th);
68
}
69
}
70
71
private static void testNewSize(final int curSize,
72
final int needSize) {
73
74
int size = ArrayCache.getNewSize(curSize, needSize);
75
76
System.out.println("getNewSize(" + curSize + ", " + needSize
77
+ ") = " + size);
78
79
if (size < 0 || size < needSize) {
80
throw new IllegalStateException("Invalid getNewSize("
81
+ curSize + ", " + needSize + ") = " + size + " !");
82
}
83
}
84
85
private static void testNewLargeSize() {
86
testNewLargeSize(0, 1);
87
testNewLargeSize(0, 100000);
88
89
testNewLargeSize(4096, 4097);
90
testNewLargeSize(4096 * 16, 4096 * 16 + 1);
91
92
testNewLargeSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);
93
94
testNewLargeSize(4096 * 4096 * 4, Integer.MAX_VALUE);
95
96
testNewLargeSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);
97
98
testNewLargeSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1L);
99
testNewLargeSizeExpectAIOB(1, -1L);
100
testNewLargeSizeExpectAIOB(Integer.MAX_VALUE, -1L);
101
}
102
103
private static void testNewLargeSizeExpectAIOB(final long curSize,
104
final long needSize) {
105
try {
106
testNewLargeSize(curSize, needSize);
107
throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");
108
} catch (ArrayIndexOutOfBoundsException aiobe) {
109
System.out.println("ArrayIndexOutOfBoundsException expected.");
110
} catch (RuntimeException re) {
111
throw re;
112
} catch (Throwable th) {
113
throw new RuntimeException("Unexpected exception", th);
114
}
115
}
116
117
private static void testNewLargeSize(final long curSize,
118
final long needSize) {
119
120
long size = ArrayCache.getNewLargeSize(curSize, needSize);
121
122
System.out.println("getNewLargeSize(" + curSize + ", " + needSize
123
+ ") = " + size);
124
125
if (size < 0 || size < needSize || size > Integer.MAX_VALUE) {
126
throw new IllegalStateException("Invalid getNewLargeSize("
127
+ curSize + ", " + needSize + ") = " + size + " !");
128
}
129
}
130
131
}
132
133