0N/A/*
553N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4990346
0N/A * @summary Verify autoboxed values are cached as required.
0N/A * @author Joseph D. Darcy
0N/A */
0N/A
0N/Apublic class BoxingCaching {
0N/A
0N/A static boolean verifyBooleanCaching() {
0N/A boolean cached = true;
0N/A
0N/A Boolean results[] = new Boolean[2];
0N/A
0N/A results[0] = false;
0N/A results[1] = true;
0N/A
0N/A Boolean B;
0N/A
0N/A B = false;
0N/A if (B != results[0]) {
0N/A cached = false;
0N/A System.err.println("Boolean value " + B +
0N/A " is not cached appropriately.");
0N/A }
0N/A
0N/A B = true;
0N/A if (B != results[1]) {
0N/A cached = false;
0N/A System.err.println("Boolean value " + B +
0N/A " is not cached appropriately.");
0N/A }
0N/A
0N/A return cached;
0N/A }
0N/A
0N/A static boolean verifyByteCaching() {
0N/A boolean cached = true;
0N/A
0N/A Byte results[] = new Byte[-(-128) + 127 +1];
0N/A for(int i = 0; i < results.length; i++)
0N/A results[i] = (byte)(i-128);
0N/A
0N/A for(int i = 0; i < results.length; i++) {
0N/A Byte B = (byte)(i-128);
0N/A if (B != results[i]) {
0N/A cached = false;
0N/A System.err.println("Byte value " + B +
0N/A " is not cached appropriately.");
0N/A }
0N/A }
0N/A
0N/A for(int i = Byte.MIN_VALUE; i < Byte.MAX_VALUE; i++) {
0N/A Byte B;
0N/A B = (byte)i;
0N/A if (B.byteValue() != i) {
0N/A cached = false;
0N/A System.err.println("Erroneous autoboxing conversion for " +
0N/A "byte value " + i + " .");
0N/A }
0N/A }
0N/A
0N/A return cached;
0N/A }
0N/A
0N/A static boolean verifyCharacterCaching() {
0N/A boolean cached = true;
0N/A
0N/A Character results[] = new Character[127 +1];
0N/A for(int i = 0; i < results.length; i++)
0N/A results[i] = (char)i;
0N/A
0N/A for(int i = 0; i < results.length; i++) {
0N/A Character C = (char)i;
0N/A if (C != results[i]) {
0N/A cached = false;
0N/A System.err.println("Char value " + C +
0N/A " is not cached appropriately.");
0N/A }
0N/A }
0N/A
0N/A for(int i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
0N/A Character C;
0N/A C = (char)i;
0N/A if (C.charValue() != i) {
0N/A cached = false;
0N/A System.err.println("Erroneous autoboxing conversion for " +
0N/A "char value " + i + " .");
0N/A }
0N/A }
0N/A
0N/A return cached;
0N/A }
0N/A
0N/A static boolean verifyIntegerCaching() {
0N/A boolean cached = true;
0N/A
0N/A Integer results[] = new Integer[-(-128) + 127 +1];
0N/A for(int i = 0; i < results.length; i++)
0N/A results[i] = (i-128);
0N/A
0N/A for(int i = 0; i < results.length; i++) {
0N/A Integer I = (i-128);
0N/A if (I != results[i]) {
0N/A cached = false;
0N/A System.err.println("Integer value " + I +
0N/A " is not cached appropriately.");
0N/A }
0N/A }
0N/A
0N/A for(int i = -256; i < 255; i++) {
0N/A Integer I;
0N/A I = i;
0N/A if (I.intValue() != i) {
0N/A cached = false;
0N/A System.err.println("Erroneous autoboxing conversion for " +
0N/A "int value " + i + " .");
0N/A }
0N/A }
0N/A
0N/A return cached;
0N/A }
0N/A
0N/A static boolean verifyLongCaching() {
0N/A boolean cached = true;
0N/A
0N/A Long results[] = new Long[-(-128) + 127 +1];
0N/A for(int i = 0; i < results.length; i++)
0N/A results[i] = (long)(i-128);
0N/A
0N/A for(int i = 0; i < results.length; i++) {
0N/A Long L = (long)(i-128);
0N/A if (L != results[i]) {
0N/A cached = false;
0N/A System.err.println("Integer value " + L +
0N/A " is not cached appropriately.");
0N/A }
0N/A }
0N/A
0N/A for(int i = -256; i < 255; i++) {
0N/A Integer L;
0N/A L = i;
0N/A if (L.longValue() != i) {
0N/A cached = false;
0N/A System.err.println("Erroneous autoboxing conversion for " +
0N/A "int value " + i + " .");
0N/A }
0N/A }
0N/A
0N/A return cached;
0N/A }
0N/A
0N/A static boolean verifyShortCaching() {
0N/A boolean cached = true;
0N/A
0N/A Short results[] = new Short[-(-128) + 127 +1];
0N/A for(int i = 0; i < results.length; i++)
0N/A results[i] = (short)(i-128);
0N/A
0N/A for(int i = 0; i < results.length; i++) {
0N/A Short S = (short)(i-128);
0N/A if (S != results[i]) {
0N/A cached = false;
0N/A System.err.println("Short value " + S +
0N/A " is not cached appropriately.");
0N/A }
0N/A }
0N/A
0N/A for(int i = Short.MIN_VALUE; i < Short.MAX_VALUE; i++) {
0N/A Short S;
0N/A S = (short)i;
0N/A if (S.shortValue() != i) {
0N/A cached = false;
0N/A System.err.println("Erroneous autoboxing conversion for " +
0N/A "short value " + i + " .");
0N/A }
0N/A }
0N/A
0N/A return cached;
0N/A }
0N/A
0N/A public static void main(String argv[]) {
0N/A boolean cached = true;
0N/A
0N/A cached &= verifyBooleanCaching();
0N/A cached &= verifyByteCaching();
0N/A cached &= verifyCharacterCaching();
0N/A cached &= verifyIntegerCaching();
0N/A cached &= verifyLongCaching();
0N/A cached &= verifyShortCaching();
0N/A
0N/A if (!cached)
0N/A throw new RuntimeException("Values not cached appropriately.");
0N/A }
0N/A}