jdk/test/java/lang/invoke/PermuteArgsTest.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 21596 0e3a39f29dbc
child 37671 7917477e22a8
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21596
diff changeset
     2
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
     4
 *
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
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: 19388
diff changeset
     7
 * published by the Free Software Foundation.
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
     8
 *
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    13
 * accompanied this code).
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    14
 *
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    18
 *
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    21
 * questions.
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    22
 */
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    23
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    24
/* @test
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    25
 * @summary unit tests for method handles which permute their arguments
19388
188246066dbb 8022749: Convert junit tests to testng in test/java/lang/invoke
henryjen
parents: 13613
diff changeset
    26
 * @run testng/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -ea -esa -DPermuteArgsTest.MAX_ARITY=8 test.java.lang.invoke.PermuteArgsTest
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    27
 */
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    28
/* Examples of manual runs:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    29
 * java -DPermuteArgsTest.{DRY_RUN=true,MAX_ARITY=253} test.java.lang.invoke.PermuteArgsTest
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    30
 * java -DPermuteArgsTest.{VERBOSE=true,MAX_ARITY=5} test.java.lang.invoke.PermuteArgsTest
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    31
 * java test.java.lang.invoke.PermuteArgsTest list3I[2,0,1] listJLJ[2,0,1]
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    32
 */
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    33
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    34
package test.java.lang.invoke;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    35
19388
188246066dbb 8022749: Convert junit tests to testng in test/java/lang/invoke
henryjen
parents: 13613
diff changeset
    36
import org.testng.*;
188246066dbb 8022749: Convert junit tests to testng in test/java/lang/invoke
henryjen
parents: 13613
diff changeset
    37
import org.testng.annotations.*;
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    38
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    39
import java.util.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    40
import java.lang.reflect.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    41
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    42
import java.lang.invoke.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    43
import static java.lang.invoke.MethodHandles.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    44
import static java.lang.invoke.MethodType.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    45
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    46
public class PermuteArgsTest {
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
    47
    private static final Class<?> CLASS = PermuteArgsTest.class;
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    48
    private static final int MAX_ARITY = Integer.getInteger(CLASS.getSimpleName()+".MAX_ARITY", 8);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    49
    private static final boolean DRY_RUN = Boolean.getBoolean(CLASS.getSimpleName()+".DRY_RUN");
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    50
    private static final boolean VERBOSE = Boolean.getBoolean(CLASS.getSimpleName()+".VERBOSE") || DRY_RUN;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    51
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    52
    static Object list2I(int x, int y) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    53
        return Arrays.asList(x, y);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    54
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    55
    static Object list3I(int x, int y, int z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    56
        return Arrays.asList(x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    57
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    58
    static Object list4I(int w, int x, int y, int z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    59
        return Arrays.asList(w, x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    60
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    61
    static Object list2J(long x, long y) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    62
        return Arrays.asList(x, y);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    63
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    64
    static Object list3J(long x, long y, long z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    65
        return Arrays.asList(x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    66
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    67
    static Object list4J(long w, long x, long y, long z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    68
        return Arrays.asList(w, x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    69
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    70
    static Object list2I2J(int w, int x, long y, long z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    71
        return Arrays.asList(w, x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    72
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    73
    static Object list2J2I(long w, long x, int y, int z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    74
        return Arrays.asList(w, x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    75
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    76
    static Object listLJJ(Object x, long y, long z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    77
        return Arrays.asList(x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    78
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    79
    static Object listJLJ(long x, Object y, long z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    80
        return Arrays.asList(x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    81
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    82
    static Object listJJL(long x, long y, Object z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    83
        return Arrays.asList(x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    84
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    85
    static Object listJLL(long x, Object y, Object z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    86
        return Arrays.asList(x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    87
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    88
    static Object listLJL(Object x, long y, Object z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    89
        return Arrays.asList(x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    90
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    91
    static Object listLLJ(Object x, Object y, long z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    92
        return Arrays.asList(x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    93
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    94
    static Object listJLLJ(long w, Object x, Object y, long z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    95
        return Arrays.asList(w, x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    96
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    97
    static Object listLJJL(Object w, long x, long y, Object z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    98
        return Arrays.asList(w, x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    99
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   100
    static Object listI_etc(int... va) {
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   101
        ArrayList<Object> res = new ArrayList<>();
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   102
        for (int x : va)  res.add(x);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   103
        return res;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   104
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   105
    static Object listIJL_etc(int x, long y, Object z, Object... va) {
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   106
        ArrayList<Object> res = new ArrayList<>();
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   107
        res.addAll(Arrays.asList(x, y, z));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   108
        res.addAll(Arrays.asList(va));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   109
        return res;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   110
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   111
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   112
    public static void main(String argv[]) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   113
        if (argv.length > 0) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   114
            for (String arg : argv) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   115
                // arg ::= name[n,...]
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   116
                int k = arg.indexOf('[');
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   117
                String mhName = arg.substring(0, k).trim();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   118
                String permString = arg.substring(k);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   119
                testOnePermutation(mhName, permString);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   120
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   121
            return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   122
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   123
        new PermuteArgsTest().test();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   124
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   125
    static int testCases;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   126
    @Test
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   127
    public void test() throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   128
        testCases = 0;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   129
        Lookup lookup = lookup();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   130
        for (Method m : lookup.lookupClass().getDeclaredMethods()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   131
            if (m.getName().startsWith("list") &&
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   132
                Modifier.isStatic(m.getModifiers())) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   133
                test(m.getName(), lookup.unreflect(m));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   134
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   135
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   136
        System.out.println("ran a total of "+testCases+" test cases");
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   137
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   138
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   139
    static int jump(int i, int min, int max) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   140
        if (i >= min && i <= max-1) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   141
            // jump faster
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   142
            int len = max-min;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   143
            if (i < min + len/2)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   144
                i = min + len/2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   145
            else
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   146
                i = max-1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   147
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   148
        return i;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   149
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   150
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   151
    static void test(String name, MethodHandle mh) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   152
        if (VERBOSE)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   153
            System.out.println("mh = "+name+" : "+mh+" { "
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   154
                               +Arrays.toString(junkArgs(mh.type().parameterArray())));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   155
        int testCases0 = testCases;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   156
        if (!mh.isVarargsCollector()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   157
            // normal case
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   158
            testPermutations(mh);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   159
        } else {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   160
            // varargs case; add params up to MAX_ARITY
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   161
            MethodType mt = mh.type();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   162
            int posArgs = mt.parameterCount() - 1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   163
            int arity0 = Math.max(3, posArgs);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   164
            for (int arity = arity0; arity <= MAX_ARITY; arity++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   165
                MethodHandle mh1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   166
                try {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   167
                    mh1 = adjustArity(mh, arity);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   168
                } catch (IllegalArgumentException ex) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   169
                    System.out.println("*** mh = "+name+" : "+mh+"; arity = "+arity+" => "+ex);
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   170
                    ex.printStackTrace(System.out);
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   171
                    break;  // cannot get this arity for this type
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   172
                }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   173
                test("("+arity+")"+name, mh1);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   174
                arity = jump(arity, arity0*2, MAX_ARITY);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   175
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   176
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   177
        if (VERBOSE)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   178
            System.out.println("ran "+(testCases - testCases0)+" test cases for "+name+" }");
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   179
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   180
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   181
    static MethodHandle adjustArity(MethodHandle mh, int arity) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   182
        MethodType mt = mh.type();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   183
        int posArgs = mt.parameterCount() - 1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   184
        Class<?> reptype = mt.parameterType(posArgs).getComponentType();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   185
        MethodType mt1 = mt.dropParameterTypes(posArgs, posArgs+1);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   186
        while (mt1.parameterCount() < arity) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   187
            Class<?> pt = reptype;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   188
            if (pt == Object.class && posArgs > 0)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   189
                // repeat types cyclically if possible:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   190
                pt = mt1.parameterType(mt1.parameterCount() - posArgs);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   191
            mt1 = mt1.appendParameterTypes(pt);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   192
        }
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   193
        try {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   194
            return mh.asType(mt1);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   195
        } catch (WrongMethodTypeException | IllegalArgumentException ex) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   196
            throw new IllegalArgumentException("cannot convert to type "+mt1+" from "+mh, ex);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   197
        }
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   198
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   199
    static MethodHandle findTestMH(String name, int[] perm) throws ReflectiveOperationException {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   200
        int arity = perm.length;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   201
        Lookup lookup = lookup();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   202
        for (Method m : lookup.lookupClass().getDeclaredMethods()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   203
            if (m.getName().equals(name) &&
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   204
                Modifier.isStatic(m.getModifiers())) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   205
                MethodHandle mh = lookup.unreflect(m);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   206
                int mhArity = mh.type().parameterCount();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   207
                if (mh.isVarargsCollector()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   208
                    if (mhArity-1 <= arity)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   209
                        return adjustArity(mh, arity);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   210
                } else if (mhArity == arity) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   211
                    return mh;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   212
                }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   213
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   214
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   215
        throw new RuntimeException("no such method for arity "+arity+": "+name);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   216
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   217
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   218
    static void testPermutations(MethodHandle mh) throws Throwable {
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   219
        HashSet<String> done = new HashSet<>();
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   220
        MethodType mt = mh.type();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   221
        int[] perm = nullPerm(mt.parameterCount());
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   222
        final int MARGIN = (perm.length <= 10 ? 2 : 0);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   223
        int testCases0 = testCases;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   224
        for (int j = 0; j <= 1; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   225
            int maxStart = perm.length-1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   226
            if (j != 0)  maxStart /= 2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   227
            for (int start = 0; start <= maxStart; start++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   228
                int maxOmit = (maxStart - start) / 2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   229
                if (start != 0)  maxOmit = 2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   230
                if (j != 0)  maxOmit = 1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   231
                for (int omit = 0; omit <= maxOmit; omit++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   232
                    int end = perm.length - omit;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   233
                    if (end - start >= 2) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   234
                        //System.out.println("testPermutations"+Arrays.asList(start, end)+(j == 0 ? "" : " (reverse)"));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   235
                        testPermutations(mh, perm, start, end, done);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   236
                    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   237
                    omit = jump(omit, (start == 0 && j == 0 ? MARGIN : 0), maxOmit);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   238
                }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   239
                start = jump(start, (j == 0 ? MARGIN : 0), maxStart);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   240
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   241
            // do everything in reverse:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   242
            reverse(perm, 0, perm.length);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   243
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   244
        switch (perm.length) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   245
        case 2: assert(testCases - testCases0 == 2); break;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   246
        case 3: assert(testCases - testCases0 == 6); break;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   247
        case 4: assert(testCases - testCases0 == 24); break;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   248
        case 5: assert(testCases - testCases0 == 120); break;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   249
        case 6: assert(testCases - testCases0 > 720/3); break;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   250
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   251
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   252
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   253
    static void testPermutations(MethodHandle mh, int[] perm, int start, int end, Set<String> done) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   254
        if (end - start <= 1)  return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   255
        for (int j = 0; j <= 1; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   256
            testRotations(mh, perm, start, end, done);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   257
            if (end - start <= 2)  return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   258
            reverse(perm, start, end);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   259
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   260
        if (end - start <= 3)  return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   261
        int excess4 = (end - start) - 4;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   262
        // composed rotations:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   263
        int start2 = start + 1 + excess4/3;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   264
        int end2   = end       - excess4/3;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   265
        end2 = start2 + Math.min(start == 0 ? 4 : 3, end2 - start2);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   266
        int skips = (perm.length+3)/5;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   267
        for (int i = start; i < end; i++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   268
            rotate(perm, start, end);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   269
            if (skips > 1 && ((i-start) + (i-start)/7) % skips != 0)  continue;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   270
            for (int j = 0; j <= 1; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   271
                testPermutations(mh, perm, start2, end2, done);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   272
                reverse(perm, start, end);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   273
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   274
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   275
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   276
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   277
    static void testRotations(MethodHandle mh, int[] perm, int start, int end, Set<String> done) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   278
        Object[] args = junkArgs(mh.type().parameterArray());
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   279
        for (int i = start; i < end; i++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   280
            if (done.add(Arrays.toString(perm)))
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   281
                testOnePermutation(mh, perm, args);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   282
            rotate(perm, start, end);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   283
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   284
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   285
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   286
    static void testOnePermutation(MethodHandle mh, int[] perm, Object[] args) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   287
        MethodType mt = mh.type();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   288
        MethodType pmt = methodType(mt.returnType(), unpermuteArgs(perm, mt.parameterArray(), Class[].class));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   289
        if (VERBOSE)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   290
            System.out.println(Arrays.toString(perm));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   291
        testCases += 1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   292
        if (DRY_RUN)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   293
            return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   294
        Object res = permuteArguments(mh, pmt, perm).invokeWithArguments(unpermuteArgs(perm, args));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   295
        String str = String.valueOf(res);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   296
        if (!Arrays.toString(args).equals(str)) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   297
            System.out.println(Arrays.toString(perm)+" "+str+" *** WRONG ***");
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   298
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   299
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   300
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   301
    // For reproducing failures:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   302
    static void testOnePermutation(String mhName, String permString) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   303
        String s = permString;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   304
        s = s.replace('[', ' ').replace(']', ' ').replace(',', ' ');  // easier to trim spaces
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   305
        s = s.trim();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   306
        int[] perm = new int[s.length()];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   307
        int arity = 0;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   308
        while (!s.isEmpty()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   309
            int k = s.indexOf(' ');
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   310
            if (k < 0)  k = s.length();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   311
            perm[arity++] = Integer.parseInt(s.substring(0, k));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   312
            s = s.substring(k).trim();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   313
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   314
        perm = Arrays.copyOf(perm, arity);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   315
        testOnePermutation(mhName, perm);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   316
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   317
    static void testOnePermutation(String mhName, int[] perm) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   318
        MethodHandle mh = findTestMH(mhName, perm);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   319
        System.out.println("mh = "+mhName+" : "+mh+" { "
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   320
                           +Arrays.toString(junkArgs(mh.type().parameterArray())));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   321
        Object[] args = junkArgs(mh.type().parameterArray());
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   322
        testOnePermutation(mh, perm, args);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   323
        System.out.println("}");
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   324
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   325
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   326
    static Object[] junkArgs(Class<?>[] ptypes) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   327
        Object[] args = new Object[ptypes.length];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   328
        for (int i = 0; i < ptypes.length; i++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   329
            Class<?> pt = ptypes[i];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   330
            Object arg;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   331
            if (pt == Void.class)       arg = null;
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   332
            else if (pt == int.class)   arg = i + 101;
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   333
            else if (pt == long.class)  arg = i + 10_000_000_001L;
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   334
            else                        arg = "#" + (i + 1);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   335
            args[i] = arg;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   336
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   337
        return args;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   338
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   339
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   340
    static int[] nullPerm(int len) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   341
        int[] perm = new int[len];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   342
        for (int i = 0; i < len; i++)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   343
            perm[i] = i;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   344
        return perm;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   345
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   346
    static void rotate(int[] perm) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   347
        rotate(perm, 0, perm.length);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   348
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   349
    static void rotate(int[] perm, int start, int end) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   350
        int x = perm[end-1];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   351
        for (int j = start; j < end; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   352
            int y = perm[j]; perm[j] = x; x = y;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   353
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   354
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   355
    static void reverse(int[] perm) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   356
        reverse(perm, 0, perm.length);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   357
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   358
    static void reverse(int[] perm, int start, int end) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   359
        int mid = start + (end - start)/2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   360
        for (int j = start; j < mid; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   361
            int k = (end-1) - j;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   362
            int x = perm[j]; perm[j] = perm[k]; perm[k] = x;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   363
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   364
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   365
    // Permute the args according to the inverse of perm.
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   366
    static Object[] unpermuteArgs(int[] perm, Object[] args) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   367
        return unpermuteArgs(perm, args, Object[].class);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   368
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   369
    static <T> T[] unpermuteArgs(int[] perm, T[] args, Class<T[]> Tclass) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   370
        T[] res = Arrays.copyOf(new Object[0], perm.length, Tclass);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   371
        for (int i = 0; i < perm.length; i++)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   372
            res[perm[i]] = args[i];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   373
        return res;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   374
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   375
}