jdk/test/java/lang/invoke/RicochetTest.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 14408 db08012d1d6f
child 23010 6dadb192ad81
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13610
diff changeset
     2
 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
     4
 *
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 14408
diff changeset
     7
 * published by the Free Software Foundation.
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
     8
 *
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    13
 * accompanied this code).
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    14
 *
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    18
 *
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    21
 * questions.
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    22
 */
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    23
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    24
/* @test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    25
 * @summary unit tests for recursive method handles
14408
db08012d1d6f 7197210: java/lang/invoke/CallSiteTest.java failing on armsflt.
jiangli
parents: 14342
diff changeset
    26
 * @run junit/othervm/timeout=3600 -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -DRicochetTest.MAX_ARITY=10 test.java.lang.invoke.RicochetTest
9781
ce852878da20 7049122: java/lang/invoke/RicochetTest.java with MAX_ARITY=255 in -Xcomp mode overflows code cache
jrose
parents: 9646
diff changeset
    27
 */
ce852878da20 7049122: java/lang/invoke/RicochetTest.java with MAX_ARITY=255 in -Xcomp mode overflows code cache
jrose
parents: 9646
diff changeset
    28
/*
ce852878da20 7049122: java/lang/invoke/RicochetTest.java with MAX_ARITY=255 in -Xcomp mode overflows code cache
jrose
parents: 9646
diff changeset
    29
 * @ignore The following test creates an unreasonable number of adapters in -Xcomp mode (7049122)
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    30
 * @run junit/othervm -DRicochetTest.MAX_ARITY=255 test.java.lang.invoke.RicochetTest
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    31
 */
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    32
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    33
package test.java.lang.invoke;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    34
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    35
import java.lang.invoke.*;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    36
import java.util.*;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    37
import org.junit.*;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    38
import static java.lang.invoke.MethodType.*;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    39
import static java.lang.invoke.MethodHandles.*;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    40
import static org.junit.Assert.*;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    41
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    42
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    43
/**
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    44
 *
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    45
 * @author jrose
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    46
 */
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    47
public class RicochetTest {
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10081
diff changeset
    48
    private static final Class<?> CLASS = RicochetTest.class;
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    49
    private static final int MAX_ARITY = Integer.getInteger(CLASS.getSimpleName()+".MAX_ARITY", 40);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    50
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    51
    public static void main(String... av) throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    52
        RicochetTest test = new RicochetTest();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    53
        if (av.length > 0)  test.testOnly = Arrays.asList(av).toString();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    54
        if (REPEAT == 1 || test.testOnly != null) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    55
            test.testAll();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    56
            if (test.testOnlyTests == null)  throw new RuntimeException("no matching test: "+test.testOnly);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    57
        } else if (REPEAT == 0) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    58
            org.junit.runner.JUnitCore.runClasses(RicochetTest.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    59
        } else {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    60
            verbose(1, "REPEAT="+REPEAT);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    61
            for (int i = 0; i < REPEAT; i++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    62
                test.testRepetition = (i+1);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    63
                verbose(0, "[#"+test.testRepetition+"]");
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    64
                test.testAll();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    65
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    66
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    67
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    68
    int testRepetition;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    69
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    70
    public void testAll() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    71
        testNull();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    72
        testBoxInteger();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    73
        testFilterReturnValue();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    74
        testFilterObject();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    75
        testBoxLong();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    76
        testFilterInteger();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    77
        testIntSpreads();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    78
        testByteSpreads();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    79
        testLongSpreads();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    80
        testIntCollects();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    81
        testReturns();
10081
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
    82
        testRecursion();
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    83
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    84
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    85
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    86
    public void testNull() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    87
        if (testRepetition > (1+REPEAT/100))  return;  // trivial test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    88
        if (!startTest("testNull"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    89
        assertEquals(opI(37), opI.invokeWithArguments(37));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    90
        assertEqualFunction(opI, opI);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    91
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    92
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    93
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    94
    public void testBoxInteger() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    95
        if (!startTest("testBoxInteger"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    96
        assertEqualFunction(opI, opI.asType(opL_I.type()).asType(opI.type()));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    97
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    98
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
    99
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   100
    public void testFilterReturnValue() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   101
        if (!startTest("testFilterReturnValue"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   102
        int[] ints = { 12, 23, 34, 45, 56, 67, 78, 89 };
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   103
        Object res = list8ints.invokeExact(ints[0], ints[1], ints[2], ints[3], ints[4], ints[5], ints[6], ints[7]);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   104
        assertEquals(Arrays.toString(ints), res.toString());
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   105
        MethodHandle idreturn = filterReturnValue(list8ints, identity(Object.class));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   106
        res = idreturn.invokeExact(ints[0], ints[1], ints[2], ints[3], ints[4], ints[5], ints[6], ints[7]);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   107
        assertEquals(Arrays.toString(ints), res.toString());
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   108
        MethodHandle add0 = addL.bindTo(0);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   109
        assertEqualFunction(filterReturnValue(opL2, add0), opL2);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   110
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   111
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   112
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   113
    public void testFilterObject() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   114
        if (!startTest("testFilterObject"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   115
        MethodHandle add0 = addL.bindTo(0);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   116
        assertEqualFunction(sequence(opL2, add0), opL2);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   117
        int bump13 = -13;  // value near 20 works as long as test values are near [-80..80]
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   118
        MethodHandle add13   = addL.bindTo(bump13);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   119
        MethodHandle add13_0 = addL.bindTo(opI2(bump13, 0));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   120
        MethodHandle add13_1 = addL.bindTo(opI2(0, bump13));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   121
        assertEqualFunction(sequence(opL2, add13_0),
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   122
                            filterArguments(opL2, 0, add13));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   123
        assertEqualFunction(sequence(opL2, add13_1),
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   124
                            filterArguments(opL2, 1, add13));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   125
        System.out.println("[testFilterObject done]");
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   126
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   127
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   128
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   129
    public void testBoxLong() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   130
        if (!startTest("testBoxLong"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   131
        assertEqualFunction(opJ, opJ.asType(opL_J.type()).asType(opJ.type()));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   132
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   133
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   134
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   135
    public void testFilterInteger() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   136
        if (!startTest("testFilterInteger"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   137
        assertEqualFunction(opI, sequence(convI_L, opL_I));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   138
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   139
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   140
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   141
    public void testIntSpreads() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   142
        if (!startTest("testIntSpreads"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   143
        MethodHandle id = identity(int[].class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   144
        final int MAX = MAX_ARITY-2;  // 253+1 would cause parameter overflow with 'this' added
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   145
        for (int nargs = 0; nargs <= MAX; nargs++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   146
            if (nargs > 30 && nargs < MAX-20)  nargs += 10;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   147
            int[] args = new int[nargs];
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10081
diff changeset
   148
            for (int j = 0; j < args.length; j++)  args[j] = j + 11;
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   149
            //System.out.println("testIntSpreads "+Arrays.toString(args));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   150
            int[] args1 = (int[]) id.invokeExact(args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   151
            assertArrayEquals(args, args1);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   152
            MethodHandle coll = id.asCollector(int[].class, nargs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   153
            int[] args2 = args;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   154
            switch (nargs) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   155
                case 0:  args2 = (int[]) coll.invokeExact(); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   156
                case 1:  args2 = (int[]) coll.invokeExact(args[0]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   157
                case 2:  args2 = (int[]) coll.invokeExact(args[0], args[1]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   158
                case 3:  args2 = (int[]) coll.invokeExact(args[0], args[1], args[2]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   159
                case 4:  args2 = (int[]) coll.invokeExact(args[0], args[1], args[2], args[3]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   160
                case 5:  args2 = (int[]) coll.invokeExact(args[0], args[1], args[2], args[3], args[4]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   161
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   162
            assertArrayEquals(args, args2);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   163
            MethodHandle mh = coll.asSpreader(int[].class, nargs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   164
            int[] args3 = (int[]) mh.invokeExact(args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   165
            assertArrayEquals(args, args3);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   166
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   167
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   168
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   169
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   170
    public void testByteSpreads() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   171
        if (!startTest("testByteSpreads"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   172
        MethodHandle id = identity(byte[].class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   173
        final int MAX = MAX_ARITY-2;  // 253+1 would cause parameter overflow with 'this' added
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   174
        for (int nargs = 0; nargs <= MAX; nargs++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   175
            if (nargs > 30 && nargs < MAX-20)  nargs += 10;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   176
            byte[] args = new byte[nargs];
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   177
            for (int j = 0; j < args.length; j++)  args[j] = (byte)(j + 11);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   178
            //System.out.println("testByteSpreads "+Arrays.toString(args));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   179
            byte[] args1 = (byte[]) id.invokeExact(args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   180
            assertArrayEquals(args, args1);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   181
            MethodHandle coll = id.asCollector(byte[].class, nargs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   182
            byte[] args2 = args;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   183
            switch (nargs) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   184
                case 0:  args2 = (byte[]) coll.invokeExact(); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   185
                case 1:  args2 = (byte[]) coll.invokeExact(args[0]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   186
                case 2:  args2 = (byte[]) coll.invokeExact(args[0], args[1]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   187
                case 3:  args2 = (byte[]) coll.invokeExact(args[0], args[1], args[2]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   188
                case 4:  args2 = (byte[]) coll.invokeExact(args[0], args[1], args[2], args[3]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   189
                case 5:  args2 = (byte[]) coll.invokeExact(args[0], args[1], args[2], args[3], args[4]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   190
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   191
            assertArrayEquals(args, args2);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   192
            MethodHandle mh = coll.asSpreader(byte[].class, nargs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   193
            byte[] args3 = (byte[]) mh.invokeExact(args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   194
            assertArrayEquals(args, args3);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   195
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   196
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   197
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   198
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   199
    public void testLongSpreads() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   200
        if (!startTest("testLongSpreads"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   201
        MethodHandle id = identity(long[].class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   202
        final int MAX = (MAX_ARITY - 2) / 2;  // 253/2+1 would cause parameter overflow with 'this' added
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   203
        for (int nargs = 0; nargs <= MAX; nargs++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   204
            if (nargs > 30 && nargs < MAX-20)  nargs += 10;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   205
            long[] args = new long[nargs];
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   206
            for (int j = 0; j < args.length; j++)  args[j] = (long)(j + 11);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   207
            //System.out.println("testLongSpreads "+Arrays.toString(args));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   208
            long[] args1 = (long[]) id.invokeExact(args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   209
            assertArrayEquals(args, args1);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   210
            MethodHandle coll = id.asCollector(long[].class, nargs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   211
            long[] args2 = args;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   212
            switch (nargs) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   213
                case 0:  args2 = (long[]) coll.invokeExact(); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   214
                case 1:  args2 = (long[]) coll.invokeExact(args[0]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   215
                case 2:  args2 = (long[]) coll.invokeExact(args[0], args[1]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   216
                case 3:  args2 = (long[]) coll.invokeExact(args[0], args[1], args[2]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   217
                case 4:  args2 = (long[]) coll.invokeExact(args[0], args[1], args[2], args[3]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   218
                case 5:  args2 = (long[]) coll.invokeExact(args[0], args[1], args[2], args[3], args[4]); break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   219
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   220
            assertArrayEquals(args, args2);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   221
            MethodHandle mh = coll.asSpreader(long[].class, nargs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   222
            long[] args3 = (long[]) mh.invokeExact(args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   223
            assertArrayEquals(args, args3);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   224
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   225
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   226
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   227
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   228
    public void testIntCollects() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   229
        if (!startTest("testIntCollects"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   230
        for (MethodHandle lister : INT_LISTERS) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   231
            int outputs = lister.type().parameterCount();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   232
            for (int collects = 0; collects <= Math.min(outputs, INT_COLLECTORS.length-1); collects++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   233
                int inputs = outputs - 1 + collects;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   234
                if (inputs < 0)  continue;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   235
                for (int pos = 0; pos + collects <= inputs; pos++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   236
                    MethodHandle collector = INT_COLLECTORS[collects];
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   237
                    int[] args = new int[inputs];
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   238
                    int ap = 0, arg = 31;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   239
                    for (int i = 0; i < pos; i++)
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   240
                        args[ap++] = arg++ + 0;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   241
                    for (int i = 0; i < collects; i++)
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   242
                        args[ap++] = arg++ + 10;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   243
                    while (ap < args.length)
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   244
                        args[ap++] = arg++ + 20;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   245
                    // calculate piecemeal:
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   246
                    //System.out.println("testIntCollects "+Arrays.asList(lister, pos, collector)+" on "+Arrays.toString(args));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   247
                    int[] collargs = Arrays.copyOfRange(args, pos, pos+collects);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   248
                    int coll = (int) collector.asSpreader(int[].class, collargs.length).invokeExact(collargs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   249
                    int[] listargs = Arrays.copyOfRange(args, 0, outputs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   250
                    System.arraycopy(args, pos+collects, listargs, pos+1, outputs - (pos+1));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   251
                    listargs[pos] = coll;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   252
                    //System.out.println("  coll="+coll+" listargs="+Arrays.toString(listargs));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   253
                    Object expect = lister.asSpreader(int[].class, listargs.length).invokeExact(listargs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   254
                    //System.out.println("  expect="+expect);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   255
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   256
                    // now use the combined MH, and test the output:
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   257
                    MethodHandle mh = collectArguments(lister, pos, int[].class, INT_COLLECTORS[collects]);
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   258
                    if (mh == null)  continue;  // no infix collection, yet
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   259
                    assert(mh.type().parameterCount() == inputs);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   260
                    Object observe = mh.asSpreader(int[].class, args.length).invokeExact(args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   261
                    assertEquals(expect, observe);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   262
                }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   263
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   264
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   265
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   266
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   267
    @Test
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   268
    public void testByteCollects() throws Throwable {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   269
        if (!startTest("testByteCollects"))  return;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   270
        for (MethodHandle lister : BYTE_LISTERS) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   271
            int outputs = lister.type().parameterCount();
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   272
            for (int collects = 0; collects <= Math.min(outputs, BYTE_COLLECTORS.length-1); collects++) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   273
                int inputs = outputs - 1 + collects;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   274
                if (inputs < 0)  continue;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   275
                for (int pos = 0; pos + collects <= inputs; pos++) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   276
                    MethodHandle collector = BYTE_COLLECTORS[collects];
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   277
                    byte[] args = new byte[inputs];
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   278
                    int ap = 0, arg = 31;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   279
                    for (int i = 0; i < pos; i++)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   280
                        args[ap++] = (byte)(arg++ + 0);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   281
                    for (int i = 0; i < collects; i++)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   282
                        args[ap++] = (byte)(arg++ + 10);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   283
                    while (ap < args.length)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   284
                        args[ap++] = (byte)(arg++ + 20);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   285
                    // calculate piecemeal:
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   286
                    //System.out.println("testIntCollects "+Arrays.asList(lister, pos, collector)+" on "+Arrays.toString(args));
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   287
                    byte[] collargs = Arrays.copyOfRange(args, pos, pos+collects);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   288
                    byte coll = (byte) collector.asSpreader(byte[].class, collargs.length).invokeExact(collargs);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   289
                    byte[] listargs = Arrays.copyOfRange(args, 0, outputs);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   290
                    System.arraycopy(args, pos+collects, listargs, pos+1, outputs - (pos+1));
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   291
                    listargs[pos] = coll;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   292
                    //System.out.println("  coll="+coll+" listargs="+Arrays.toString(listargs));
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   293
                    Object expect = lister.asSpreader(byte[].class, listargs.length).invokeExact(listargs);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   294
                    //System.out.println("  expect="+expect);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   295
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   296
                    // now use the combined MH, and test the output:
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   297
                    MethodHandle mh = collectArguments(lister, pos, byte[].class, BYTE_COLLECTORS[collects]);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   298
                    if (mh == null)  continue;  // no infix collection, yet
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   299
                    assert(mh.type().parameterCount() == inputs);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   300
                    Object observe = mh.asSpreader(byte[].class, args.length).invokeExact(args);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   301
                    assertEquals(expect, observe);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   302
                }
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   303
            }
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   304
        }
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   305
    }
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   306
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   307
    private static MethodHandle collectArguments(MethodHandle lister, int pos, Class<?> array, MethodHandle collector) {
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   308
        int collects = collector.type().parameterCount();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   309
        int outputs = lister.type().parameterCount();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   310
        if (pos == outputs - 1)
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   311
            return MethodHandles.filterArguments(lister, pos,
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   312
                        collector.asSpreader(array, collects))
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   313
                            .asCollector(array, collects);
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   314
        //return MethodHandles.collectArguments(lister, pos, collector); //no such animal
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   315
        return null;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   316
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   317
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   318
    private static final Class<?>[] RETURN_TYPES = {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   319
        Object.class, String.class, Integer.class,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   320
        int.class, long.class,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   321
        boolean.class, byte.class, char.class, short.class,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   322
        float.class, double.class,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   323
        void.class,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   324
    };
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   325
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   326
    @Test
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   327
    public void testReturns() throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   328
        if (!startTest("testReturns"))  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   329
        // fault injection:
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   330
        int faultCount = 0;  // total of 1296 tests
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   331
        faultCount = Integer.getInteger("testReturns.faultCount", 0);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   332
        for (Class<?> ret : RETURN_TYPES) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   333
            // make a complicated identity function and pass something through it
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   334
            System.out.println(ret.getSimpleName());
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   335
            Class<?> vret = (ret == void.class) ? Void.class : ret;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   336
            MethodHandle id = // (vret)->ret
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   337
                identity(vret).asType(methodType(ret, vret));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   338
            final int LENGTH = 4;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   339
            int[] index = {0};
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   340
            Object vals = java.lang.reflect.Array.newInstance(vret, LENGTH);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   341
            MethodHandle indexGetter =  //()->int
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   342
                insertArguments(arrayElementGetter(index.getClass()), 0, index, 0);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   343
            MethodHandle valSelector =  // (int)->vret
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   344
                arrayElementGetter(vals.getClass()).bindTo(vals);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   345
            MethodHandle valGetter =  // ()->vret
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   346
                foldArguments(valSelector, indexGetter);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   347
            if (ret != void.class) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   348
                for (int i = 0; i < LENGTH; i++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   349
                    Object val = (i + 50);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   350
                    if (ret == boolean.class)  val = (i % 3 == 0);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   351
                    if (ret == String.class)   val = "#"+i;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   352
                    if (ret == char.class)     val = (char)('a'+i);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   353
                    if (ret == byte.class)     val = (byte)~i;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   354
                    if (ret == short.class)    val = (short)(1<<i);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   355
                    java.lang.reflect.Array.set(vals, i, val);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   356
                }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   357
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   358
            for (int i = 0; i < LENGTH; i++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   359
                Object val = java.lang.reflect.Array.get(vals, i);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   360
                System.out.println(i+" => "+val);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   361
                index[0] = i;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   362
                if (--faultCount == 0)  index[0] ^= 1;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   363
                Object x = valGetter.invokeWithArguments();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   364
                assertEquals(val, x);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   365
                // make a return-filter call:  x = id(valGetter())
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   366
                if (--faultCount == 0)  index[0] ^= 1;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   367
                x = filterReturnValue(valGetter, id).invokeWithArguments();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   368
                assertEquals(val, x);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   369
                // make a filter call:  x = id(*,valGetter(),*)
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   370
                for (int len = 1; len <= 4; len++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   371
                    for (int pos = 0; pos < len; pos++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   372
                        MethodHandle proj = id;  // lambda(..., vret x,...){x}
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   373
                        for (int j = 0; j < len; j++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   374
                            if (j == pos)  continue;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   375
                            proj = dropArguments(proj, j, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   376
                        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   377
                        assert(proj.type().parameterCount() == len);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   378
                        // proj: (Object*, pos: vret, Object*)->ret
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   379
                        assertEquals(vret, proj.type().parameterType(pos));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   380
                        MethodHandle vgFilter = dropArguments(valGetter, 0, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   381
                        if (--faultCount == 0)  index[0] ^= 1;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   382
                        x = filterArguments(proj, pos, vgFilter).invokeWithArguments(new Object[len]);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   383
                        assertEquals(val, x);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   384
                    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   385
                }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   386
                // make a fold call:
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   387
                for (int len = 0; len <= 4; len++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   388
                    for (int fold = 0; fold <= len; fold++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   389
                        MethodHandle proj = id;  // lambda(ret x, ...){x}
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   390
                        if (ret == void.class)  proj = constant(Object.class, null);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   391
                        int arg0 = (ret == void.class ? 0 : 1);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   392
                        for (int j = 0; j < len; j++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   393
                            proj = dropArguments(proj, arg0, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   394
                        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   395
                        assert(proj.type().parameterCount() == arg0 + len);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   396
                        // proj: (Object*, pos: vret, Object*)->ret
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   397
                        if (arg0 != 0)  assertEquals(vret, proj.type().parameterType(0));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   398
                        MethodHandle vgFilter = valGetter.asType(methodType(ret));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   399
                        for (int j = 0; j < fold; j++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   400
                            vgFilter = dropArguments(vgFilter, j, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   401
                        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   402
                        x = foldArguments(proj, vgFilter).invokeWithArguments(new Object[len]);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   403
                        if (--faultCount == 0)  index[0] ^= 1;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   404
                        assertEquals(val, x);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   405
                    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   406
                }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   407
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   408
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   409
        //System.out.println("faultCount="+faultCount);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   410
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   411
10081
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   412
    @Test
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   413
    public void testRecursion() throws Throwable {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   414
        if (!startTest("testRecursion"))  return;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   415
        final int LIMIT = 10;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   416
        for (int i = 0; i < LIMIT; i++) {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   417
            RFCB rfcb = new RFCB(i);
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   418
            Object x = "x", y = "y";
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   419
            Object result = rfcb.recursiveFunction(x, y);
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   420
            verbose(1, result);
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   421
        }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   422
    }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   423
    /** Recursive Function Control Block */
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   424
    private static class RFCB {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   425
        java.util.Random random;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   426
        final MethodHandle[] fns;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   427
        int depth;
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10081
diff changeset
   428
        @SuppressWarnings("LeakingThisInConstructor")
10081
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   429
        RFCB(int seed) throws Throwable {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   430
            this.random = new java.util.Random(seed);
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   431
            this.fns = new MethodHandle[Math.max(29, (1 << MAX_DEPTH-2)/3)];
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   432
            java.util.Arrays.fill(fns, lookup().bind(this, "recursiveFunction", genericMethodType(2)));
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   433
            for (int i = 5; i < fns.length; i++) {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   434
                switch (i % 4) {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   435
                case 0: fns[i] = filterArguments(fns[i - 5], 0, insertArguments(fns[i - 4], 1, ".")); break;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   436
                case 1: fns[i] = filterArguments(fns[i - 5], 1, insertArguments(fns[i - 3], 1, ".")); break;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   437
                case 2: fns[i] = filterReturnValue(fns[i - 5], insertArguments(fns[i - 2], 1, ".")); break;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   438
                }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   439
            }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   440
        }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   441
        Object recursiveFunction(Object x, Object y) throws Throwable {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   442
            depth++;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   443
            try {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   444
                final int ACTION_COUNT = 11;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   445
                switch (random.nextInt(ACTION_COUNT)) {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   446
                case 1:
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   447
                    Throwable ex = new RuntimeException();
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   448
                    ex.fillInStackTrace();
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10081
diff changeset
   449
                    if (VERBOSITY >= 2) ex.printStackTrace(System.out);
10081
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   450
                    x = "ST; " + x;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   451
                    break;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   452
                case 2:
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   453
                    System.gc();
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   454
                    x = "GC; " + x;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   455
                    break;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   456
                }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   457
                boolean isLeaf = (depth >= MAX_DEPTH);
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   458
                if (isLeaf) {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   459
                    return Arrays.asList(x, y).toString();
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   460
                }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   461
                return fns[random.nextInt(fns.length)].invokeExact(x, y);
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   462
            } finally {
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   463
                depth--;
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   464
            }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   465
        }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   466
    }
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   467
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   468
    private static MethodHandle sequence(MethodHandle mh1, MethodHandle... mhs) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   469
        MethodHandle res = mh1;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   470
        for (MethodHandle mh2 : mhs)
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   471
            res = filterReturnValue(res, mh2);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   472
        return res;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   473
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   474
    private static void assertEqualFunction(MethodHandle x, MethodHandle y) throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   475
        assertEquals(x.type(), y.type()); //??
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   476
        MethodType t = x.type();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   477
        if (t.parameterCount() == 0) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   478
            assertEqualFunctionAt(null, x, y);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   479
            return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   480
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   481
        Class<?> ptype = t.parameterType(0);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   482
        if (ptype == long.class || ptype == Long.class) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   483
            for (long i = -10; i <= 10; i++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   484
                assertEqualFunctionAt(i, x, y);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   485
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   486
        } else {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   487
            for (int i = -10; i <= 10; i++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   488
                assertEqualFunctionAt(i, x, y);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   489
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   490
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   491
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   492
    private static void assertEqualFunctionAt(Object v, MethodHandle x, MethodHandle y) throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   493
        Object[] args = new Object[x.type().parameterCount()];
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   494
        Arrays.fill(args, v);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   495
        Object xval = invokeWithCatch(x, args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   496
        Object yval = invokeWithCatch(y, args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   497
        String msg = "ok";
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   498
        if (!Objects.equals(xval, yval)) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   499
            msg = ("applying "+x+" & "+y+" to "+v);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   500
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   501
        assertEquals(msg, xval, yval);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   502
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   503
    private static Object invokeWithCatch(MethodHandle mh, Object... args) throws Throwable {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   504
        try {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   505
            return mh.invokeWithArguments(args);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   506
        } catch (Throwable ex) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   507
            System.out.println("threw: "+mh+Arrays.asList(args));
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10081
diff changeset
   508
            ex.printStackTrace(System.out);
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   509
            return ex;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   510
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   511
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   512
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   513
    private static final Lookup LOOKUP = lookup();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   514
    private static MethodHandle findStatic(String name,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   515
                                           Class<?> rtype,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   516
                                           Class<?>... ptypes) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   517
        try {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   518
            return LOOKUP.findStatic(LOOKUP.lookupClass(), name, methodType(rtype, ptypes));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   519
        } catch (ReflectiveOperationException ex) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   520
            throw new RuntimeException(ex);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   521
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   522
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   523
    private static MethodHandle findStatic(String name,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   524
                                           Class<?> rtype,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   525
                                           List<?> ptypes) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   526
        return findStatic(name, rtype, ptypes.toArray(new Class<?>[ptypes.size()]));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   527
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   528
    static int getProperty(String name, int dflt) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   529
        String qual = LOOKUP.lookupClass().getName();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   530
        String prop = System.getProperty(qual+"."+name);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   531
        if (prop == null)  prop = System.getProperty(name);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   532
        if (prop == null)  return dflt;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   533
        return Integer.parseInt(prop);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   534
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   535
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   536
    private static int opI(int... xs) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   537
        stress();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   538
        int base = 100;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   539
        int z = 0;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   540
        for (int x : xs) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   541
            z = (z * base) + (x % base);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   542
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   543
        verbose("opI", xs.length, xs, z);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   544
        return z;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   545
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   546
    private static int opI2(int x, int y) { return opI(x, y); }  // x*100 + y%100
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   547
    private static int opI3(int x, int y, int z) { return opI(x, y, z); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   548
    private static int opI4(int w, int x, int y, int z) { return opI(w, x, y, z); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   549
    private static int opI(int x) { return opI2(x, 37); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   550
    private static Object opI_L(int x) { return (Object) opI(x); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   551
    private static long opJ3(long x, long y, long z) { return (long) opI3((int)x, (int)y, (int)z); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   552
    private static long opJ2(long x, long y) { return (long) opI2((int)x, (int)y); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   553
    private static long opJ(long x) { return (long) opI((int)x); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   554
    private static Object opL2(Object x, Object y) { return (Object) opI2((int)x, (int)y); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   555
    private static Object opL(Object x) { return (Object) opI((int)x); }
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10081
diff changeset
   556
    private static int opL2_I(Object x, Object y) { return opI2((int)x, (int)y); }
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10081
diff changeset
   557
    private static int opL_I(Object x) { return opI((int)x); }
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   558
    private static long opL_J(Object x) { return (long) opI((int)x); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   559
    private static final MethodHandle opI, opI2, opI3, opI4, opI_L, opJ, opJ2, opJ3, opL2, opL, opL2_I, opL_I, opL_J;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   560
    static {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   561
        opI4 = findStatic("opI4", int.class, int.class, int.class, int.class, int.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   562
        opI3 = findStatic("opI3", int.class, int.class, int.class, int.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   563
        opI2 = findStatic("opI2", int.class, int.class, int.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   564
        opI = findStatic("opI", int.class, int.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   565
        opI_L = findStatic("opI_L", Object.class, int.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   566
        opJ = findStatic("opJ", long.class, long.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   567
        opJ2 = findStatic("opJ2", long.class, long.class, long.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   568
        opJ3 = findStatic("opJ3", long.class, long.class, long.class, long.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   569
        opL2 = findStatic("opL2", Object.class, Object.class, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   570
        opL = findStatic("opL", Object.class, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   571
        opL2_I = findStatic("opL2_I", int.class, Object.class, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   572
        opL_I = findStatic("opL_I", int.class, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   573
        opL_J = findStatic("opL_J", long.class, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   574
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   575
    private static final MethodHandle[] INT_COLLECTORS = {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   576
        constant(int.class, 42), opI, opI2, opI3, opI4
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   577
    };
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   578
    private static final MethodHandle[] BYTE_COLLECTORS = {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   579
        constant(byte.class, (byte)42), i2b(opI), i2b(opI2), i2b(opI3), i2b(opI4)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   580
    };
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   581
    private static final MethodHandle[] LONG_COLLECTORS = {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   582
        constant(long.class, 42), opJ, opJ2, opJ3
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   583
    };
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   584
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   585
    private static int addI(int x, int y) { stress(); return x+y; }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   586
    private static Object addL(Object x, Object y) { return addI((int)x, (int)y); }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   587
    private static final MethodHandle addI, addL;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   588
    static {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   589
        addI = findStatic("addI", int.class, int.class, int.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   590
        addL = findStatic("addL", Object.class, Object.class, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   591
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   592
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   593
    private static Object list8ints(int a, int b, int c, int d, int e, int f, int g, int h) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   594
        return Arrays.asList(a, b, c, d, e, f, g, h);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   595
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   596
    private static Object list8longs(long a, long b, long c, long d, long e, long f, long g, long h) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   597
        return Arrays.asList(a, b, c, d, e, f, g, h);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   598
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   599
    private static final MethodHandle list8ints = findStatic("list8ints", Object.class,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   600
                                                             Collections.nCopies(8, int.class));
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   601
    private static final MethodHandle list8longs = findStatic("list8longs", Object.class,
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   602
                                                              Collections.nCopies(8, long.class));
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   603
    private static final MethodHandle[] INT_LISTERS, LONG_LISTERS, BYTE_LISTERS;
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   604
    static {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   605
        int listerCount = list8ints.type().parameterCount() + 1;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   606
        INT_LISTERS  = new MethodHandle[listerCount];
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   607
        LONG_LISTERS = new MethodHandle[listerCount];
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   608
        BYTE_LISTERS = new MethodHandle[listerCount];
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   609
        MethodHandle lister = list8ints;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   610
        MethodHandle llister = list8longs;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   611
        for (int i = listerCount - 1; ; i--) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   612
            INT_LISTERS[i] = lister;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   613
            LONG_LISTERS[i] = llister;
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   614
            BYTE_LISTERS[i] = i2b(lister);
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   615
            if (i == 0)  break;
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10081
diff changeset
   616
            lister  = insertArguments(lister,  i-1, 0);
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10081
diff changeset
   617
            llister = insertArguments(llister, i-1, 0L);
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   618
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   619
    }
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   620
    private static MethodHandle i2b(MethodHandle mh) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   621
        return MethodHandles.explicitCastArguments(mh, subst(mh.type(), int.class, byte.class));
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   622
    }
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   623
    private static MethodType subst(MethodType mt, Class<?> from, Class<?> to) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   624
        for (int i = 0; i < mt.parameterCount(); i++) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   625
            if (mt.parameterType(i) == from)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   626
                mt = mt.changeParameterType(i, to);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   627
        }
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   628
        if (mt.returnType() == from)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   629
            mt = mt.changeReturnType(to);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   630
        return mt;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   631
    }
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   632
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   633
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   634
    private static Object  convI_L(int     x) { stress(); return (Object)  x; }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   635
    private static int     convL_I(Object  x) { stress(); return (int)     x; }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   636
    private static Object  convJ_L(long    x) { stress(); return (Object)  x; }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   637
    private static long    convL_J(Object  x) { stress(); return (long)    x; }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   638
    private static int     convJ_I(long    x) { stress(); return (int)     x; }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   639
    private static long    convI_J(int     x) { stress(); return (long)    x; }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   640
    private static final MethodHandle convI_L, convL_I, convJ_L, convL_J, convJ_I, convI_J;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   641
    static {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   642
        convI_L = findStatic("convI_L", Object.class, int.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   643
        convL_I = findStatic("convL_I", int.class, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   644
        convJ_L = findStatic("convJ_L", Object.class, long.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   645
        convL_J = findStatic("convL_J", long.class, Object.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   646
        convJ_I = findStatic("convJ_I", int.class, long.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   647
        convI_J = findStatic("convI_J", long.class, int.class);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   648
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   649
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   650
    // stress modes:
10081
0f7b9636aa64 7058651: JSR 292 unit tests need a refresh
jrose
parents: 9781
diff changeset
   651
    private static final int MAX_DEPTH = getProperty("MAX_DEPTH", 5);
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   652
    private static final int REPEAT = getProperty("REPEAT", 0);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   653
    private static final int STRESS = getProperty("STRESS", 0);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   654
    private static /*v*/ int STRESS_COUNT;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   655
    private static final Object[] SINK = new Object[4];
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   656
    private static void stress() {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   657
        if (STRESS <= 0) return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   658
        int count = STRESS + (STRESS_COUNT++ & 0x1);  // non-constant value
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   659
        for (int i = 0; i < count; i++) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   660
            SINK[i % SINK.length] = new Object[STRESS + i % (SINK.length + 1)];
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   661
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   662
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   663
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   664
    // verbosity:
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   665
    private static final int VERBOSITY = getProperty("VERBOSITY", 0) + (REPEAT == 0 ? 0 : -1);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   666
    private static void verbose(Object a, Object b, Object c, Object d) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   667
        if (VERBOSITY <= 0)  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   668
        verbose(1, a, b, c, d);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   669
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   670
    private static void verbose(Object a, Object b, Object c) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   671
        if (VERBOSITY <= 0)  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   672
        verbose(1, a, b, c);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   673
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   674
    private static void verbose(int level, Object a, Object... bcd) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   675
        if (level > VERBOSITY)  return;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   676
        String m = a.toString();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   677
        if (bcd != null && bcd.length > 0) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   678
            List<Object> l = new ArrayList<>(bcd.length);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   679
            for (Object x : bcd) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   680
                if (x instanceof Object[])  x = Arrays.asList((Object[])x);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   681
                if (x instanceof int[])     x = Arrays.toString((int[])x);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   682
                if (x instanceof long[])    x = Arrays.toString((long[])x);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   683
                l.add(x);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   684
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   685
            m = m+Arrays.asList(bcd);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   686
        }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   687
        System.out.println(m);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   688
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   689
    String testOnly;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   690
    String testOnlyTests;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   691
    private boolean startTest(String name) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   692
        if (testOnly != null && !testOnly.contains(name))
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   693
            return false;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   694
        verbose(0, "["+name+"]");
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   695
        testOnlyTests = (testOnlyTests == null) ? name : testOnlyTests+" "+name;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   696
        return true;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   697
    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   698
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents:
diff changeset
   699
}