jdk/test/java/lang/invoke/7087570/Test7087570.java
author alanb
Fri, 10 Feb 2017 09:04:39 +0000
changeset 43712 5dfd0950317c
parent 40684 2e37c119dc2a
permissions -rw-r--r--
8173393: Module system implementation refresh (2/2017) Reviewed-by: dfuchs, psandoz, mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, claes.redestad@oracle.com, alex.buckley@oracle.com, mark.reinhold@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
     1
/*
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
     4
 *
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
     7
 * published by the Free Software Foundation.
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
     8
 *
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    13
 * accompanied this code).
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    14
 *
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    18
 *
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    21
 * questions.
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    22
 */
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    23
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    24
/* @test
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    25
 * @bug 7087570
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    26
 * @summary REF_invokeSpecial DMHs (which are unusual) get marked explicitly; tweak the MHI to use this bit
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    27
 *
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    28
 * @run main Test7087570
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    29
 */
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    30
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    31
import java.lang.invoke.*;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    32
import java.lang.reflect.*;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    33
import java.util.*;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    34
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    35
import static java.lang.invoke.MethodHandles.*;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    36
import static java.lang.invoke.MethodType.*;
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    37
import static java.lang.invoke.MethodHandleInfo.*;
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    38
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    39
public class Test7087570 {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    40
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    41
    private static final TestMethodData[] TESTS = new TestMethodData[] {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    42
        // field accessors
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    43
        data(DummyFieldHolder.class, "instanceField", getterMethodType(String.class), DummyFieldHolder.class, REF_getField),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    44
        data(DummyFieldHolder.class, "instanceField", setterMethodType(String.class), DummyFieldHolder.class, REF_putField),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    45
        data(DummyFieldHolder.class, "staticField", getterMethodType(Integer.class), DummyFieldHolder.class, REF_getStatic),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    46
        data(DummyFieldHolder.class, "staticField", setterMethodType(Integer.class), DummyFieldHolder.class, REF_putStatic),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    47
        data(DummyFieldHolder.class, "instanceByteField", getterMethodType(byte.class), DummyFieldHolder.class, REF_getField),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    48
        data(DummyFieldHolder.class, "instanceByteField", setterMethodType(byte.class), DummyFieldHolder.class, REF_putField),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    49
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    50
        // REF_invokeVirtual
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    51
        data(Object.class, "hashCode", methodType(int.class), Object.class, REF_invokeVirtual),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    52
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    53
        // REF_invokeVirtual strength-reduced to REF_invokeSpecial,
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    54
        // test if it normalizes back to REF_invokeVirtual in MethodHandleInfo as expected
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    55
        data(String.class, "hashCode", methodType(int.class), String.class, REF_invokeVirtual),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    56
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    57
        // REF_invokeStatic
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    58
        data(Collections.class, "sort", methodType(void.class, List.class), Collections.class, REF_invokeStatic),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    59
        data(Arrays.class, "asList", methodType(List.class, Object[].class), Arrays.class, REF_invokeStatic), // varargs case
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    60
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    61
        // REF_invokeSpecial
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    62
        data(Object.class, "hashCode", methodType(int.class), Object.class, REF_invokeSpecial),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    63
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    64
        // REF_newInvokeSpecial
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    65
        data(String.class, "<init>", methodType(void.class, char[].class), String.class, REF_newInvokeSpecial),
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    66
        data(DummyFieldHolder.class, "<init>", methodType(void.class, byte.class, Long[].class), DummyFieldHolder.class, REF_newInvokeSpecial), // varargs case
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    67
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    68
        // REF_invokeInterface
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    69
        data(List.class, "size", methodType(int.class), List.class, REF_invokeInterface)
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    70
    };
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    71
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    72
    public static void main(String... args) throws Throwable {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    73
        testWithLookup();
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    74
        testWithUnreflect();
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    75
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    76
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    77
    private static void doTest(MethodHandle mh, TestMethodData testMethod) {
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    78
        MethodHandleInfo mhi = LOOKUP.revealDirect(mh);
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    79
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    80
        System.out.printf("%s.%s: %s, nominal refKind: %s, actual refKind: %s\n",
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    81
                          testMethod.clazz.getName(), testMethod.name, testMethod.methodType,
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    82
                          referenceKindToString(testMethod.referenceKind),
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    83
                          referenceKindToString(mhi.getReferenceKind()));
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    84
        assertEquals(testMethod.name,           mhi.getName());
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    85
        assertEquals(testMethod.methodType,     mhi.getMethodType());
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    86
        assertEquals(testMethod.declaringClass, mhi.getDeclaringClass());
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    87
        assertEquals(testMethod.referenceKind == REF_invokeSpecial, isInvokeSpecial(mh));
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    88
        assertRefKindEquals(testMethod.referenceKind,  mhi.getReferenceKind());
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    89
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    90
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    91
    private static void testWithLookup() throws Throwable {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    92
        for (TestMethodData testMethod : TESTS) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    93
            MethodHandle mh = lookupFrom(testMethod);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    94
            doTest(mh, testMethod);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    95
        }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    96
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    97
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    98
    private static void testWithUnreflect() throws Throwable {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
    99
        for (TestMethodData testMethod : TESTS) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   100
            MethodHandle mh = unreflectFrom(testMethod);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   101
            doTest(mh, testMethod);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   102
        }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   103
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   104
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   105
    private static MethodType getterMethodType(Class<?> clazz) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   106
        return methodType(clazz);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   107
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   108
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   109
    private static MethodType setterMethodType(Class<?> clazz) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   110
        return methodType(void.class, clazz);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   111
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   112
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   113
    private static final Lookup LOOKUP = lookup();
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   114
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   115
    private static class TestMethodData {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   116
        final Class<?> clazz;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   117
        final String name;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   118
        final MethodType methodType;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   119
        final Class<?> declaringClass;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   120
        final int referenceKind; // the nominal refKind
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   121
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   122
        public TestMethodData(Class<?> clazz, String name,
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   123
                        MethodType methodType, Class<?> declaringClass,
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   124
                        int referenceKind) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   125
            this.clazz = clazz;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   126
            this.name = name;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   127
            this.methodType = methodType;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   128
            this.declaringClass = declaringClass;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   129
            this.referenceKind = referenceKind;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   130
        }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   131
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   132
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   133
    private static TestMethodData data(Class<?> clazz, String name,
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   134
                                       MethodType methodType, Class<?> declaringClass,
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   135
                                       int referenceKind) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   136
        return new TestMethodData(clazz, name, methodType, declaringClass, referenceKind);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   137
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   138
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   139
    private static MethodHandle lookupFrom(TestMethodData testMethod)
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   140
            throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   141
        switch (testMethod.referenceKind) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   142
        case REF_getField:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   143
            return LOOKUP.findGetter(testMethod.clazz, testMethod.name, testMethod.methodType.returnType());
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   144
        case REF_putField:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   145
            return LOOKUP.findSetter(testMethod.clazz, testMethod.name, testMethod.methodType.parameterType(0));
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   146
        case REF_getStatic:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   147
            return LOOKUP.findStaticGetter(testMethod.clazz, testMethod.name, testMethod.methodType.returnType());
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   148
        case REF_putStatic:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   149
            return LOOKUP.findStaticSetter(testMethod.clazz, testMethod.name, testMethod.methodType.parameterType(0));
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   150
        case REF_invokeVirtual:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   151
        case REF_invokeInterface:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   152
            return LOOKUP.findVirtual(testMethod.clazz, testMethod.name, testMethod.methodType);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   153
        case REF_invokeStatic:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   154
            return LOOKUP.findStatic(testMethod.clazz, testMethod.name, testMethod.methodType);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   155
        case REF_invokeSpecial:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   156
            Class<?> thisClass = LOOKUP.lookupClass();
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   157
            MethodHandle smh = LOOKUP.findSpecial(testMethod.clazz, testMethod.name, testMethod.methodType, thisClass);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   158
            noteInvokeSpecial(smh);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   159
            return smh;
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   160
        case REF_newInvokeSpecial:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   161
            return LOOKUP.findConstructor(testMethod.clazz, testMethod.methodType);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   162
        default:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   163
            throw new Error("ERROR: unexpected referenceKind in test data");
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   164
        }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   165
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   166
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   167
    private static MethodHandle unreflectFrom(TestMethodData testMethod)
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   168
            throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   169
        switch (testMethod.referenceKind) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   170
        case REF_getField:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   171
        case REF_getStatic: {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   172
                Field f = testMethod.clazz.getDeclaredField(testMethod.name);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   173
                return LOOKUP.unreflectGetter(f);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   174
            }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   175
        case REF_putField:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   176
        case REF_putStatic: {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   177
                Field f = testMethod.clazz.getDeclaredField(testMethod.name);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   178
                return LOOKUP.unreflectSetter(f);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   179
            }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   180
        case REF_invokeVirtual:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   181
        case REF_invokeStatic:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   182
        case REF_invokeInterface: {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   183
                Method m = testMethod.clazz.getDeclaredMethod(testMethod.name, testMethod.methodType.parameterArray());
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   184
                return LOOKUP.unreflect(m);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   185
            }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   186
        case REF_invokeSpecial: {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   187
                Method m = testMethod.clazz.getDeclaredMethod(testMethod.name, testMethod.methodType.parameterArray());
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   188
                Class<?> thisClass = LOOKUP.lookupClass();
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   189
                MethodHandle smh = LOOKUP.unreflectSpecial(m, thisClass);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   190
                noteInvokeSpecial(smh);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   191
                return smh;
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   192
            }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   193
        case REF_newInvokeSpecial: {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   194
                Constructor c = testMethod.clazz.getDeclaredConstructor(testMethod.methodType.parameterArray());
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   195
                return LOOKUP.unreflectConstructor(c);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   196
            }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   197
        default:
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   198
            throw new Error("ERROR: unexpected referenceKind in test data");
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   199
        }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   200
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   201
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   202
    private static List<MethodHandle> specialMethodHandles = new ArrayList<>();
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   203
    private static void noteInvokeSpecial(MethodHandle mh) {
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   204
        specialMethodHandles.add(mh);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   205
        assert(isInvokeSpecial(mh));
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   206
    }
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   207
    private static boolean isInvokeSpecial(MethodHandle mh) {
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   208
        return specialMethodHandles.contains(mh);
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   209
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   210
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   211
    private static void assertRefKindEquals(int expect, int observed) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   212
        if (expect == observed) return;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   213
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   214
        String msg = "expected " + referenceKindToString(expect) +
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   215
                     " but observed " + referenceKindToString(observed);
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   216
        System.out.println("FAILED: " + msg);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   217
        throw new AssertionError(msg);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   218
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   219
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   220
    private static void assertEquals(Object expect, Object observed) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   221
        if (java.util.Objects.equals(expect, observed)) return;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   222
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   223
        String msg = "expected " + expect + " but observed " + observed;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   224
        System.out.println("FAILED: " + msg);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   225
        throw new AssertionError(msg);
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   226
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   227
}
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   228
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   229
class DummyFieldHolder {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   230
    public static Integer staticField;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   231
    public String instanceField;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   232
    public byte instanceByteField;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   233
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   234
    public DummyFieldHolder(byte unused1, Long... unused2) {
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   235
    }
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   236
}
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
diff changeset
   237