test/tools/javac/boxing/BoxingCaching.java

Tue, 03 Jun 2008 13:26:47 -0700

author
jjg
date
Tue, 03 Jun 2008 13:26:47 -0700
changeset 46
7708bd6d800d
parent 1
9a66ca7c79fa
child 289
84061bd68019
permissions
-rw-r--r--

4075303: Use javap to enquire aboput a specific inner class
4348375: Javap is not internationalized
4459541: "javap -l" shows line numbers as signed short; they should be unsigned
4501660: change diagnostic of -help as 'print this help message and exit'
4776241: unused source file in javap...
4870651: javap should recognize generics, varargs, enum
4876942: javap invoked without args does not print help screen
4880663: javap could output whitespace between class name and opening brace
4975569: javap doesn't print new flag bits
6271787: javap dumps LocalVariableTypeTable attribute in hex, needs to print a table
6305779: javap: support annotations
6439940: Clean up javap implementation
6469569: wrong check of searchpath in JavapEnvironment
6474890: javap does not open .zip files in -classpath
6587786: Javap throws error : "ERROR:Could not find <classname>" for JRE classes
6622215: javap ignores certain relevant access flags
6622216: javap names some attributes incorrectly
6622232: javap gets whitespace confused
6622260: javap prints negative bytes incorrectly in hex
Reviewed-by: ksrini

duke@1 1 /*
duke@1 2 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
duke@1 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 21 * have any questions.
duke@1 22 */
duke@1 23
duke@1 24 /*
duke@1 25 * @test
duke@1 26 * @bug 4990346
duke@1 27 * @summary Verify autoboxed values are cached as required.
duke@1 28 * @author Joseph D. Darcy
duke@1 29 *
duke@1 30 * @compile -source 1.5 BoxingCaching.java
duke@1 31 * @run main BoxingCaching
duke@1 32 */
duke@1 33
duke@1 34 public class BoxingCaching {
duke@1 35
duke@1 36 static boolean verifyBooleanCaching() {
duke@1 37 boolean cached = true;
duke@1 38
duke@1 39 Boolean results[] = new Boolean[2];
duke@1 40
duke@1 41 results[0] = false;
duke@1 42 results[1] = true;
duke@1 43
duke@1 44 Boolean B;
duke@1 45
duke@1 46 B = false;
duke@1 47 if (B != results[0]) {
duke@1 48 cached = false;
duke@1 49 System.err.println("Boolean value " + B +
duke@1 50 " is not cached appropriately.");
duke@1 51 }
duke@1 52
duke@1 53 B = true;
duke@1 54 if (B != results[1]) {
duke@1 55 cached = false;
duke@1 56 System.err.println("Boolean value " + B +
duke@1 57 " is not cached appropriately.");
duke@1 58 }
duke@1 59
duke@1 60 return cached;
duke@1 61 }
duke@1 62
duke@1 63 static boolean verifyByteCaching() {
duke@1 64 boolean cached = true;
duke@1 65
duke@1 66 Byte results[] = new Byte[-(-128) + 127 +1];
duke@1 67 for(int i = 0; i < results.length; i++)
duke@1 68 results[i] = (byte)(i-128);
duke@1 69
duke@1 70 for(int i = 0; i < results.length; i++) {
duke@1 71 Byte B = (byte)(i-128);
duke@1 72 if (B != results[i]) {
duke@1 73 cached = false;
duke@1 74 System.err.println("Byte value " + B +
duke@1 75 " is not cached appropriately.");
duke@1 76 }
duke@1 77 }
duke@1 78
duke@1 79 for(int i = Byte.MIN_VALUE; i < Byte.MAX_VALUE; i++) {
duke@1 80 Byte B;
duke@1 81 B = (byte)i;
duke@1 82 if (B.byteValue() != i) {
duke@1 83 cached = false;
duke@1 84 System.err.println("Erroneous autoboxing conversion for " +
duke@1 85 "byte value " + i + " .");
duke@1 86 }
duke@1 87 }
duke@1 88
duke@1 89 return cached;
duke@1 90 }
duke@1 91
duke@1 92 static boolean verifyCharacterCaching() {
duke@1 93 boolean cached = true;
duke@1 94
duke@1 95 Character results[] = new Character[127 +1];
duke@1 96 for(int i = 0; i < results.length; i++)
duke@1 97 results[i] = (char)i;
duke@1 98
duke@1 99 for(int i = 0; i < results.length; i++) {
duke@1 100 Character C = (char)i;
duke@1 101 if (C != results[i]) {
duke@1 102 cached = false;
duke@1 103 System.err.println("Char value " + C +
duke@1 104 " is not cached appropriately.");
duke@1 105 }
duke@1 106 }
duke@1 107
duke@1 108 for(int i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
duke@1 109 Character C;
duke@1 110 C = (char)i;
duke@1 111 if (C.charValue() != i) {
duke@1 112 cached = false;
duke@1 113 System.err.println("Erroneous autoboxing conversion for " +
duke@1 114 "char value " + i + " .");
duke@1 115 }
duke@1 116 }
duke@1 117
duke@1 118 return cached;
duke@1 119 }
duke@1 120
duke@1 121 static boolean verifyIntegerCaching() {
duke@1 122 boolean cached = true;
duke@1 123
duke@1 124 Integer results[] = new Integer[-(-128) + 127 +1];
duke@1 125 for(int i = 0; i < results.length; i++)
duke@1 126 results[i] = (i-128);
duke@1 127
duke@1 128 for(int i = 0; i < results.length; i++) {
duke@1 129 Integer I = (i-128);
duke@1 130 if (I != results[i]) {
duke@1 131 cached = false;
duke@1 132 System.err.println("Integer value " + I +
duke@1 133 " is not cached appropriately.");
duke@1 134 }
duke@1 135 }
duke@1 136
duke@1 137 for(int i = -256; i < 255; i++) {
duke@1 138 Integer I;
duke@1 139 I = i;
duke@1 140 if (I.intValue() != i) {
duke@1 141 cached = false;
duke@1 142 System.err.println("Erroneous autoboxing conversion for " +
duke@1 143 "int value " + i + " .");
duke@1 144 }
duke@1 145 }
duke@1 146
duke@1 147 return cached;
duke@1 148 }
duke@1 149
duke@1 150 static boolean verifyLongCaching() {
duke@1 151 boolean cached = true;
duke@1 152
duke@1 153 Long results[] = new Long[-(-128) + 127 +1];
duke@1 154 for(int i = 0; i < results.length; i++)
duke@1 155 results[i] = (long)(i-128);
duke@1 156
duke@1 157 for(int i = 0; i < results.length; i++) {
duke@1 158 Long L = (long)(i-128);
duke@1 159 if (L != results[i]) {
duke@1 160 cached = false;
duke@1 161 System.err.println("Integer value " + L +
duke@1 162 " is not cached appropriately.");
duke@1 163 }
duke@1 164 }
duke@1 165
duke@1 166 for(int i = -256; i < 255; i++) {
duke@1 167 Integer L;
duke@1 168 L = i;
duke@1 169 if (L.longValue() != i) {
duke@1 170 cached = false;
duke@1 171 System.err.println("Erroneous autoboxing conversion for " +
duke@1 172 "int value " + i + " .");
duke@1 173 }
duke@1 174 }
duke@1 175
duke@1 176 return cached;
duke@1 177 }
duke@1 178
duke@1 179 static boolean verifyShortCaching() {
duke@1 180 boolean cached = true;
duke@1 181
duke@1 182 Short results[] = new Short[-(-128) + 127 +1];
duke@1 183 for(int i = 0; i < results.length; i++)
duke@1 184 results[i] = (short)(i-128);
duke@1 185
duke@1 186 for(int i = 0; i < results.length; i++) {
duke@1 187 Short S = (short)(i-128);
duke@1 188 if (S != results[i]) {
duke@1 189 cached = false;
duke@1 190 System.err.println("Short value " + S +
duke@1 191 " is not cached appropriately.");
duke@1 192 }
duke@1 193 }
duke@1 194
duke@1 195 for(int i = Short.MIN_VALUE; i < Short.MAX_VALUE; i++) {
duke@1 196 Short S;
duke@1 197 S = (short)i;
duke@1 198 if (S.shortValue() != i) {
duke@1 199 cached = false;
duke@1 200 System.err.println("Erroneous autoboxing conversion for " +
duke@1 201 "short value " + i + " .");
duke@1 202 }
duke@1 203 }
duke@1 204
duke@1 205 return cached;
duke@1 206 }
duke@1 207
duke@1 208 public static void main(String argv[]) {
duke@1 209 boolean cached = true;
duke@1 210
duke@1 211 cached &= verifyBooleanCaching();
duke@1 212 cached &= verifyByteCaching();
duke@1 213 cached &= verifyCharacterCaching();
duke@1 214 cached &= verifyIntegerCaching();
duke@1 215 cached &= verifyLongCaching();
duke@1 216 cached &= verifyShortCaching();
duke@1 217
duke@1 218 if (!cached)
duke@1 219 throw new RuntimeException("Values not cached appropriately.");
duke@1 220 }
duke@1 221 }

mercurial