Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
1 /*
2 * Copyright (c) 2004, 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 */
24 /*
25 * @test
26 * @bug 4990346
27 * @summary Verify autoboxed values are cached as required.
28 * @author Joseph D. Darcy
29 */
31 public class BoxingCaching {
33 static boolean verifyBooleanCaching() {
34 boolean cached = true;
36 Boolean results[] = new Boolean[2];
38 results[0] = false;
39 results[1] = true;
41 Boolean B;
43 B = false;
44 if (B != results[0]) {
45 cached = false;
46 System.err.println("Boolean value " + B +
47 " is not cached appropriately.");
48 }
50 B = true;
51 if (B != results[1]) {
52 cached = false;
53 System.err.println("Boolean value " + B +
54 " is not cached appropriately.");
55 }
57 return cached;
58 }
60 static boolean verifyByteCaching() {
61 boolean cached = true;
63 Byte results[] = new Byte[-(-128) + 127 +1];
64 for(int i = 0; i < results.length; i++)
65 results[i] = (byte)(i-128);
67 for(int i = 0; i < results.length; i++) {
68 Byte B = (byte)(i-128);
69 if (B != results[i]) {
70 cached = false;
71 System.err.println("Byte value " + B +
72 " is not cached appropriately.");
73 }
74 }
76 for(int i = Byte.MIN_VALUE; i < Byte.MAX_VALUE; i++) {
77 Byte B;
78 B = (byte)i;
79 if (B.byteValue() != i) {
80 cached = false;
81 System.err.println("Erroneous autoboxing conversion for " +
82 "byte value " + i + " .");
83 }
84 }
86 return cached;
87 }
89 static boolean verifyCharacterCaching() {
90 boolean cached = true;
92 Character results[] = new Character[127 +1];
93 for(int i = 0; i < results.length; i++)
94 results[i] = (char)i;
96 for(int i = 0; i < results.length; i++) {
97 Character C = (char)i;
98 if (C != results[i]) {
99 cached = false;
100 System.err.println("Char value " + C +
101 " is not cached appropriately.");
102 }
103 }
105 for(int i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
106 Character C;
107 C = (char)i;
108 if (C.charValue() != i) {
109 cached = false;
110 System.err.println("Erroneous autoboxing conversion for " +
111 "char value " + i + " .");
112 }
113 }
115 return cached;
116 }
118 static boolean verifyIntegerCaching() {
119 boolean cached = true;
121 Integer results[] = new Integer[-(-128) + 127 +1];
122 for(int i = 0; i < results.length; i++)
123 results[i] = (i-128);
125 for(int i = 0; i < results.length; i++) {
126 Integer I = (i-128);
127 if (I != results[i]) {
128 cached = false;
129 System.err.println("Integer value " + I +
130 " is not cached appropriately.");
131 }
132 }
134 for(int i = -256; i < 255; i++) {
135 Integer I;
136 I = i;
137 if (I.intValue() != i) {
138 cached = false;
139 System.err.println("Erroneous autoboxing conversion for " +
140 "int value " + i + " .");
141 }
142 }
144 return cached;
145 }
147 static boolean verifyLongCaching() {
148 boolean cached = true;
150 Long results[] = new Long[-(-128) + 127 +1];
151 for(int i = 0; i < results.length; i++)
152 results[i] = (long)(i-128);
154 for(int i = 0; i < results.length; i++) {
155 Long L = (long)(i-128);
156 if (L != results[i]) {
157 cached = false;
158 System.err.println("Integer value " + L +
159 " is not cached appropriately.");
160 }
161 }
163 for(int i = -256; i < 255; i++) {
164 Integer L;
165 L = i;
166 if (L.longValue() != i) {
167 cached = false;
168 System.err.println("Erroneous autoboxing conversion for " +
169 "int value " + i + " .");
170 }
171 }
173 return cached;
174 }
176 static boolean verifyShortCaching() {
177 boolean cached = true;
179 Short results[] = new Short[-(-128) + 127 +1];
180 for(int i = 0; i < results.length; i++)
181 results[i] = (short)(i-128);
183 for(int i = 0; i < results.length; i++) {
184 Short S = (short)(i-128);
185 if (S != results[i]) {
186 cached = false;
187 System.err.println("Short value " + S +
188 " is not cached appropriately.");
189 }
190 }
192 for(int i = Short.MIN_VALUE; i < Short.MAX_VALUE; i++) {
193 Short S;
194 S = (short)i;
195 if (S.shortValue() != i) {
196 cached = false;
197 System.err.println("Erroneous autoboxing conversion for " +
198 "short value " + i + " .");
199 }
200 }
202 return cached;
203 }
205 public static void main(String argv[]) {
206 boolean cached = true;
208 cached &= verifyBooleanCaching();
209 cached &= verifyByteCaching();
210 cached &= verifyCharacterCaching();
211 cached &= verifyIntegerCaching();
212 cached &= verifyLongCaching();
213 cached &= verifyShortCaching();
215 if (!cached)
216 throw new RuntimeException("Values not cached appropriately.");
217 }
218 }