hotspot/test/compiler/jsr292/NonInlinedCall/InvokeTest.java
author vlivanov
Wed, 04 May 2016 23:08:43 +0300
changeset 38188 e76af590ea2f
parent 38152 80e5da81fb2c
child 38207 2ed792c9481d
permissions -rw-r--r--
8155751: Some tests miss othervm for main/bootclasspath mode Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
     1
/*
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
     4
 *
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
     8
 *
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    14
 *
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    18
 *
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    21
 * questions.
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    22
 */
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    23
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    24
/*
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    25
 * @test
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    26
 * @bug 8072008
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    27
 * @library /testlibrary /test/lib / ../patches
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36508
diff changeset
    28
 * @modules java.base/jdk.internal.misc
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    29
 * @modules java.base/jdk.internal.vm.annotation
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    30
 * @build java.base/java.lang.invoke.MethodHandleHelper
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    31
 * @build sun.hotspot.WhiteBox
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    32
 * @build compiler.jsr292.NonInlinedCall.InvokeTest
38188
e76af590ea2f 8155751: Some tests miss othervm for main/bootclasspath mode
vlivanov
parents: 38152
diff changeset
    33
 * @run main/bootclasspath/othervm -XX:+IgnoreUnrecognizedVMOptions
e76af590ea2f 8155751: Some tests miss othervm for main/bootclasspath mode
vlivanov
parents: 38152
diff changeset
    34
 *                                 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
e76af590ea2f 8155751: Some tests miss othervm for main/bootclasspath mode
vlivanov
parents: 38152
diff changeset
    35
 *                                 -Xbatch -XX:-TieredCompilation -XX:CICompilerCount=1
e76af590ea2f 8155751: Some tests miss othervm for main/bootclasspath mode
vlivanov
parents: 38152
diff changeset
    36
 *                                 compiler.jsr292.NonInlinedCall.InvokeTest
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    37
 */
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    38
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    39
package compiler.jsr292.NonInlinedCall;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    40
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    41
import java.lang.invoke.MethodHandle;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    42
import java.lang.invoke.MethodHandleHelper;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    43
import java.lang.invoke.MethodHandleHelper.NonInlinedReinvoker;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    44
import java.lang.invoke.MethodHandles;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    45
import java.lang.invoke.MethodType;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    46
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    47
import jdk.internal.vm.annotation.DontInline;
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    48
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    49
import sun.hotspot.WhiteBox;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    50
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    51
import static jdk.test.lib.Asserts.*;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    52
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    53
public class InvokeTest {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
    54
    static MethodHandles.Lookup LOOKUP = MethodHandleHelper.IMPL_LOOKUP;
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    55
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    56
    static final MethodHandle virtualMH;  // invokevirtual   T.f1
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    57
    static final MethodHandle staticMH;   // invokestatic    T.f2
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    58
    static final MethodHandle intfMH;     // invokeinterface I.f1
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    59
    static final MethodHandle specialMH;  // invokespecial   T.f4 T
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    60
    static final MethodHandle basicMH;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    61
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    62
    static final WhiteBox WB = WhiteBox.getWhiteBox();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    63
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    64
    static volatile boolean doDeopt = false;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    65
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    66
    static {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    67
        try {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    68
            MethodType mtype = MethodType.methodType(Class.class);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    69
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    70
            virtualMH  = LOOKUP.findVirtual(T.class, "f1", mtype);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    71
            staticMH   = LOOKUP.findStatic (T.class, "f2", mtype);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    72
            intfMH     = LOOKUP.findVirtual(I.class, "f3", mtype);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    73
            specialMH  = LOOKUP.findSpecial(T.class, "f4", mtype, T.class);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    74
            basicMH    = NonInlinedReinvoker.make(staticMH);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    75
        } catch (Exception e) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    76
            throw new Error(e);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    77
        }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    78
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    79
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    80
    static class T implements I {
35108
ccb4e1f2a6cf 8145137: Incorrect call signature can be used in nmethod::preserve_callee_argument_oops
vlivanov
parents: 35107
diff changeset
    81
        @DontInline public        Class<?> f1() { if (doDeopt) WB.deoptimizeAll(); return T.class; }
ccb4e1f2a6cf 8145137: Incorrect call signature can be used in nmethod::preserve_callee_argument_oops
vlivanov
parents: 35107
diff changeset
    82
        @DontInline public static Class<?> f2() { if (doDeopt) WB.deoptimizeAll(); return T.class; }
ccb4e1f2a6cf 8145137: Incorrect call signature can be used in nmethod::preserve_callee_argument_oops
vlivanov
parents: 35107
diff changeset
    83
        @DontInline private       Class<?> f4() { if (doDeopt) WB.deoptimizeAll(); return T.class; }
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    84
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    85
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    86
    static class P1 extends T {
35108
ccb4e1f2a6cf 8145137: Incorrect call signature can be used in nmethod::preserve_callee_argument_oops
vlivanov
parents: 35107
diff changeset
    87
        @DontInline public Class<?> f1() { if (doDeopt) WB.deoptimizeAll(); return P1.class; }
ccb4e1f2a6cf 8145137: Incorrect call signature can be used in nmethod::preserve_callee_argument_oops
vlivanov
parents: 35107
diff changeset
    88
        @DontInline public Class<?> f3() { if (doDeopt) WB.deoptimizeAll(); return P1.class; }
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    89
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    90
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    91
    static class P2 extends T {
35108
ccb4e1f2a6cf 8145137: Incorrect call signature can be used in nmethod::preserve_callee_argument_oops
vlivanov
parents: 35107
diff changeset
    92
        @DontInline public Class<?> f1() { if (doDeopt) WB.deoptimizeAll(); return P2.class; }
ccb4e1f2a6cf 8145137: Incorrect call signature can be used in nmethod::preserve_callee_argument_oops
vlivanov
parents: 35107
diff changeset
    93
        @DontInline public Class<?> f3() { if (doDeopt) WB.deoptimizeAll(); return P2.class; }
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    94
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    95
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    96
    static interface I {
35108
ccb4e1f2a6cf 8145137: Incorrect call signature can be used in nmethod::preserve_callee_argument_oops
vlivanov
parents: 35107
diff changeset
    97
        @DontInline default Class<?> f3() { if (doDeopt) WB.deoptimizeAll(); return I.class; }
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    98
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
    99
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   100
    @DontInline
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   101
    static void linkToVirtual(Object obj, Class<?> extecpted) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   102
        try {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   103
            Class<?> cls = (Class<?>)virtualMH.invokeExact((T)obj);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   104
            assertEquals(cls, obj.getClass());
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   105
        } catch (Throwable e) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   106
            throw new Error(e);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   107
        }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   108
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   109
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   110
    @DontInline
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   111
    static void linkToInterface(Object obj, Class<?> expected) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   112
        try {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   113
            Class<?> cls = (Class<?>)intfMH.invokeExact((I)obj);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   114
            assertEquals(cls, expected);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   115
        } catch (Throwable e) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   116
            throw new Error(e);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   117
        }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   118
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   119
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   120
    @DontInline
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   121
    static void linkToStatic() {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   122
        try {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   123
            Class<?> cls = (Class<?>)staticMH.invokeExact();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   124
            assertEquals(cls, T.class);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   125
        } catch (Throwable e) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   126
            throw new Error(e);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   127
        }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   128
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   129
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   130
    @DontInline
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   131
    static void linkToSpecial(Object obj, Class<?> expected) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   132
        try {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   133
            Class<?> cls = (Class<?>)specialMH.invokeExact((T)obj);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   134
            assertEquals(cls, expected);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   135
        } catch (Throwable e) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   136
            throw new Error(e);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   137
        }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   138
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   139
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   140
    @DontInline
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   141
    static void invokeBasic() {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   142
        try {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36331
diff changeset
   143
            Class<?> cls = (Class<?>)MethodHandleHelper.invokeBasicL(basicMH);
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   144
            assertEquals(cls, T.class);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   145
        } catch (Throwable e) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   146
            throw new Error(e);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   147
        }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   148
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   149
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   150
    static void run(Runnable r) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   151
        for (int i = 0; i < 20_000; i++) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   152
            r.run();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   153
        }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   154
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   155
        doDeopt = true;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   156
        r.run();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   157
        doDeopt = false;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   158
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   159
        WB.clearInlineCaches();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   160
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   161
        for (int i = 0; i < 20_000; i++) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   162
            r.run();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   163
        }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   164
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   165
        doDeopt = true;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   166
        r.run();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   167
        doDeopt = false;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   168
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   169
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   170
    static void testVirtual() {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   171
        System.out.println("linkToVirtual");
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   172
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   173
        // Monomorphic case (optimized virtual call)
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   174
        run(() -> linkToVirtual(new T(), T.class));
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   175
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   176
        // Megamorphic case (virtual call)
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   177
        Object[] recv = new Object[] { new T(), new P1(), new P2() };
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   178
        run(() -> {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   179
            for (Object r : recv) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   180
                linkToVirtual(r, r.getClass());
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   181
            }});
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   182
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   183
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   184
    static void testInterface() {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   185
        System.out.println("linkToInterface");
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   186
36331
eeeb86fd9922 8150436: Incorrect invocation mode when linkToInteface linker is eliminated
vlivanov
parents: 35108
diff changeset
   187
        // Monomorphic case (optimized virtual call), concrete target method
eeeb86fd9922 8150436: Incorrect invocation mode when linkToInteface linker is eliminated
vlivanov
parents: 35108
diff changeset
   188
        run(() -> linkToInterface(new P1(), P1.class));
eeeb86fd9922 8150436: Incorrect invocation mode when linkToInteface linker is eliminated
vlivanov
parents: 35108
diff changeset
   189
eeeb86fd9922 8150436: Incorrect invocation mode when linkToInteface linker is eliminated
vlivanov
parents: 35108
diff changeset
   190
        // Monomorphic case (optimized virtual call), default target method
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   191
        run(() -> linkToInterface(new T(), I.class));
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   192
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   193
        // Megamorphic case (virtual call)
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   194
        Object[][] recv = new Object[][] {{new T(), I.class}, {new P1(), P1.class}, {new P2(), P2.class}};
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   195
        run(() -> {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   196
            for (Object[] r : recv) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   197
                linkToInterface(r[0], (Class<?>)r[1]);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   198
            }});
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   199
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   200
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   201
    static void testSpecial() {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   202
        System.out.println("linkToSpecial");
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   203
        // Monomorphic case (optimized virtual call)
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   204
        run(() -> linkToSpecial(new T(), T.class));
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   205
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   206
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   207
    static void testStatic() {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   208
        System.out.println("linkToStatic");
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   209
        // static call
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   210
        run(() -> linkToStatic());
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   211
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   212
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   213
    static void testBasic() {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   214
        System.out.println("invokeBasic");
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   215
        // static call
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   216
        run(() -> invokeBasic());
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   217
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   218
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   219
    public static void main(String[] args) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   220
        testVirtual();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   221
        testInterface();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   222
        testSpecial();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   223
        testStatic();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   224
        testBasic();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   225
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
diff changeset
   226
}