3793N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. 1193N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1193N/A * This code is free software; you can redistribute it and/or modify it 1193N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 1193N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 1193N/A * This code is distributed in the hope that it will be useful, but WITHOUT 1193N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1193N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1193N/A * version 2 for more details (a copy is included in the LICENSE file that 1193N/A * You should have received a copy of the GNU General Public License version 1193N/A * 2 along with this work; if not, write to the Free Software Foundation, 1193N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 3240N/A // These must be in the order defined for widening primitive conversions in JLS 5.1.2 4183N/A //NULL(Null.class, null.class, 'N', null, null, Format.other(1)), 3240N/A // VOID must be the last type, since it is "assignable" from any other type: 4183N/A /** For debugging, give the details of this wrapper. */ 1193N/A /** How many bits are in the wrapped value? Returns 0 for OBJECT or VOID. */ 1193N/A /** How many JVM stack slots occupied by the wrapped value? Returns 0 for VOID. */ 1193N/A /** Does the wrapped value occupy a single JVM stack slot? */ 1193N/A /** Does the wrapped value occupy two JVM stack slots? */ 1193N/A /** Is the wrapped type numeric (not void or object)? */ 1193N/A /** Is the wrapped type a primitive other than float, double, or void? */ 1193N/A /** Is the wrapped type one of int, boolean, byte, char, or short? */ 1193N/A /* Is the wrapped value a signed integral type (one of byte, short, int, or long)? */ 1193N/A /* Is the wrapped value an unsigned integral type (one of boolean or char)? */ 1193N/A /** Is the wrapped type either float or double? */ 4183N/A /** Is the wrapped type either void or a reference? */ 4183N/A /** Does the JLS 5.1.2 allow a variable of this wrapper's 3240N/A * primitive type to be assigned from a value of the given wrapper's primitive type? 3240N/A * <li>unboxing followed by widening primitive conversion 4183N/A * <li>any type converted to {@code void} (i.e., dropping a method call's value) 3240N/A * <li>boxing conversion followed by widening reference conversion to {@code Object} 4250N/A * These are the cases allowed by MethodHandle.asType. 3240N/A // At best, this is a narrowing conversion. 4183N/A // All conversions are allowed in the enum order between floats and signed ints. 4183N/A // First detect non-signed non-float types (boolean, char, Object, void). 4183N/A // can convert char to int or wider, but nothing else 4183N/A // no other conversions are classified as widening 4183N/A // All signed and float conversions in the enum order are widening. 4183N/A // Check the matrix for correct classification of widening conversions. 4183N/A // check relations with unsigned integral types: 4183N/A // check relations with signed integral types: 4183N/A // check relations with floating types: 4183N/A return true;
// i.e., assert(true) 1193N/A /** Produce a zero value for the given wrapper type. 1193N/A * This will be a numeric zero for a number or character, 1193N/A * false for a boolean, and null for a reference or void. 1193N/A * The common thread is that this is what is contained 1193N/A * in a default-initialized variable of the given primitive 1193N/A * type. (For void, it is what a reflective method returns 1193N/A * instead of no value at all.) 1193N/A /** Produce a zero value for the given wrapper type T. 3240N/A * The optional argument must a type compatible with this wrapper. 1193N/A * Equivalent to {@code this.cast(this.zero(), type)}. 1193N/A// /** Produce a wrapper for the given wrapper or primitive type. */ 1193N/A// public static Wrapper valueOf(Class<?> type) { 1193N/A// if (isPrimitiveType(type)) 1193N/A// return forPrimitiveType(type); 1193N/A// return forWrapperType(type); 1193N/A /** Return the wrapper that wraps values of the given type. 1193N/A * The type may be {@code Object}, meaning the {@code OBJECT} wrapper. 1193N/A * Otherwise, the type must be a primitive. 1193N/A * @throws IllegalArgumentException for unexpected types 1193N/A /** Return the wrapper that wraps values into the given wrapper type. 4244N/A * If it is {@code Object}, return {@code OBJECT}. 1193N/A * Otherwise, it must be a wrapper type. 1193N/A * The type must not be a primitive type. 1193N/A * @throws IllegalArgumentException for unexpected types 1193N/A /** Return the wrapper that corresponds to the given bytecode 1193N/A * signature character. Return {@code OBJECT} for the character 'L'. 1193N/A * @throws IllegalArgumentException for any non-signature character or {@code '['}. 1193N/A /** Return the wrapper for the given type, if it is 1193N/A * a primitive type, else return {@code OBJECT}. 1193N/A return OBJECT;
// any reference, including wrappers or arrays 1193N/A // for signature chars c, do (c + (c >> 1)) % 16 1193N/A // for primitive type names n, do (n[0] + n[2]) % 16 1193N/A // The type name hash works for both primitive and wrapper names. 1193N/A // But you add the wrapper name Object, use (n[2] + (3*n[1])) % 16. 1193N/A return (x + (x >>
1)) %
16;
3793N/A //assert(jdk.sun.invoke.util.WrapperTest.test(false)); 1193N/A /** What is the primitive type wrapped by this wrapper? */ 1193N/A /** What is the wrapper type for this wrapper? */ 1193N/A /** What is the wrapper type for this wrapper? 2040N/A * Otherwise, the example type must be the wrapper type, 1193N/A * or the corresponding primitive type. 2040N/A * (For {@code OBJECT}, the example type can be any non-primitive, 2040N/A * and is normalized to {@code Object.class}.) 1193N/A * The resulting class type has the same type parameter. 1193N/A /** If {@code type} is a primitive type, return the corresponding 1193N/A * wrapper type, else return {@code type} unchanged. 1193N/A /** If {@code type} is a wrapper type, return the corresponding 1193N/A * primitive type, else return {@code type} unchanged. 1193N/A /** Query: Is the given type a wrapper, such as {@code Integer} or {@code Void}? */ 1193N/A /** Query: Is the given type a primitive, such as {@code int} or {@code void}? */ 2040N/A /** What is the bytecode signature character for this type? 2040N/A * All non-primitives, including array types, report as 'L', the signature character for references. 1193N/A /** What is the bytecode signature character for this wrapper's 1193N/A /** What is the simple name of the wrapper type? 5459N/A /** What is the simple name of the primitive type? 1193N/A// /** Wrap a value in the given type, which may be either a primitive or wrapper type. 1193N/A// * Performs standard primitive conversions, including truncation and float conversions. 1193N/A// public static <T> T wrap(Object x, Class<T> type) { 1193N/A// return Wrapper.valueOf(type).cast(x, type); 1193N/A /** Cast a wrapped value to the given type, which may be either a primitive or wrapper type. 3240N/A * The given target type must be this wrapper's primitive or wrapper type. 3240N/A * If this wrapper is OBJECT, the target type may also be an interface, perform no runtime check. 1193N/A * Performs standard primitive conversions, including truncation and float conversions. 1193N/A * The given type must be compatible with this wrapper. That is, it must either 2040N/A * be the wrapper type (or a subtype, in the case of {@code OBJECT}) or else 1193N/A * it must be the wrapper's primitive type. 3240N/A * Primitive conversions are only performed if the given type is itself a primitive. 1193N/A * @throws ClassCastException if the given type is not compatible with this wrapper 3240N/A /** Convert a wrapped value to the given type. 3240N/A * The given target type must be this wrapper's primitive or wrapper type. 3240N/A * This is equivalent to {@link #cast}, except that it refuses to perform 3240N/A * narrowing primitive conversions. 3240N/A // If the target wrapper is OBJECT, just do a reference cast. 3240N/A // If the target type is an interface, perform no runtime check. 3240N/A // (This loophole is safe, and is allowed by the JVM verifier.) 3240N/A // If the target type is a primitive, change it to a wrapper. 1193N/A /** Cast a reference type to another reference type. 1193N/A * If the target type is an interface, perform no runtime check. 1193N/A * (This loophole is safe, and is allowed by the JVM verifier.) 1193N/A * If the target type is a primitive, change it to a wrapper. 1193N/A /** Wrap a value in this wrapper's type. 1193N/A * Performs standard primitive conversions, including truncation and float conversions. 1193N/A * Performs returns the unchanged reference for {@code OBJECT}. 1193N/A * Returns null for {@code VOID}. 1193N/A * Returns a zero value for a null input. 1193N/A * @throws ClassCastException if this wrapper is numeric and the operand 1193N/A * is not a number, character, boolean, or null 1193N/A // do non-numeric wrappers first 1193N/A /** Wrap a value (an int or smaller value) in this wrapper's type. 1193N/A * Performs standard primitive conversions, including truncation and float conversions. 1193N/A * Produces an {@code Integer} for {@code OBJECT}, although the exact type 1193N/A * of the operand is not known. 1193N/A * Returns null for {@code VOID}. 1193N/A // Remaining allowed case of void: Must be a null reference. 5459N/A // Parameter type of boolValue must be byte, because 5459N/A // MethodHandles.explicitCastArguments defines boolean 5459N/A // conversion as first converting to byte. 4183N/A //Already done: value = convert(value, primitiveType);