Java Code Examples for sun.invoke.util.Wrapper

The following examples show how to use sun.invoke.util.Wrapper. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testConvert() throws Throwable {
    for (long tval = 0, ctr = 0;;) {
        if (++ctr > 99999)  throw new AssertionError("too many test values");
        // prints 3776 test patterns (3776 = 8*59*8)
        tval = nextTestValue(tval);
        if (tval == 0) {
            break;  // repeat
        }
    }
    for (Wrapper src : Wrapper.values()) {
        for (Wrapper dst : Wrapper.values()) {
            testConvert(src, dst, 0);
        }
    }
}
 
Example 2
@Test
public void testBox() throws Throwable {
    for (Wrapper w : Wrapper.values()) {
        if (w == Wrapper.VOID)    continue;  // skip this; no unboxed form
        if (w == Wrapper.OBJECT)  continue;  // skip this; already unboxed
        for (int n = -5; n < 10; n++) {
            Object box = w.wrap(n);
            MethodHandle boxer = ValueConversions.boxExact(w);
            Object expResult = box;
            Object result = null;
            switch (w) {
                case INT:     result = (Integer) boxer.invokeExact(/*int*/n); break;
                case LONG:    result = (Long)    boxer.invokeExact((long)n); break;
                case FLOAT:   result = (Float)   boxer.invokeExact((float)n); break;
                case DOUBLE:  result = (Double)  boxer.invokeExact((double)n); break;
                case CHAR:    result = (Character) boxer.invokeExact((char)n); break;
                case BYTE:    result = (Byte)    boxer.invokeExact((byte)n); break;
                case SHORT:   result = (Short)   boxer.invokeExact((short)n); break;
                case BOOLEAN: result = (Boolean) boxer.invokeExact((n & 1) != 0); break;
            }
            assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box),
                         expResult, result);
        }
    }
}
 
Example 3
private void emitI2X(Wrapper type) {
    switch (type) {
    case BYTE:    mv.visitInsn(Opcodes.I2B);  break;
    case SHORT:   mv.visitInsn(Opcodes.I2S);  break;
    case CHAR:    mv.visitInsn(Opcodes.I2C);  break;
    case INT:     /* naught */                break;
    case LONG:    mv.visitInsn(Opcodes.I2L);  break;
    case FLOAT:   mv.visitInsn(Opcodes.I2F);  break;
    case DOUBLE:  mv.visitInsn(Opcodes.I2D);  break;
    case BOOLEAN:
        // For compatibility with ValueConversions and explicitCastArguments:
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitInsn(Opcodes.IAND);
        break;
    default:   throw new InternalError("unknown type: " + type);
    }
}
 
Example 4
private void emitPushArgument(Class<?> ptype, Object arg) {
    BasicType bptype = basicType(ptype);
    if (arg instanceof Name) {
        Name n = (Name) arg;
        emitLoadInsn(n.type, n.index());
        emitImplicitConversion(n.type, ptype, n);
    } else if ((arg == null || arg instanceof String) && bptype == L_TYPE) {
        emitConst(arg);
    } else {
        if (Wrapper.isWrapperType(arg.getClass()) && bptype != L_TYPE) {
            emitConst(arg);
        } else {
            mv.visitLdcInsn(constantPlaceholder(arg));
            emitImplicitConversion(L_TYPE, ptype, arg);
        }
    }
}
 
Example 5
private void emitI2X(Wrapper type) {
    switch (type) {
    case BYTE:    mv.visitInsn(Opcodes.I2B);  break;
    case SHORT:   mv.visitInsn(Opcodes.I2S);  break;
    case CHAR:    mv.visitInsn(Opcodes.I2C);  break;
    case INT:     /* naught */                break;
    case LONG:    mv.visitInsn(Opcodes.I2L);  break;
    case FLOAT:   mv.visitInsn(Opcodes.I2F);  break;
    case DOUBLE:  mv.visitInsn(Opcodes.I2D);  break;
    case BOOLEAN:
        // For compatibility with ValueConversions and explicitCastArguments:
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitInsn(Opcodes.IAND);
        break;
    default:   throw new InternalError("unknown type: " + type);
    }
}
 
Example 6
/**
 * Produces a method handle of the requested return type which returns the given
 * constant value every time it is invoked.
 * <p>
 * Before the method handle is returned, the passed-in value is converted to the requested type.
 * If the requested type is primitive, widening primitive conversions are attempted,
 * else reference conversions are attempted.
 * <p>The returned method handle is equivalent to {@code identity(type).bindTo(value)}.
 * @param type the return type of the desired method handle
 * @param value the value to return
 * @return a method handle of the given return type and no arguments, which always returns the given value
 * @throws NullPointerException if the {@code type} argument is null
 * @throws ClassCastException if the value cannot be converted to the required return type
 * @throws IllegalArgumentException if the given type is {@code void.class}
 */
public static
MethodHandle constant(Class<?> type, Object value) {
    if (type.isPrimitive()) {
        if (type == void.class)
            throw newIllegalArgumentException("void type");
        Wrapper w = Wrapper.forPrimitiveType(type);
        value = w.convert(value, type);
        if (w.zero().equals(value))
            return zero(w, type);
        return insertArguments(identity(type), 0, value);
    } else {
        if (value == null)
            return zero(Wrapper.OBJECT, type);
        return identity(type).bindTo(value);
    }
}
 
Example 7
/**
 * Tests that non-null wrapper reference is successfully converted to
 * primitive types.
 */
public static void testRef2Prim() {
    for (Wrapper from : Wrapper.values()) {
        for (Wrapper to : Wrapper.values()) {
            if (from == Wrapper.VOID || to == Wrapper.VOID
                    || to == Wrapper.OBJECT) {
                continue;
            }
            Object value = RANDOM_VALUES.get(from);
            for (TestConversionMode mode : TestConversionMode.values()) {
                if (from != Wrapper.OBJECT) {
                    Object convValue = to.wrap(value);
                    testConversion(mode, from.wrapperType(),
                            to.primitiveType(), value, convValue, false, null);
                } else {
                    testConversion(mode, from.wrapperType(),
                            to.primitiveType(), value, null,
                            true, ClassCastException.class);
                }
            }
        }
    }
}
 
Example 8
/**
 * Tests that primitive is successfully converted to other primitive type.
 */
public static void testPrim2Prim() {
    for (Wrapper from : Wrapper.values()) {
        for (Wrapper to : Wrapper.values()) {
            if (from == Wrapper.VOID || to == Wrapper.VOID
                    || from == Wrapper.OBJECT || to == Wrapper.OBJECT) {
                continue;
            }
            Object value = RANDOM_VALUES.get(from);
            Object convValue = to.wrap(value);
            for (TestConversionMode mode : TestConversionMode.values()) {
                testConversion(mode, from.primitiveType(),
                        to.primitiveType(), value, convValue, false, null);
            }
        }
    }
}
 
Example 9
Source Project: Java8CN   Source File: InvokerBytecodeGenerator.java    License: Apache License 2.0 6 votes vote down vote up
private void emitPushArgument(Class<?> ptype, Object arg) {
    BasicType bptype = basicType(ptype);
    if (arg instanceof Name) {
        Name n = (Name) arg;
        emitLoadInsn(n.type, n.index());
        emitImplicitConversion(n.type, ptype, n);
    } else if ((arg == null || arg instanceof String) && bptype == L_TYPE) {
        emitConst(arg);
    } else {
        if (Wrapper.isWrapperType(arg.getClass()) && bptype != L_TYPE) {
            emitConst(arg);
        } else {
            mv.visitLdcInsn(constantPlaceholder(arg));
            emitImplicitConversion(L_TYPE, ptype, arg);
        }
    }
}
 
Example 10
Source Project: AndroidComponentPlugin   Source File: Transformers.java    License: Apache License 2.0 6 votes vote down vote up
private static Object referenceArray(StackFrameReader reader, Class<?>[] ptypes,
                                     Class<?> elementType, int offset, int length) {
    Object arityArray = Array.newInstance(elementType, length);
    for (int i = 0; i < length; ++i) {
        Class<?> argumentType = ptypes[i + offset];
        Object o = null;
        switch (Wrapper.basicTypeChar(argumentType)) {
            case 'L': { o = reader.nextReference(argumentType); break; }
            case 'I': { o = reader.nextInt(); break; }
            case 'J': { o = reader.nextLong(); break; }
            case 'B': { o = reader.nextByte(); break; }
            case 'S': { o = reader.nextShort(); break; }
            case 'C': { o = reader.nextChar(); break; }
            case 'Z': { o = reader.nextBoolean(); break; }
            case 'F': { o = reader.nextFloat(); break; }
            case 'D': { o = reader.nextDouble(); break; }
        }
        Array.set(arityArray, i, elementType.cast(o));
    }
    return arityArray;
}
 
Example 11
Source Project: AndroidComponentPlugin   Source File: Transformers.java    License: Apache License 2.0 6 votes vote down vote up
private static Object intArray(StackFrameReader reader, Class<?> ptypes[],
                               int offset, int length) {
    int[] arityArray = new int[length];
    for (int i = 0; i < length; ++i) {
        Class<?> argumentType = ptypes[i + offset];
        switch (Wrapper.basicTypeChar(argumentType)) {
            case 'I': { arityArray[i] = reader.nextInt(); break; }
            case 'S': { arityArray[i] = reader.nextShort(); break; }
            case 'B': { arityArray[i] = reader.nextByte(); break; }
            default: {
                arityArray[i] = (Integer) reader.nextReference(argumentType);
                break;
            }
        }
    }
    return arityArray;
}
 
Example 12
Source Project: jdk8u-dev-jdk   Source File: MethodHandles.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Produces a method handle of the requested return type which returns the given
 * constant value every time it is invoked.
 * <p>
 * Before the method handle is returned, the passed-in value is converted to the requested type.
 * If the requested type is primitive, widening primitive conversions are attempted,
 * else reference conversions are attempted.
 * <p>The returned method handle is equivalent to {@code identity(type).bindTo(value)}.
 * @param type the return type of the desired method handle
 * @param value the value to return
 * @return a method handle of the given return type and no arguments, which always returns the given value
 * @throws NullPointerException if the {@code type} argument is null
 * @throws ClassCastException if the value cannot be converted to the required return type
 * @throws IllegalArgumentException if the given type is {@code void.class}
 */
public static
MethodHandle constant(Class<?> type, Object value) {
    if (type.isPrimitive()) {
        if (type == void.class)
            throw newIllegalArgumentException("void type");
        Wrapper w = Wrapper.forPrimitiveType(type);
        value = w.convert(value, type);
        if (w.zero().equals(value))
            return zero(w, type);
        return insertArguments(identity(type), 0, value);
    } else {
        if (value == null)
            return zero(Wrapper.OBJECT, type);
        return identity(type).bindTo(value);
    }
}
 
Example 13
Source Project: TencentKona-8   Source File: MethodHandles.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Produces a method handle of the requested return type which returns the given
 * constant value every time it is invoked.
 * <p>
 * Before the method handle is returned, the passed-in value is converted to the requested type.
 * If the requested type is primitive, widening primitive conversions are attempted,
 * else reference conversions are attempted.
 * <p>The returned method handle is equivalent to {@code identity(type).bindTo(value)}.
 * @param type the return type of the desired method handle
 * @param value the value to return
 * @return a method handle of the given return type and no arguments, which always returns the given value
 * @throws NullPointerException if the {@code type} argument is null
 * @throws ClassCastException if the value cannot be converted to the required return type
 * @throws IllegalArgumentException if the given type is {@code void.class}
 */
public static
MethodHandle constant(Class<?> type, Object value) {
    if (type.isPrimitive()) {
        if (type == void.class)
            throw newIllegalArgumentException("void type");
        Wrapper w = Wrapper.forPrimitiveType(type);
        value = w.convert(value, type);
        if (w.zero().equals(value))
            return zero(w, type);
        return insertArguments(identity(type), 0, value);
    } else {
        if (value == null)
            return zero(Wrapper.OBJECT, type);
        return identity(type).bindTo(value);
    }
}
 
Example 14
Source Project: AndroidComponentPlugin   Source File: Transformers.java    License: Apache License 2.0 6 votes vote down vote up
public static void spreadArray(int[] array, StackFrameWriter writer, MethodType type,
                               int numArgs, int offset) {
    final Class<?>[] ptypes = type.ptypes();
    for (int i = 0; i < numArgs; ++i) {
        Class<?> argumentType = ptypes[i + offset];
        int j = array[i];
        switch (Wrapper.basicTypeChar(argumentType)) {
            case 'L': { writer.putNextReference(j, argumentType); break; }
            case 'I': { writer.putNextInt(j); break; }
            case 'J': { writer.putNextLong(j); break; }
            case 'F': { writer.putNextFloat(j); break; }
            case 'D': { writer.putNextDouble(j); break; }
            default : { throw new AssertionError(); }
        }
    }
}
 
Example 15
private void emitPushArgument(Class<?> ptype, Object arg) {
    BasicType bptype = basicType(ptype);
    if (arg instanceof Name) {
        Name n = (Name) arg;
        emitLoadInsn(n.type, n.index());
        emitImplicitConversion(n.type, ptype, n);
    } else if ((arg == null || arg instanceof String) && bptype == L_TYPE) {
        emitConst(arg);
    } else {
        if (Wrapper.isWrapperType(arg.getClass()) && bptype != L_TYPE) {
            emitConst(arg);
        } else {
            mv.visitLdcInsn(constantPlaceholder(arg));
            emitImplicitConversion(L_TYPE, ptype, arg);
        }
    }
}
 
Example 16
/**
 * Tests that non-null wrapper reference is successfully converted to
 * primitive types.
 */
public static void testRef2Prim() {
    for (Wrapper from : Wrapper.values()) {
        for (Wrapper to : Wrapper.values()) {
            if (from == Wrapper.VOID || to == Wrapper.VOID
                    || to == Wrapper.OBJECT) {
                continue;
            }
            Object value = RANDOM_VALUES.get(from);
            for (TestConversionMode mode : TestConversionMode.values()) {
                if (from != Wrapper.OBJECT) {
                    Object convValue = to.wrap(value);
                    testConversion(mode, from.wrapperType(),
                            to.primitiveType(), value, convValue, false, null);
                } else {
                    testConversion(mode, from.wrapperType(),
                            to.primitiveType(), value, null,
                            true, ClassCastException.class);
                }
            }
        }
    }
}
 
Example 17
Source Project: AndroidComponentPlugin   Source File: Transformers.java    License: Apache License 2.0 6 votes vote down vote up
public static void spreadArray(char[] array,
                               StackFrameWriter writer, MethodType type,
                               int numArgs, int offset) {
    final Class<?>[] ptypes = type.ptypes();
    for (int i = 0; i < numArgs; ++i) {
        Class<?> argumentType = ptypes[i + offset];
        char c = array[i];
        switch (Wrapper.basicTypeChar(argumentType)) {
            case 'L': { writer.putNextReference(c, argumentType); break; }
            case 'I': { writer.putNextInt(c); break; }
            case 'J': { writer.putNextLong(c); break; }
            case 'C': { writer.putNextChar(c); break; }
            case 'F': { writer.putNextFloat(c); break; }
            case 'D': { writer.putNextDouble(c); break; }
            default : { throw new AssertionError(); }
        }
    }
}
 
Example 18
private void emitPushArgument(Class<?> ptype, Object arg) {
    BasicType bptype = basicType(ptype);
    if (arg instanceof Name) {
        Name n = (Name) arg;
        emitLoadInsn(n.type, n.index());
        emitImplicitConversion(n.type, ptype, n);
    } else if ((arg == null || arg instanceof String) && bptype == L_TYPE) {
        emitConst(arg);
    } else {
        if (Wrapper.isWrapperType(arg.getClass()) && bptype != L_TYPE) {
            emitConst(arg);
        } else {
            mv.visitLdcInsn(constantPlaceholder(arg));
            emitImplicitConversion(L_TYPE, ptype, arg);
        }
    }
}
 
Example 19
/**
 * Emit a boxing call.
 *
 * @param type primitive type class to box.
 */
private void emitBoxing(Class<?> type) {
    Wrapper wrapper = Wrapper.forPrimitiveType(type);
    String owner = "java/lang/" + wrapper.wrapperType().getSimpleName();
    String name  = "valueOf";
    String desc  = "(" + wrapper.basicTypeChar() + ")L" + owner + ";";
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, owner, name, desc);
}
 
Example 20
Source Project: jdk8u60   Source File: ValueConversionsTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void testConvert(Wrapper src, Wrapper dst, long tval) throws Throwable {
    if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT)  return;  // must have prims
    if (dst == Wrapper.VOID   || src == Wrapper.VOID  )  return;  // must have values
    boolean testSingleCase = (tval != 0);
    final long tvalInit = tval;
    MethodHandle conv = ValueConversions.convertPrimitive(src, dst);
    MethodType convType = MethodType.methodType(dst.primitiveType(), src.primitiveType());
    assertEquals(convType, conv.type());
    MethodHandle converter = conv.asType(conv.type().changeReturnType(Object.class));
    for (;;) {
        long n = tval;
        Object testValue = src.wrap(n);
        Object expResult = dst.cast(testValue, dst.primitiveType());
        Object result;
        switch (src) {
            case INT:     result = converter.invokeExact((int)n); break;
            case LONG:    result = converter.invokeExact(/*long*/n); break;
            case FLOAT:   result = converter.invokeExact((float)n); break;
            case DOUBLE:  result = converter.invokeExact((double)n); break;
            case CHAR:    result = converter.invokeExact((char)n); break;
            case BYTE:    result = converter.invokeExact((byte)n); break;
            case SHORT:   result = converter.invokeExact((short)n); break;
            case BOOLEAN: result = converter.invokeExact((n & 1) != 0); break;
            default:  throw new AssertionError();
        }
        assertEquals("(src,dst,n,testValue)="+Arrays.asList(src,dst,"0x"+Long.toHexString(n),testValue),
                     expResult, result);
        if (testSingleCase)  break;
        // next test value:
        tval = nextTestValue(tval);
        if (tval == tvalInit)  break;  // repeat
    }
}
 
Example 21
Source Project: jdk8u-dev-jdk   Source File: MethodHandles.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Produces a method handle which returns its sole argument when invoked.
 * @param type the type of the sole parameter and return value of the desired method handle
 * @return a unary method handle which accepts and returns the given type
 * @throws NullPointerException if the argument is null
 * @throws IllegalArgumentException if the given type is {@code void.class}
 */
public static
MethodHandle identity(Class<?> type) {
    Wrapper btw = (type.isPrimitive() ? Wrapper.forPrimitiveType(type) : Wrapper.OBJECT);
    int pos = btw.ordinal();
    MethodHandle ident = IDENTITY_MHS[pos];
    if (ident == null) {
        ident = setCachedMethodHandle(IDENTITY_MHS, pos, makeIdentity(btw.primitiveType()));
    }
    if (ident.type().returnType() == type)
        return ident;
    // something like identity(Foo.class); do not bother to intern these
    assert(btw == Wrapper.OBJECT);
    return makeIdentity(type);
}
 
Example 22
Source Project: jdk8u_jdk   Source File: LambdaForm.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static boolean checkInt(Class<?> type, Object x) {
    assert(x instanceof Integer);
    if (type == int.class)  return true;
    Wrapper w = Wrapper.forBasicType(type);
    assert(w.isSubwordOrInt());
    Object x1 = Wrapper.INT.wrap(w.wrap(x));
    return x.equals(x1);
}
 
Example 23
void emitNewArray(Name name) throws InternalError {
    Class<?> rtype = name.function.methodType().returnType();
    if (name.arguments.length == 0) {
        // The array will be a constant.
        Object emptyArray;
        try {
            emptyArray = name.function.resolvedHandle.invoke();
        } catch (Throwable ex) {
            throw newInternalError(ex);
        }
        assert(java.lang.reflect.Array.getLength(emptyArray) == 0);
        assert(emptyArray.getClass() == rtype);  // exact typing
        mv.visitLdcInsn(constantPlaceholder(emptyArray));
        emitReferenceCast(rtype, emptyArray);
        return;
    }
    Class<?> arrayElementType = rtype.getComponentType();
    assert(arrayElementType != null);
    emitIconstInsn(name.arguments.length);
    int xas = Opcodes.AASTORE;
    if (!arrayElementType.isPrimitive()) {
        mv.visitTypeInsn(Opcodes.ANEWARRAY, getInternalName(arrayElementType));
    } else {
        byte tc = arrayTypeCode(Wrapper.forPrimitiveType(arrayElementType));
        xas = arrayInsnOpcode(tc, xas);
        mv.visitIntInsn(Opcodes.NEWARRAY, tc);
    }
    // store arguments
    for (int i = 0; i < name.arguments.length; i++) {
        mv.visitInsn(Opcodes.DUP);
        emitIconstInsn(i);
        emitPushArgument(name, i);
        mv.visitInsn(xas);
    }
    // the array is left on the stack
    assertStaticType(rtype, name);
}
 
Example 24
Source Project: openjdk-jdk8u   Source File: MethodHandles.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static BoundMethodHandle insertArgumentPrimitive(BoundMethodHandle result, int pos,
                                                         Class<?> ptype, Object value) {
    Wrapper w = Wrapper.forPrimitiveType(ptype);
    // perform unboxing and/or primitive conversion
    value = w.convert(value, ptype);
    switch (w) {
    case INT:     return result.bindArgumentI(pos, (int)value);
    case LONG:    return result.bindArgumentJ(pos, (long)value);
    case FLOAT:   return result.bindArgumentF(pos, (float)value);
    case DOUBLE:  return result.bindArgumentD(pos, (double)value);
    default:      return result.bindArgumentI(pos, ValueConversions.widenSubword(value));
    }
}
 
Example 25
Source Project: jdk8u60   Source File: BoundMethodHandle.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle makeGetter(Class<?> cbmhClass, String types, int index) {
    String fieldName = makeFieldName(types, index);
    Class<?> fieldType = Wrapper.forBasicType(types.charAt(index)).primitiveType();
    try {
        return LOOKUP.findGetter(cbmhClass, fieldName, fieldType);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw newInternalError(e);
    }
}
 
Example 26
private void emitX2I(Wrapper type) {
    switch (type) {
    case LONG:    mv.visitInsn(Opcodes.L2I);  break;
    case FLOAT:   mv.visitInsn(Opcodes.F2I);  break;
    case DOUBLE:  mv.visitInsn(Opcodes.D2I);  break;
    default:      throw new InternalError("unknown type: " + type);
    }
}
 
Example 27
static
MethodHandle makeGuardWithCatch(MethodHandle target,
                                Class<? extends Throwable> exType,
                                MethodHandle catcher) {
    MethodType type = target.type();
    LambdaForm form = makeGuardWithCatchForm(type.basicType());

    // Prepare auxiliary method handles used during LambdaForm interpreation.
    // Box arguments and wrap them into Object[]: ValueConversions.array().
    MethodType varargsType = type.changeReturnType(Object[].class);
    MethodHandle collectArgs = varargsArray(type.parameterCount()).asType(varargsType);
    // Result unboxing: ValueConversions.unbox() OR ValueConversions.identity() OR ValueConversions.ignore().
    MethodHandle unboxResult;
    Class<?> rtype = type.returnType();
    if (rtype.isPrimitive()) {
        if (rtype == void.class) {
            unboxResult = ValueConversions.ignore();
        } else {
            Wrapper w = Wrapper.forPrimitiveType(type.returnType());
            unboxResult = ValueConversions.unboxExact(w);
        }
    } else {
        unboxResult = MethodHandles.identity(Object.class);
    }

    BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLL();
    BoundMethodHandle mh;
    try {
        mh = (BoundMethodHandle)
                data.constructor().invokeBasic(type, form, (Object) target, (Object) exType, (Object) catcher,
                                               (Object) collectArgs, (Object) unboxResult);
    } catch (Throwable ex) {
        throw uncaughtException(ex);
    }
    assert(mh.type() == type);
    return mh;
}
 
Example 28
/**
 * Emit an unboxing call (plus preceding checkcast).
 *
 * @param wrapper wrapper type class to unbox.
 */
private void emitUnboxing(Wrapper wrapper) {
    String owner = "java/lang/" + wrapper.wrapperType().getSimpleName();
    String name  = wrapper.primitiveSimpleName() + "Value";
    String desc  = "()" + wrapper.basicTypeChar();
    emitReferenceCast(wrapper.wrapperType(), null);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, owner, name, desc, false);
}
 
Example 29
private void emitX2I(Wrapper type) {
    switch (type) {
    case LONG:    mv.visitInsn(Opcodes.L2I);  break;
    case FLOAT:   mv.visitInsn(Opcodes.F2I);  break;
    case DOUBLE:  mv.visitInsn(Opcodes.D2I);  break;
    default:      throw new InternalError("unknown type: " + type);
    }
}
 
Example 30
/**
 * Tests that primitive is successfully converted to wrapper reference
 * types, to the Number type (if possible) and to the Object type.
 */
public static void testPrim2Ref() {
    for (Wrapper from : Wrapper.values()) {
        for (Wrapper to : Wrapper.values()) {
            if (from == Wrapper.VOID || from == Wrapper.OBJECT
                    || to == Wrapper.VOID || to == Wrapper.OBJECT) {
                continue;
            }
            Object value = RANDOM_VALUES.get(from);
            for (TestConversionMode mode : TestConversionMode.values()) {
                if (from == to) {
                    testConversion(mode, from.primitiveType(),
                            to.wrapperType(), value, value, false, null);
                } else {
                    testConversion(mode, from.primitiveType(),
                            to.wrapperType(), value, null, true, ClassCastException.class);
                }
                if (from != Wrapper.BOOLEAN && from != Wrapper.CHAR) {
                    testConversion(mode, from.primitiveType(),
                            Number.class, value, value, false, null);
                } else {
                    testConversion(mode, from.primitiveType(),
                            Number.class, value, null,
                            true, ClassCastException.class);
                }
                testConversion(mode, from.primitiveType(),
                        Object.class, value, value, false, null);
            }
        }
    }
}