test/hotspot/jtreg/runtime/invokedynamic/MethodHandleConstantTest.java
author egahlin
Tue, 26 Nov 2019 17:00:57 +0100
changeset 59274 eb3e2a5c2bcd
parent 48514 9608f7f41c4e
permissions -rw-r--r--
8233870: JFR TestSetEndTime.java times out - onClose() is never called Reviewed-by: mgronlun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48514
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
     1
/*
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
     4
 *
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
     8
 *
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    14
 *
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    18
 *
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    21
 * questions.
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    22
 *
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    23
 */
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    24
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    25
/**
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    26
 * @test
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    27
 * @bug 8188145
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    28
 * @compile MethodHandleConstantHelper.jasm
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    29
 * @run main runtime.invokedynamic.MethodHandleConstantTest
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    30
 */
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    31
package runtime.invokedynamic;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    32
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    33
import java.lang.invoke.*;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    34
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    35
public class MethodHandleConstantTest {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    36
    static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    37
    static final MethodType TEST_MT = MethodType.methodType(void.class);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    38
    static final Class<?> TEST_CLASS;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    39
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    40
    static {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    41
       try {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    42
          TEST_CLASS = Class.forName("runtime.invokedynamic.MethodHandleConstantHelper");
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    43
       } catch (ClassNotFoundException e) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    44
           throw new Error(e);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    45
       }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    46
    }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    47
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    48
    static void test(String testName, Class<? extends Throwable> expectedError) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    49
        System.out.print(testName);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    50
        try {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    51
            LOOKUP.findStatic(TEST_CLASS, testName, TEST_MT).invokeExact();
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    52
        } catch (Throwable e) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    53
            if (expectedError.isInstance(e)) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    54
                // expected
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    55
            } else {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    56
                e.printStackTrace();
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    57
                String msg = String.format("%s: wrong exception: %s, but %s expected",
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    58
                                           testName, e.getClass().getName(), expectedError.getName());
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    59
                throw new AssertionError(msg);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    60
            }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    61
        }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    62
        System.out.println(": PASSED");
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    63
    }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    64
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    65
    public static void main(String[] args) throws Throwable {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    66
        test("testMethodSignatureResolutionFailure", NoSuchMethodError.class);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    67
        test("testFieldSignatureResolutionFailure",  NoSuchFieldError.class);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    68
    }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents:
diff changeset
    69
}