jdk/test/java/lang/invoke/PermuteArgsTest.java
author mhaupt
Wed, 27 Apr 2016 15:01:21 +0200
changeset 37671 7917477e22a8
parent 23010 6dadb192ad81
child 45283 fcb2af038805
permissions -rw-r--r--
8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache Reviewed-by: sundar
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
/*
37671
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
     2
 * Copyright (c) 2011, 2016, 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
37671
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
    26
 * @library /lib/testlibrary/jsr292 /lib/testlibrary
19388
188246066dbb 8022749: Convert junit tests to testng in test/java/lang/invoke
henryjen
parents: 13613
diff changeset
    27
 * @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
    28
 */
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    29
/* Examples of manual runs:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    30
 * 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
    31
 * 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
    32
 * 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
    33
 */
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    34
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    35
package test.java.lang.invoke;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    36
19388
188246066dbb 8022749: Convert junit tests to testng in test/java/lang/invoke
henryjen
parents: 13613
diff changeset
    37
import org.testng.*;
188246066dbb 8022749: Convert junit tests to testng in test/java/lang/invoke
henryjen
parents: 13613
diff changeset
    38
import org.testng.annotations.*;
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    39
37671
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
    40
import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
    41
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    42
import java.util.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    43
import java.lang.reflect.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    44
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    45
import java.lang.invoke.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    46
import static java.lang.invoke.MethodHandles.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    47
import static java.lang.invoke.MethodType.*;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    48
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    49
public class PermuteArgsTest {
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
    50
    private static final Class<?> CLASS = PermuteArgsTest.class;
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    51
    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
    52
    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
    53
    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
    54
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    55
    static Object list2I(int x, int y) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    56
        return Arrays.asList(x, y);
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 list3I(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(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 list4I(int w, int x, int y, int z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    62
        return Arrays.asList(w, x, y, z);
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 list2J(long x, long y) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    65
        return Arrays.asList(x, y);
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 list3J(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(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 list4J(long w, long 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 list2I2J(int w, int x, long y, long 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 list2J2I(long w, long x, int y, int z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
    77
        return Arrays.asList(w, 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 listLJJ(Object x, long 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 listJLJ(long x, Object y, long 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 listJJL(long x, long 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 listJLL(long x, Object 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 listLJL(Object x, long y, Object 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 listLLJ(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(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 listJLLJ(long w, Object x, Object y, long 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 listLJJL(Object w, long x, long y, Object z) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   101
        return Arrays.asList(w, x, y, z);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   102
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   103
    static Object listI_etc(int... va) {
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   104
        ArrayList<Object> res = new ArrayList<>();
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   105
        for (int x : va)  res.add(x);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   106
        return res;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   107
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   108
    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
   109
        ArrayList<Object> res = new ArrayList<>();
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   110
        res.addAll(Arrays.asList(x, y, z));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   111
        res.addAll(Arrays.asList(va));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   112
        return res;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   113
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   114
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   115
    public static void main(String argv[]) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   116
        if (argv.length > 0) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   117
            for (String arg : argv) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   118
                // arg ::= name[n,...]
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   119
                int k = arg.indexOf('[');
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   120
                String mhName = arg.substring(0, k).trim();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   121
                String permString = arg.substring(k);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   122
                testOnePermutation(mhName, permString);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   123
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   124
            return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   125
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   126
        new PermuteArgsTest().test();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   127
    }
37671
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
   128
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   129
    static int testCases;
37671
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
   130
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   131
    @Test
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   132
    public void test() throws Throwable {
37671
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
   133
        CodeCacheOverflowProcessor.runMHTest(this::test0);
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
   134
    }
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
   135
7917477e22a8 8155214: java/lang/invoke/PermuteArgsTest.java fails due to exhausted code cache
mhaupt
parents: 23010
diff changeset
   136
    public void test0() throws Throwable {
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   137
        testCases = 0;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   138
        Lookup lookup = lookup();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   139
        for (Method m : lookup.lookupClass().getDeclaredMethods()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   140
            if (m.getName().startsWith("list") &&
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   141
                Modifier.isStatic(m.getModifiers())) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   142
                test(m.getName(), lookup.unreflect(m));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   143
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   144
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   145
        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
   146
    }
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
    static int jump(int i, int min, int max) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   149
        if (i >= min && i <= max-1) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   150
            // jump faster
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   151
            int len = max-min;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   152
            if (i < min + len/2)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   153
                i = min + len/2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   154
            else
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   155
                i = max-1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   156
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   157
        return i;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   158
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   159
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   160
    static void test(String name, MethodHandle mh) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   161
        if (VERBOSE)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   162
            System.out.println("mh = "+name+" : "+mh+" { "
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   163
                               +Arrays.toString(junkArgs(mh.type().parameterArray())));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   164
        int testCases0 = testCases;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   165
        if (!mh.isVarargsCollector()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   166
            // normal case
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   167
            testPermutations(mh);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   168
        } else {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   169
            // varargs case; add params up to MAX_ARITY
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   170
            MethodType mt = mh.type();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   171
            int posArgs = mt.parameterCount() - 1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   172
            int arity0 = Math.max(3, posArgs);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   173
            for (int arity = arity0; arity <= MAX_ARITY; arity++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   174
                MethodHandle mh1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   175
                try {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   176
                    mh1 = adjustArity(mh, arity);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   177
                } catch (IllegalArgumentException ex) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   178
                    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
   179
                    ex.printStackTrace(System.out);
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   180
                    break;  // cannot get this arity for this type
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   181
                }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   182
                test("("+arity+")"+name, mh1);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   183
                arity = jump(arity, arity0*2, MAX_ARITY);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   184
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   185
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   186
        if (VERBOSE)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   187
            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
   188
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   189
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   190
    static MethodHandle adjustArity(MethodHandle mh, int arity) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   191
        MethodType mt = mh.type();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   192
        int posArgs = mt.parameterCount() - 1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   193
        Class<?> reptype = mt.parameterType(posArgs).getComponentType();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   194
        MethodType mt1 = mt.dropParameterTypes(posArgs, posArgs+1);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   195
        while (mt1.parameterCount() < arity) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   196
            Class<?> pt = reptype;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   197
            if (pt == Object.class && posArgs > 0)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   198
                // repeat types cyclically if possible:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   199
                pt = mt1.parameterType(mt1.parameterCount() - posArgs);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   200
            mt1 = mt1.appendParameterTypes(pt);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   201
        }
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   202
        try {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   203
            return mh.asType(mt1);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   204
        } catch (WrongMethodTypeException | IllegalArgumentException ex) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 11534
diff changeset
   205
            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
   206
        }
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   207
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   208
    static MethodHandle findTestMH(String name, int[] perm) throws ReflectiveOperationException {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   209
        int arity = perm.length;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   210
        Lookup lookup = lookup();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   211
        for (Method m : lookup.lookupClass().getDeclaredMethods()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   212
            if (m.getName().equals(name) &&
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   213
                Modifier.isStatic(m.getModifiers())) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   214
                MethodHandle mh = lookup.unreflect(m);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   215
                int mhArity = mh.type().parameterCount();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   216
                if (mh.isVarargsCollector()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   217
                    if (mhArity-1 <= arity)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   218
                        return adjustArity(mh, arity);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   219
                } else if (mhArity == arity) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   220
                    return mh;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   221
                }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   222
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   223
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   224
        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
   225
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   226
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   227
    static void testPermutations(MethodHandle mh) throws Throwable {
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   228
        HashSet<String> done = new HashSet<>();
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   229
        MethodType mt = mh.type();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   230
        int[] perm = nullPerm(mt.parameterCount());
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   231
        final int MARGIN = (perm.length <= 10 ? 2 : 0);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   232
        int testCases0 = testCases;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   233
        for (int j = 0; j <= 1; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   234
            int maxStart = perm.length-1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   235
            if (j != 0)  maxStart /= 2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   236
            for (int start = 0; start <= maxStart; start++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   237
                int maxOmit = (maxStart - start) / 2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   238
                if (start != 0)  maxOmit = 2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   239
                if (j != 0)  maxOmit = 1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   240
                for (int omit = 0; omit <= maxOmit; omit++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   241
                    int end = perm.length - omit;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   242
                    if (end - start >= 2) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   243
                        //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
   244
                        testPermutations(mh, perm, start, end, done);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   245
                    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   246
                    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
   247
                }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   248
                start = jump(start, (j == 0 ? MARGIN : 0), maxStart);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   249
            }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   250
            // do everything in reverse:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   251
            reverse(perm, 0, perm.length);
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
        switch (perm.length) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   254
        case 2: assert(testCases - testCases0 == 2); break;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   255
        case 3: assert(testCases - testCases0 == 6); break;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   256
        case 4: assert(testCases - testCases0 == 24); break;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   257
        case 5: assert(testCases - testCases0 == 120); break;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   258
        case 6: assert(testCases - testCases0 > 720/3); break;
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
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   261
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   262
    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
   263
        if (end - start <= 1)  return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   264
        for (int j = 0; j <= 1; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   265
            testRotations(mh, perm, start, end, done);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   266
            if (end - start <= 2)  return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   267
            reverse(perm, start, end);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   268
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   269
        if (end - start <= 3)  return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   270
        int excess4 = (end - start) - 4;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   271
        // composed rotations:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   272
        int start2 = start + 1 + excess4/3;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   273
        int end2   = end       - excess4/3;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   274
        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
   275
        int skips = (perm.length+3)/5;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   276
        for (int i = start; i < end; i++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   277
            rotate(perm, start, end);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   278
            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
   279
            for (int j = 0; j <= 1; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   280
                testPermutations(mh, perm, start2, end2, done);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   281
                reverse(perm, start, end);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   282
            }
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 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
   287
        Object[] args = junkArgs(mh.type().parameterArray());
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   288
        for (int i = start; i < end; i++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   289
            if (done.add(Arrays.toString(perm)))
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   290
                testOnePermutation(mh, perm, args);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   291
            rotate(perm, start, end);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   292
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   293
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   294
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   295
    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
   296
        MethodType mt = mh.type();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   297
        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
   298
        if (VERBOSE)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   299
            System.out.println(Arrays.toString(perm));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   300
        testCases += 1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   301
        if (DRY_RUN)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   302
            return;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   303
        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
   304
        String str = String.valueOf(res);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   305
        if (!Arrays.toString(args).equals(str)) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   306
            System.out.println(Arrays.toString(perm)+" "+str+" *** WRONG ***");
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   307
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   308
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   309
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   310
    // For reproducing failures:
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   311
    static void testOnePermutation(String mhName, String permString) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   312
        String s = permString;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   313
        s = s.replace('[', ' ').replace(']', ' ').replace(',', ' ');  // easier to trim spaces
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   314
        s = s.trim();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   315
        int[] perm = new int[s.length()];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   316
        int arity = 0;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   317
        while (!s.isEmpty()) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   318
            int k = s.indexOf(' ');
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   319
            if (k < 0)  k = s.length();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   320
            perm[arity++] = Integer.parseInt(s.substring(0, k));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   321
            s = s.substring(k).trim();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   322
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   323
        perm = Arrays.copyOf(perm, arity);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   324
        testOnePermutation(mhName, perm);
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 void testOnePermutation(String mhName, int[] perm) throws Throwable {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   327
        MethodHandle mh = findTestMH(mhName, perm);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   328
        System.out.println("mh = "+mhName+" : "+mh+" { "
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   329
                           +Arrays.toString(junkArgs(mh.type().parameterArray())));
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   330
        Object[] args = junkArgs(mh.type().parameterArray());
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   331
        testOnePermutation(mh, perm, args);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   332
        System.out.println("}");
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   333
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   334
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   335
    static Object[] junkArgs(Class<?>[] ptypes) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   336
        Object[] args = new Object[ptypes.length];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   337
        for (int i = 0; i < ptypes.length; i++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   338
            Class<?> pt = ptypes[i];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   339
            Object arg;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   340
            if (pt == Void.class)       arg = null;
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   341
            else if (pt == int.class)   arg = i + 101;
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 9859
diff changeset
   342
            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
   343
            else                        arg = "#" + (i + 1);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   344
            args[i] = arg;
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
        return args;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   347
    }
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 int[] nullPerm(int len) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   350
        int[] perm = new int[len];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   351
        for (int i = 0; i < len; i++)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   352
            perm[i] = i;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   353
        return perm;
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 rotate(int[] perm) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   356
        rotate(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 rotate(int[] perm, int start, int end) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   359
        int x = perm[end-1];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   360
        for (int j = start; j < end; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   361
            int y = perm[j]; perm[j] = x; x = y;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   362
        }
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
    static void reverse(int[] perm) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   365
        reverse(perm, 0, perm.length);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   366
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   367
    static void reverse(int[] perm, int start, int end) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   368
        int mid = start + (end - start)/2;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   369
        for (int j = start; j < mid; j++) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   370
            int k = (end-1) - j;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   371
            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
   372
        }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   373
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   374
    // Permute the args according to the inverse of perm.
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   375
    static Object[] unpermuteArgs(int[] perm, Object[] args) {
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   376
        return unpermuteArgs(perm, args, Object[].class);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   377
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   378
    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
   379
        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
   380
        for (int i = 0; i < perm.length; i++)
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   381
            res[perm[i]] = args[i];
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   382
        return res;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   383
    }
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
diff changeset
   384
}