jdk/test/sun/invoke/util/ValueConversionsTest.java
changeset 26466 3bbb6a284bd4
parent 23010 6dadb192ad81
child 26474 655d08549e43
--- a/jdk/test/sun/invoke/util/ValueConversionsTest.java	Wed Sep 10 19:19:47 2014 +0400
+++ b/jdk/test/sun/invoke/util/ValueConversionsTest.java	Wed Sep 10 19:19:47 2014 +0400
@@ -25,11 +25,11 @@
 
 import sun.invoke.util.ValueConversions;
 import sun.invoke.util.Wrapper;
+
 import java.lang.invoke.MethodType;
 import java.lang.invoke.MethodHandle;
 import java.io.Serializable;
 import java.util.Arrays;
-import java.util.Collections;
 import org.junit.Test;
 import static org.junit.Assert.*;
 
@@ -37,24 +37,13 @@
  * @summary unit tests for value-type conversion utilities
  * @compile -XDignore.symbol.file ValueConversionsTest.java
  * @run junit/othervm test.sun.invoke.util.ValueConversionsTest
- * @run junit/othervm
- *          -DValueConversionsTest.MAX_ARITY=255 -DValueConversionsTest.START_ARITY=250
- *              test.sun.invoke.util.ValueConversionsTest
  */
 
-// This might take a while and burn lots of metadata:
-// @run junit/othervm -DValueConversionsTest.MAX_ARITY=255 -DValueConversionsTest.EXHAUSTIVE=true test.sun.invoke.util.ValueConversionsTest
-
 /**
  *
  * @author jrose
  */
 public class ValueConversionsTest {
-    private static final Class<?> CLASS = ValueConversionsTest.class;
-    private static final int MAX_ARITY = Integer.getInteger(CLASS.getSimpleName()+".MAX_ARITY", 40);
-    private static final int START_ARITY = Integer.getInteger(CLASS.getSimpleName()+".START_ARITY", 0);
-    private static final boolean EXHAUSTIVE = Boolean.getBoolean(CLASS.getSimpleName()+".EXHAUSTIVE");
-
     @Test
     public void testUnbox() throws Throwable {
         testUnbox(false);
@@ -66,9 +55,7 @@
     }
 
     private void testUnbox(boolean doCast) throws Throwable {
-        //System.out.println("unbox");
         for (Wrapper dst : Wrapper.values()) {
-            //System.out.println(dst);
             for (Wrapper src : Wrapper.values()) {
                 testUnbox(doCast, dst, src);
             }
@@ -123,10 +110,8 @@
 
     @Test
     public void testBox() throws Throwable {
-        //System.out.println("box");
         for (Wrapper w : Wrapper.values()) {
             if (w == Wrapper.VOID)  continue;  // skip this; no unboxed form
-            //System.out.println(w);
             for (int n = -5; n < 10; n++) {
                 Object box = w.wrap(n);
                 MethodHandle boxer = ValueConversions.box(w.primitiveType());
@@ -151,7 +136,6 @@
 
     @Test
     public void testCast() throws Throwable {
-        //System.out.println("cast");
         Class<?>[] types = { Object.class, Serializable.class, String.class, Number.class, Integer.class };
         Object[] objects = { new Object(), Boolean.FALSE,      "hello",      (Long)12L,    (Integer)6    };
         for (Class<?> dst : types) {
@@ -160,7 +144,6 @@
             for (Object obj : objects) {
                 Class<?> src = obj.getClass();
                 boolean canCast = dst.isAssignableFrom(src);
-                //System.out.println("obj="+obj+" <: dst="+dst+(canCast ? " (OK)" : " (will fail)"));
                 try {
                     Object result = caster.invokeExact(obj);
                     if (canCast)
@@ -177,24 +160,19 @@
 
     @Test
     public void testIdentity() throws Throwable {
-        //System.out.println("identity");
         MethodHandle id = ValueConversions.identity();
         Object expResult = "foo";
         Object result = id.invokeExact(expResult);
-        // compiler bug:  ValueConversions.identity().invokeExact("bar");
         assertEquals(expResult, result);
     }
 
     @Test
     public void testConvert() throws Throwable {
-        //System.out.println("convert");
         for (long tval = 0, ctr = 0;;) {
             if (++ctr > 99999)  throw new AssertionError("too many test values");
-            // next test value:
-            //System.out.println(Long.toHexString(tval)); // prints 3776 test patterns
+            // prints 3776 test patterns (3776 = 8*59*8)
             tval = nextTestValue(tval);
             if (tval == 0) {
-                //System.out.println("test value count = "+ctr);  // 3776 = 8*59*8
                 break;  // repeat
             }
         }
@@ -205,7 +183,6 @@
         }
     }
     static void testConvert(Wrapper src, Wrapper dst, long tval) throws Throwable {
-        //System.out.println(src+" => "+dst);
         boolean testSingleCase = (tval != 0);
         final long tvalInit = tval;
         MethodHandle conv = ValueConversions.convertPrimitive(src, dst);
@@ -269,169 +246,4 @@
         }
         return tweakSign(ux);
     }
-
-    @Test
-    public void testVarargsArray() throws Throwable {
-        //System.out.println("varargsArray");
-        final int MIN = START_ARITY;
-        final int MAX = MAX_ARITY-2;  // 253+1 would cause parameter overflow with 'this' added
-        for (int nargs = MIN; nargs <= MAX; nargs = nextArgCount(nargs, 17, MAX)) {
-            MethodHandle target = ValueConversions.varargsArray(nargs);
-            Object[] args = new Object[nargs];
-            for (int i = 0; i < nargs; i++)
-                args[i] = "#"+i;
-            Object res = target.invokeWithArguments(args);
-            assertArrayEquals(args, (Object[])res);
-        }
-    }
-
-    @Test
-    public void testVarargsReferenceArray() throws Throwable {
-        //System.out.println("varargsReferenceArray");
-        testTypedVarargsArray(Object[].class);
-        testTypedVarargsArray(String[].class);
-        testTypedVarargsArray(Number[].class);
-    }
-
-    @Test
-    public void testVarargsPrimitiveArray() throws Throwable {
-        //System.out.println("varargsPrimitiveArray");
-        testTypedVarargsArray(int[].class);
-        testTypedVarargsArray(long[].class);
-        testTypedVarargsArray(byte[].class);
-        testTypedVarargsArray(boolean[].class);
-        testTypedVarargsArray(short[].class);
-        testTypedVarargsArray(char[].class);
-        testTypedVarargsArray(float[].class);
-        testTypedVarargsArray(double[].class);
-    }
-
-    private static int nextArgCount(int nargs, int density, int MAX) {
-        if (EXHAUSTIVE)  return nargs + 1;
-        if (nargs >= MAX)  return Integer.MAX_VALUE;
-        int BOT = 20, TOP = MAX-5;
-        if (density < 10) { BOT = 10; MAX = TOP-2; }
-        if (nargs <= BOT || nargs >= TOP) {
-            ++nargs;
-        } else {
-            int bump = Math.max(1, 100 / density);
-            nargs += bump;
-            if (nargs > TOP)  nargs = TOP;
-        }
-        return nargs;
-    }
-
-    private void testTypedVarargsArray(Class<?> arrayType) throws Throwable {
-        //System.out.println(arrayType.getSimpleName());
-        Class<?> elemType = arrayType.getComponentType();
-        int MIN = START_ARITY;
-        int MAX = MAX_ARITY-2;  // 253+1 would cause parameter overflow with 'this' added
-        int density = 3;
-        if (elemType == int.class || elemType == long.class)  density = 7;
-        if (elemType == long.class || elemType == double.class) { MAX /= 2; MIN /= 2; }
-        for (int nargs = MIN; nargs <= MAX; nargs = nextArgCount(nargs, density, MAX)) {
-            Object[] args = makeTestArray(elemType, nargs);
-            MethodHandle varargsArray = ValueConversions.varargsArray(arrayType, nargs);
-            MethodType vaType = varargsArray.type();
-            assertEquals(arrayType, vaType.returnType());
-            if (nargs != 0) {
-                assertEquals(elemType, vaType.parameterType(0));
-                assertEquals(elemType, vaType.parameterType(vaType.parameterCount()-1));
-            }
-            assertEquals(MethodType.methodType(arrayType, Collections.<Class<?>>nCopies(nargs, elemType)),
-                         vaType);
-            Object res = varargsArray.invokeWithArguments(args);
-            String resString = toArrayString(res);
-            assertEquals(Arrays.toString(args), resString);
-
-            MethodHandle spreader = varargsArray.asSpreader(arrayType, nargs);
-            MethodType stype = spreader.type();
-            assert(stype == MethodType.methodType(arrayType, arrayType));
-            if (nargs <= 5) {
-                // invoke target as a spreader also:
-                @SuppressWarnings("cast")
-                Object res2 = spreader.invokeWithArguments((Object)res);
-                String res2String = toArrayString(res2);
-                assertEquals(Arrays.toString(args), res2String);
-                // invoke the spreader on a generic Object[] array; check for error
-                try {
-                    Object res3 = spreader.invokeWithArguments((Object)args);
-                    String res3String = toArrayString(res3);
-                    assertTrue(arrayType.getName(), arrayType.isAssignableFrom(Object[].class));
-                    assertEquals(Arrays.toString(args), res3String);
-                } catch (ClassCastException ex) {
-                    assertFalse(arrayType.getName(), arrayType.isAssignableFrom(Object[].class));
-                }
-            }
-            if (nargs == 0) {
-                // invoke spreader on null arglist
-                Object res3 = spreader.invokeWithArguments((Object)null);
-                String res3String = toArrayString(res3);
-                assertEquals(Arrays.toString(args), res3String);
-            }
-        }
-    }
-
-    private static Object[] makeTestArray(Class<?> elemType, int len) {
-        Wrapper elem = null;
-        if (elemType.isPrimitive())
-            elem = Wrapper.forPrimitiveType(elemType);
-        else if (Wrapper.isWrapperType(elemType))
-            elem = Wrapper.forWrapperType(elemType);
-        Object[] args = new Object[len];
-        for (int i = 0; i < len; i++) {
-            Object arg = i * 100;
-            if (elem == null) {
-                if (elemType == String.class)
-                    arg = "#"+arg;
-                arg = elemType.cast(arg);  // just to make sure
-            } else {
-                switch (elem) {
-                    case BOOLEAN: arg = (i % 3 == 0);           break;
-                    case CHAR:    arg = 'a' + i;                break;
-                    case LONG:    arg = (long)i * 1000_000_000; break;
-                    case FLOAT:   arg = (float)i / 100;         break;
-                    case DOUBLE:  arg = (double)i / 1000_000;   break;
-                }
-                arg = elem.cast(arg, elemType);
-            }
-            args[i] = arg;
-        }
-        //System.out.println(elemType.getName()+Arrays.toString(args));
-        return args;
-    }
-
-    private static String toArrayString(Object a) {
-        if (a == null)  return "null";
-        Class<?> elemType = a.getClass().getComponentType();
-        if (elemType == null)  return a.toString();
-        if (elemType.isPrimitive()) {
-            switch (Wrapper.forPrimitiveType(elemType)) {
-                case INT:      return Arrays.toString((int[])a);
-                case BYTE:     return Arrays.toString((byte[])a);
-                case BOOLEAN:  return Arrays.toString((boolean[])a);
-                case SHORT:    return Arrays.toString((short[])a);
-                case CHAR:     return Arrays.toString((char[])a);
-                case FLOAT:    return Arrays.toString((float[])a);
-                case LONG:     return Arrays.toString((long[])a);
-                case DOUBLE:   return Arrays.toString((double[])a);
-            }
-        }
-        return Arrays.toString((Object[])a);
-    }
-
-    @Test
-    public void testVarargsList() throws Throwable {
-        //System.out.println("varargsList");
-        final int MIN = START_ARITY;
-        final int MAX = MAX_ARITY-2;  // 253+1 would cause parameter overflow with 'this' added
-        for (int nargs = MIN; nargs <= MAX; nargs = nextArgCount(nargs, 7, MAX)) {
-            MethodHandle target = ValueConversions.varargsList(nargs);
-            Object[] args = new Object[nargs];
-            for (int i = 0; i < nargs; i++)
-                args[i] = "#"+i;
-            Object res = target.invokeWithArguments(args);
-            assertEquals(Arrays.asList(args), res);
-        }
-    }
 }