jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java
author shade
Tue, 17 May 2016 22:28:00 +0300
changeset 38372 017d7578731c
parent 38328 40435a469d25
child 40543 629f1f599595
permissions -rw-r--r--
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles Reviewed-by: psandoz, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     1
/*
35773
80def5fa4d65 8071368: Use more concrete types for NamedFunction constants in the code
srastogi
parents: 35252
diff changeset
     2
 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     4
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    10
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    15
 * accompanied this code).
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    16
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    23
 * questions.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    24
 */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    25
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    26
package java.lang.invoke;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    27
35252
754852fba784 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 33841
diff changeset
    28
import jdk.internal.vm.annotation.DontInline;
754852fba784 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 33841
diff changeset
    29
import jdk.internal.vm.annotation.ForceInline;
754852fba784 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 33841
diff changeset
    30
import jdk.internal.vm.annotation.Stable;
754852fba784 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 33841
diff changeset
    31
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    32
import java.lang.reflect.Array;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
    33
import java.util.Arrays;
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    34
14089
0a41b980d62a 8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents: 13610
diff changeset
    35
import static java.lang.invoke.MethodHandleStatics.*;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
    36
import static java.lang.invoke.MethodHandleNatives.Constants.*;
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    37
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
    38
import static java.lang.invoke.LambdaForm.*;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    39
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    40
/**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    41
 * Construction and caching of often-used invokers.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    42
 * @author jrose
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    43
 */
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
    44
class Invokers {
25979
42e5d9f8087e 8054857: Fix typos in java.lang.** packages
prappo
parents: 23010
diff changeset
    45
    // exact type (sans leading target MH) for the outgoing call
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    46
    private final MethodType targetType;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    47
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    48
    // Cached adapter information:
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    49
    private final @Stable MethodHandle[] invokers = new MethodHandle[INV_LIMIT];
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    50
    // Indexes into invokers:
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    51
    static final int
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    52
            INV_EXACT          =  0,  // MethodHandles.exactInvoker
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    53
            INV_GENERIC        =  1,  // MethodHandles.invoker (generic invocation)
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    54
            INV_BASIC          =  2,  // MethodHandles.basicInvoker
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    55
            INV_LIMIT          =  3;
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7554
diff changeset
    56
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    57
    /** Compute and cache information common to all collecting adapters
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    58
     *  that implement members of the erasure-family of the given erased type.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    59
     */
8345
9e2483e6cfab 7013417: JSR 292 needs to support variadic method handle calls
jrose
parents: 7668
diff changeset
    60
    /*non-public*/ Invokers(MethodType targetType) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    61
        this.targetType = targetType;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    62
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    63
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
    64
    /*non-public*/ MethodHandle exactInvoker() {
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    65
        MethodHandle invoker = cachedInvoker(INV_EXACT);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    66
        if (invoker != null)  return invoker;
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
    67
        invoker = makeExactOrGeneralInvoker(true);
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    68
        return setCachedInvoker(INV_EXACT, invoker);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    69
    }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    70
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    71
    /*non-public*/ MethodHandle genericInvoker() {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    72
        MethodHandle invoker = cachedInvoker(INV_GENERIC);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    73
        if (invoker != null)  return invoker;
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    74
        invoker = makeExactOrGeneralInvoker(false);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    75
        return setCachedInvoker(INV_GENERIC, invoker);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    76
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    77
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    78
    /*non-public*/ MethodHandle basicInvoker() {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    79
        MethodHandle invoker = cachedInvoker(INV_BASIC);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    80
        if (invoker != null)  return invoker;
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    81
        MethodType basicType = targetType.basicType();
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    82
        if (basicType != targetType) {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    83
            // double cache; not used significantly
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    84
            return setCachedInvoker(INV_BASIC, basicType.invokers().basicInvoker());
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    85
        }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    86
        invoker = basicType.form().cachedMethodHandle(MethodTypeForm.MH_BASIC_INV);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    87
        if (invoker == null) {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    88
            MemberName method = invokeBasicMethod(basicType);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    89
            invoker = DirectMethodHandle.make(method);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    90
            assert(checkInvoker(invoker));
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    91
            invoker = basicType.form().setCachedMethodHandle(MethodTypeForm.MH_BASIC_INV, invoker);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    92
        }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    93
        return setCachedInvoker(INV_BASIC, invoker);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    94
    }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    95
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
    96
    /*non-public*/ MethodHandle varHandleMethodInvoker(VarHandle.AccessMode ak) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
    97
        // TODO cache invoker
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
    98
        return makeVarHandleMethodInvoker(ak, false);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
    99
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   100
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   101
    /*non-public*/ MethodHandle varHandleMethodExactInvoker(VarHandle.AccessMode ak) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   102
        // TODO cache invoker
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   103
        return makeVarHandleMethodInvoker(ak, true);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   104
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   105
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   106
    private MethodHandle cachedInvoker(int idx) {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   107
        return invokers[idx];
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   108
    }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   109
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   110
    private synchronized MethodHandle setCachedInvoker(int idx, final MethodHandle invoker) {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   111
        // Simulate a CAS, to avoid racy duplication of results.
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   112
        MethodHandle prev = invokers[idx];
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   113
        if (prev != null)  return prev;
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   114
        return invokers[idx] = invoker;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   115
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   116
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   117
    private MethodHandle makeExactOrGeneralInvoker(boolean isExact) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   118
        MethodType mtype = targetType;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   119
        MethodType invokerType = mtype.invokerType();
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   120
        int which = (isExact ? MethodTypeForm.LF_EX_INVOKER : MethodTypeForm.LF_GEN_INVOKER);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   121
        LambdaForm lform = invokeHandleForm(mtype, false, which);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   122
        MethodHandle invoker = BoundMethodHandle.bindSingle(invokerType, lform, mtype);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   123
        String whichName = (isExact ? "invokeExact" : "invoke");
26471
1de6be0c6945 8050174: Support overriding of isInvokeSpecial flag in WrappedMember
vlivanov
parents: 26468
diff changeset
   124
        invoker = invoker.withInternalMemberName(MemberName.makeMethodHandleInvoke(whichName, mtype), false);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   125
        assert(checkInvoker(invoker));
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   126
        maybeCompileToBytecode(invoker);
9752
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   127
        return invoker;
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   128
    }
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   129
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   130
    private MethodHandle makeVarHandleMethodInvoker(VarHandle.AccessMode ak, boolean isExact) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   131
        MethodType mtype = targetType;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   132
        MethodType invokerType = mtype.insertParameterTypes(0, VarHandle.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   133
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   134
        LambdaForm lform = varHandleMethodInvokerHandleForm(ak.methodName(), mtype, isExact);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   135
        VarHandle.AccessDescriptor ad = new VarHandle.AccessDescriptor(mtype, ak.at.ordinal(), ak.ordinal());
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   136
        MethodHandle invoker = BoundMethodHandle.bindSingle(invokerType, lform, ad);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   137
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   138
        invoker = invoker.withInternalMemberName(MemberName.makeVarHandleMethodInvoke(ak.methodName(), mtype), false);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   139
        assert(checkVarHandleInvoker(invoker));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   140
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   141
        maybeCompileToBytecode(invoker);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   142
        return invoker;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   143
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   144
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   145
    /** If the target type seems to be common enough, eagerly compile the invoker to bytecodes. */
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   146
    private void maybeCompileToBytecode(MethodHandle invoker) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   147
        final int EAGER_COMPILE_ARITY_LIMIT = 10;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   148
        if (targetType == targetType.erase() &&
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   149
            targetType.parameterCount() < EAGER_COMPILE_ARITY_LIMIT) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   150
            invoker.form.compileToBytecode();
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   151
        }
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   152
    }
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   153
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   154
    // This next one is called from LambdaForm.NamedFunction.<init>.
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   155
    /*non-public*/ static MemberName invokeBasicMethod(MethodType basicType) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   156
        assert(basicType == basicType.basicType());
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   157
        try {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   158
            //Lookup.findVirtual(MethodHandle.class, name, type);
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   159
            return IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, MethodHandle.class, "invokeBasic", basicType);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   160
        } catch (ReflectiveOperationException ex) {
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   161
            throw newInternalError("JVM cannot find invoker for "+basicType, ex);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   162
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   163
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   164
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   165
    private boolean checkInvoker(MethodHandle invoker) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   166
        assert(targetType.invokerType().equals(invoker.type()))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   167
                : java.util.Arrays.asList(targetType, targetType.invokerType(), invoker);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   168
        assert(invoker.internalMemberName() == null ||
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   169
               invoker.internalMemberName().getMethodType().equals(targetType));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   170
        assert(!invoker.isVarargsCollector());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   171
        return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   172
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   173
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   174
    private boolean checkVarHandleInvoker(MethodHandle invoker) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   175
        MethodType invokerType = targetType.insertParameterTypes(0, VarHandle.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   176
        assert(invokerType.equals(invoker.type()))
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   177
                : java.util.Arrays.asList(targetType, invokerType, invoker);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   178
        assert(invoker.internalMemberName() == null ||
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   179
               invoker.internalMemberName().getMethodType().equals(targetType));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   180
        assert(!invoker.isVarargsCollector());
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   181
        return true;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   182
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   183
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   184
    /**
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   185
     * Find or create an invoker which passes unchanged a given number of arguments
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   186
     * and spreads the rest from a trailing array argument.
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   187
     * The invoker target type is the post-spread type {@code (TYPEOF(uarg*), TYPEOF(sarg*))=>RT}.
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   188
     * All the {@code sarg}s must have a common type {@code C}.  (If there are none, {@code Object} is assumed.}
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   189
     * @param leadingArgCount the number of unchanged (non-spread) arguments
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   190
     * @return {@code invoker.invokeExact(mh, uarg*, C[]{sarg*}) := (RT)mh.invoke(uarg*, sarg*)}
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   191
     */
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   192
    /*non-public*/ MethodHandle spreadInvoker(int leadingArgCount) {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   193
        int spreadArgCount = targetType.parameterCount() - leadingArgCount;
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   194
        MethodType postSpreadType = targetType;
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   195
        Class<?> argArrayType = impliedRestargType(postSpreadType, leadingArgCount);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   196
        if (postSpreadType.parameterSlotCount() <= MethodType.MAX_MH_INVOKER_ARITY) {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   197
            return genericInvoker().asSpreader(argArrayType, spreadArgCount);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   198
        }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   199
        // Cannot build a generic invoker here of type ginvoker.invoke(mh, a*[254]).
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   200
        // Instead, factor sinvoker.invoke(mh, a) into ainvoker.invoke(filter(mh), a)
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   201
        // where filter(mh) == mh.asSpreader(Object[], spreadArgCount)
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   202
        MethodType preSpreadType = postSpreadType
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   203
            .replaceParameterTypes(leadingArgCount, postSpreadType.parameterCount(), argArrayType);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   204
        MethodHandle arrayInvoker = MethodHandles.invoker(preSpreadType);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   205
        MethodHandle makeSpreader = MethodHandles.insertArguments(Lazy.MH_asSpreader, 1, argArrayType, spreadArgCount);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   206
        return MethodHandles.filterArgument(arrayInvoker, 0, makeSpreader);
7554
8a0ad9757002 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 7052
diff changeset
   207
    }
8a0ad9757002 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 7052
diff changeset
   208
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   209
    private static Class<?> impliedRestargType(MethodType restargType, int fromPos) {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   210
        if (restargType.isGeneric())  return Object[].class;  // can be nothing else
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   211
        int maxPos = restargType.parameterCount();
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   212
        if (fromPos >= maxPos)  return Object[].class;  // reasonable default
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   213
        Class<?> argType = restargType.parameterType(fromPos);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   214
        for (int i = fromPos+1; i < maxPos; i++) {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   215
            if (argType != restargType.parameterType(i))
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   216
                throw newIllegalArgumentException("need homogeneous rest arguments", restargType);
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   217
        }
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   218
        if (argType == Object.class)  return Object[].class;
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   219
        return Array.newInstance(argType, 0).getClass();
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7554
diff changeset
   220
    }
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7554
diff changeset
   221
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   222
    public String toString() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   223
        return "Invokers"+targetType;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   224
    }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   225
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   226
    static MemberName methodHandleInvokeLinkerMethod(String name,
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   227
                                                     MethodType mtype,
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   228
                                                     Object[] appendixResult) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   229
        int which;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   230
        switch (name) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   231
            case "invokeExact":  which = MethodTypeForm.LF_EX_LINKER; break;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   232
            case "invoke":       which = MethodTypeForm.LF_GEN_LINKER; break;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   233
            default:             throw new InternalError("not invoker: "+name);
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   234
        }
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   235
        LambdaForm lform;
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   236
        if (mtype.parameterSlotCount() <= MethodType.MAX_MH_ARITY - MH_LINKER_ARG_APPENDED) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   237
            lform = invokeHandleForm(mtype, false, which);
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   238
            appendixResult[0] = mtype;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   239
        } else {
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   240
            lform = invokeHandleForm(mtype, true, which);
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   241
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   242
        return lform.vmentry;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   243
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   244
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   245
    // argument count to account for trailing "appendix value" (typically the mtype)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   246
    private static final int MH_LINKER_ARG_APPENDED = 1;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   247
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   248
    /** Returns an adapter for invokeExact or generic invoke, as a MH or constant pool linker.
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   249
     * If !customized, caller is responsible for supplying, during adapter execution,
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   250
     * a copy of the exact mtype.  This is because the adapter might be generalized to
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   251
     * a basic type.
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   252
     * @param mtype the caller's method type (either basic or full-custom)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   253
     * @param customized whether to use a trailing appendix argument (to carry the mtype)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   254
     * @param which bit-encoded 0x01 whether it is a CP adapter ("linker") or MHs.invoker value ("invoker");
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   255
     *                          0x02 whether it is for invokeExact or generic invoke
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   256
     */
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   257
    private static LambdaForm invokeHandleForm(MethodType mtype, boolean customized, int which) {
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   258
        boolean isCached;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   259
        if (!customized) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   260
            mtype = mtype.basicType();  // normalize Z to I, String to Object, etc.
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   261
            isCached = true;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   262
        } else {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   263
            isCached = false;  // maybe cache if mtype == mtype.basicType()
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   264
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   265
        boolean isLinker, isGeneric;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   266
        String debugName;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   267
        switch (which) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   268
        case MethodTypeForm.LF_EX_LINKER:   isLinker = true;  isGeneric = false; debugName = "invokeExact_MT"; break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   269
        case MethodTypeForm.LF_EX_INVOKER:  isLinker = false; isGeneric = false; debugName = "exactInvoker"; break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   270
        case MethodTypeForm.LF_GEN_LINKER:  isLinker = true;  isGeneric = true;  debugName = "invoke_MT"; break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   271
        case MethodTypeForm.LF_GEN_INVOKER: isLinker = false; isGeneric = true;  debugName = "invoker"; break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   272
        default: throw new InternalError();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   273
        }
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   274
        LambdaForm lform;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   275
        if (isCached) {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   276
            lform = mtype.form().cachedLambdaForm(which);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   277
            if (lform != null)  return lform;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   278
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   279
        // exactInvokerForm (Object,Object)Object
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   280
        //   link with java.lang.invoke.MethodHandle.invokeBasic(MethodHandle,Object,Object)Object/invokeSpecial
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   281
        final int THIS_MH      = 0;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   282
        final int CALL_MH      = THIS_MH + (isLinker ? 0 : 1);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   283
        final int ARG_BASE     = CALL_MH + 1;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   284
        final int OUTARG_LIMIT = ARG_BASE + mtype.parameterCount();
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   285
        final int INARG_LIMIT  = OUTARG_LIMIT + (isLinker && !customized ? 1 : 0);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   286
        int nameCursor = OUTARG_LIMIT;
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   287
        final int MTYPE_ARG    = customized ? -1 : nameCursor++;  // might be last in-argument
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   288
        final int CHECK_TYPE   = nameCursor++;
29020
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   289
        final int CHECK_CUSTOM = (CUSTOMIZE_THRESHOLD >= 0) ? nameCursor++ : -1;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   290
        final int LINKER_CALL  = nameCursor++;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   291
        MethodType invokerFormType = mtype.invokerType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   292
        if (isLinker) {
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   293
            if (!customized)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   294
                invokerFormType = invokerFormType.appendParameterTypes(MemberName.class);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   295
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   296
            invokerFormType = invokerFormType.invokerType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   297
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   298
        Name[] names = arguments(nameCursor - INARG_LIMIT, invokerFormType);
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   299
        assert(names.length == nameCursor)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   300
                : Arrays.asList(mtype, customized, which, nameCursor, names.length);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   301
        if (MTYPE_ARG >= INARG_LIMIT) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   302
            assert(names[MTYPE_ARG] == null);
26479
a60a19ec5ce5 8057657: Annotate LambdaForm parameters with types
vlivanov
parents: 26471
diff changeset
   303
            BoundMethodHandle.SpeciesData speciesData = BoundMethodHandle.speciesData_L();
a60a19ec5ce5 8057657: Annotate LambdaForm parameters with types
vlivanov
parents: 26471
diff changeset
   304
            names[THIS_MH] = names[THIS_MH].withConstraint(speciesData);
a60a19ec5ce5 8057657: Annotate LambdaForm parameters with types
vlivanov
parents: 26471
diff changeset
   305
            NamedFunction getter = speciesData.getterFunction(0);
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   306
            names[MTYPE_ARG] = new Name(getter, names[THIS_MH]);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   307
            // else if isLinker, then MTYPE is passed in from the caller (e.g., the JVM)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   308
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   309
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   310
        // Make the final call.  If isGeneric, then prepend the result of type checking.
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   311
        MethodType outCallType = mtype.basicType();
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   312
        Object[] outArgs = Arrays.copyOfRange(names, CALL_MH, OUTARG_LIMIT, Object[].class);
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   313
        Object mtypeArg = (customized ? mtype : names[MTYPE_ARG]);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   314
        if (!isGeneric) {
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   315
            names[CHECK_TYPE] = new Name(NF_checkExactType, names[CALL_MH], mtypeArg);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   316
            // mh.invokeExact(a*):R => checkExactType(mh, TYPEOF(a*:R)); mh.invokeBasic(a*)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   317
        } else {
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   318
            names[CHECK_TYPE] = new Name(NF_checkGenericType, names[CALL_MH], mtypeArg);
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   319
            // mh.invokeGeneric(a*):R => checkGenericType(mh, TYPEOF(a*:R)).invokeBasic(a*)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   320
            outArgs[0] = names[CHECK_TYPE];
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   321
        }
29020
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   322
        if (CHECK_CUSTOM != -1) {
30363
bff7ca1e5d2a 8078290: Customize adapted MethodHandle in MH.invoke() case
vlivanov
parents: 30336
diff changeset
   323
            names[CHECK_CUSTOM] = new Name(NF_checkCustomized, outArgs[0]);
29020
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   324
        }
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   325
        names[LINKER_CALL] = new Name(outCallType, outArgs);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   326
        lform = new LambdaForm(debugName, INARG_LIMIT, names);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   327
        if (isLinker)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   328
            lform.compileToBytecode();  // JVM needs a real methodOop
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   329
        if (isCached)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
   330
            lform = mtype.form().setCachedLambdaForm(which, lform);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   331
        return lform;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   332
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   333
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   334
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   335
    static MemberName varHandleInvokeLinkerMethod(String name,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   336
                                                  MethodType mtype) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   337
        LambdaForm lform;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   338
        if (mtype.parameterSlotCount() <= MethodType.MAX_MH_ARITY - MH_LINKER_ARG_APPENDED) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   339
            lform = varHandleMethodGenericLinkerHandleForm(name, mtype);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   340
        } else {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   341
            // TODO
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   342
            throw newInternalError("Unsupported parameter slot count " + mtype.parameterSlotCount());
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   343
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   344
        return lform.vmentry;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   345
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   346
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   347
    private static LambdaForm varHandleMethodGenericLinkerHandleForm(String name, MethodType mtype) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   348
        // TODO Cache form?
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   349
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   350
        final int THIS_VH      = 0;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   351
        final int ARG_BASE     = THIS_VH + 1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   352
        final int ARG_LIMIT = ARG_BASE + mtype.parameterCount();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   353
        int nameCursor = ARG_LIMIT;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   354
        final int VAD_ARG      = nameCursor++;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   355
        final int CHECK_TYPE   = nameCursor++;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   356
        final int CHECK_CUSTOM = (CUSTOMIZE_THRESHOLD >= 0) ? nameCursor++ : -1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   357
        final int LINKER_CALL  = nameCursor++;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   358
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   359
        Name[] names = new Name[LINKER_CALL + 1];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   360
        names[THIS_VH] = argument(THIS_VH, BasicType.basicType(Object.class));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   361
        for (int i = 0; i < mtype.parameterCount(); i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   362
            names[ARG_BASE + i] = argument(ARG_BASE + i, BasicType.basicType(mtype.parameterType(i)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   363
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   364
        names[VAD_ARG] = new Name(ARG_LIMIT, BasicType.basicType(Object.class));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   365
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   366
        names[CHECK_TYPE] = new Name(NF_checkVarHandleGenericType, names[THIS_VH], names[VAD_ARG]);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   367
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   368
        Object[] outArgs = new Object[ARG_LIMIT + 1];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   369
        outArgs[0] = names[CHECK_TYPE];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   370
        for (int i = 0; i < ARG_LIMIT; i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   371
            outArgs[i + 1] = names[i];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   372
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   373
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   374
        if (CHECK_CUSTOM != -1) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   375
            names[CHECK_CUSTOM] = new Name(NF_checkCustomized, outArgs[0]);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   376
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   377
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   378
        MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   379
                .basicType();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   380
        names[LINKER_CALL] = new Name(outCallType, outArgs);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   381
        LambdaForm lform = new LambdaForm(name + ":VarHandle_invoke_MT_" + shortenSignature(basicTypeSignature(mtype)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   382
                                          ARG_LIMIT + 1, names);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   383
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37343
diff changeset
   384
        lform.compileToBytecode();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   385
        return lform;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   386
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   387
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   388
    private static LambdaForm varHandleMethodInvokerHandleForm(String name, MethodType mtype, boolean isExact) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   389
        // TODO Cache form?
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   390
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   391
        final int THIS_MH      = 0;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   392
        final int CALL_VH      = THIS_MH + 1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   393
        final int ARG_BASE     = CALL_VH + 1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   394
        final int ARG_LIMIT = ARG_BASE + mtype.parameterCount();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   395
        int nameCursor = ARG_LIMIT;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   396
        final int VAD_ARG      = nameCursor++;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   397
        final int CHECK_TYPE   = nameCursor++;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   398
        final int LINKER_CALL  = nameCursor++;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   399
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   400
        Name[] names = new Name[LINKER_CALL + 1];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   401
        names[THIS_MH] = argument(THIS_MH, BasicType.basicType(Object.class));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   402
        names[CALL_VH] = argument(CALL_VH, BasicType.basicType(Object.class));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   403
        for (int i = 0; i < mtype.parameterCount(); i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   404
            names[ARG_BASE + i] = argument(ARG_BASE + i, BasicType.basicType(mtype.parameterType(i)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   405
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   406
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   407
        BoundMethodHandle.SpeciesData speciesData = BoundMethodHandle.speciesData_L();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   408
        names[THIS_MH] = names[THIS_MH].withConstraint(speciesData);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   409
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   410
        NamedFunction getter = speciesData.getterFunction(0);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   411
        names[VAD_ARG] = new Name(getter, names[THIS_MH]);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   412
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   413
        if (isExact) {
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   414
            names[CHECK_TYPE] = new Name(NF_checkVarHandleExactType, names[CALL_VH], names[VAD_ARG]);
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   415
        } else {
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   416
            names[CHECK_TYPE] = new Name(NF_checkVarHandleGenericType, names[CALL_VH], names[VAD_ARG]);
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   417
        }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   418
        Object[] outArgs = new Object[ARG_LIMIT];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   419
        outArgs[0] = names[CHECK_TYPE];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   420
        for (int i = 1; i < ARG_LIMIT; i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   421
            outArgs[i] = names[i];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   422
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   423
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   424
        MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   425
                .basicType();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   426
        names[LINKER_CALL] = new Name(outCallType, outArgs);
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   427
        String debugName = isExact ? ":VarHandle_exactInvoker" : ":VarHandle_invoker";
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   428
        LambdaForm lform = new LambdaForm(name + debugName + shortenSignature(basicTypeSignature(mtype)),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   429
                                          ARG_LIMIT, names);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   430
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   431
        lform.prepare();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   432
        return lform;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   433
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   434
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   435
    /*non-public*/ static
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   436
    @ForceInline
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37343
diff changeset
   437
    MethodHandle checkVarHandleGenericType(VarHandle handle, VarHandle.AccessDescriptor ad) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37343
diff changeset
   438
        // Test for exact match on invoker types
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37343
diff changeset
   439
        // TODO match with erased types and add cast of return value to lambda form
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37343
diff changeset
   440
        MethodHandle mh = handle.getMethodHandle(ad.mode);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37343
diff changeset
   441
        if (mh.type() == ad.symbolicMethodTypeInvoker) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   442
            return mh;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   443
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   444
        else {
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37343
diff changeset
   445
            return mh.asType(ad.symbolicMethodTypeInvoker);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   446
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   447
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   448
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   449
    /*non-public*/ static
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   450
    @ForceInline
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   451
    MethodHandle checkVarHandleExactType(VarHandle handle, VarHandle.AccessDescriptor ad) {
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   452
        MethodHandle mh = handle.getMethodHandle(ad.mode);
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   453
        MethodType mt = mh.type();
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   454
        if (mt != ad.symbolicMethodTypeInvoker) {
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   455
            throw newWrongMethodTypeException(mt, ad.symbolicMethodTypeInvoker);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   456
        }
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   457
        return mh;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   458
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   459
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   460
    /*non-public*/ static
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   461
    WrongMethodTypeException newWrongMethodTypeException(MethodType actual, MethodType expected) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   462
        // FIXME: merge with JVM logic for throwing WMTE
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   463
        return new WrongMethodTypeException("expected "+expected+" but found "+actual);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   464
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   465
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   466
    /** Static definition of MethodHandle.invokeExact checking code. */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   467
    /*non-public*/ static
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   468
    @ForceInline
35773
80def5fa4d65 8071368: Use more concrete types for NamedFunction constants in the code
srastogi
parents: 35252
diff changeset
   469
    void checkExactType(MethodHandle mh, MethodType expected) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   470
        MethodType actual = mh.type();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   471
        if (actual != expected)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   472
            throw newWrongMethodTypeException(expected, actual);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   473
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   474
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   475
    /** Static definition of MethodHandle.invokeGeneric checking code.
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   476
     * Directly returns the type-adjusted MH to invoke, as follows:
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   477
     * {@code (R)MH.invoke(a*) => MH.asType(TYPEOF(a*:R)).invokeBasic(a*)}
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   478
     */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   479
    /*non-public*/ static
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   480
    @ForceInline
35773
80def5fa4d65 8071368: Use more concrete types for NamedFunction constants in the code
srastogi
parents: 35252
diff changeset
   481
    MethodHandle checkGenericType(MethodHandle mh,  MethodType expected) {
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   482
        return mh.asType(expected);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   483
        /* Maybe add more paths here.  Possible optimizations:
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   484
         * for (R)MH.invoke(a*),
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   485
         * let MT0 = TYPEOF(a*:R), MT1 = MH.type
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   486
         *
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   487
         * if MT0==MT1 or MT1 can be safely called by MT0
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   488
         *  => MH.invokeBasic(a*)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   489
         * if MT1 can be safely called by MT0[R := Object]
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   490
         *  => MH.invokeBasic(a*) & checkcast(R)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   491
         * if MT1 can be safely called by MT0[* := Object]
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   492
         *  => checkcast(A)* & MH.invokeBasic(a*) & checkcast(R)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   493
         * if a big adapter BA can be pulled out of (MT0,MT1)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   494
         *  => BA.invokeBasic(MT0,MH,a*)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   495
         * if a local adapter LA can cached on static CS0 = new GICS(MT0)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   496
         *  => CS0.LA.invokeBasic(MH,a*)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   497
         * else
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   498
         *  => MH.asType(MT0).invokeBasic(A*)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   499
         */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   500
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   501
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   502
    static MemberName linkToCallSiteMethod(MethodType mtype) {
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   503
        LambdaForm lform = callSiteForm(mtype, false);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   504
        return lform.vmentry;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   505
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   506
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   507
    static MemberName linkToTargetMethod(MethodType mtype) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   508
        LambdaForm lform = callSiteForm(mtype, true);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   509
        return lform.vmentry;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   510
    }
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   511
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   512
    // skipCallSite is true if we are optimizing a ConstantCallSite
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   513
    private static LambdaForm callSiteForm(MethodType mtype, boolean skipCallSite) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   514
        mtype = mtype.basicType();  // normalize Z to I, String to Object, etc.
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   515
        final int which = (skipCallSite ? MethodTypeForm.LF_MH_LINKER : MethodTypeForm.LF_CS_LINKER);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   516
        LambdaForm lform = mtype.form().cachedLambdaForm(which);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   517
        if (lform != null)  return lform;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   518
        // exactInvokerForm (Object,Object)Object
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   519
        //   link with java.lang.invoke.MethodHandle.invokeBasic(MethodHandle,Object,Object)Object/invokeSpecial
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   520
        final int ARG_BASE     = 0;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   521
        final int OUTARG_LIMIT = ARG_BASE + mtype.parameterCount();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   522
        final int INARG_LIMIT  = OUTARG_LIMIT + 1;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   523
        int nameCursor = OUTARG_LIMIT;
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   524
        final int APPENDIX_ARG = nameCursor++;  // the last in-argument
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   525
        final int CSITE_ARG    = skipCallSite ? -1 : APPENDIX_ARG;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   526
        final int CALL_MH      = skipCallSite ? APPENDIX_ARG : nameCursor++;  // result of getTarget
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   527
        final int LINKER_CALL  = nameCursor++;
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   528
        MethodType invokerFormType = mtype.appendParameterTypes(skipCallSite ? MethodHandle.class : CallSite.class);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   529
        Name[] names = arguments(nameCursor - INARG_LIMIT, invokerFormType);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   530
        assert(names.length == nameCursor);
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   531
        assert(names[APPENDIX_ARG] != null);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   532
        if (!skipCallSite)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   533
            names[CALL_MH] = new Name(NF_getCallSiteTarget, names[CSITE_ARG]);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   534
        // (site.)invokedynamic(a*):R => mh = site.getTarget(); mh.invokeBasic(a*)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   535
        final int PREPEND_MH = 0, PREPEND_COUNT = 1;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   536
        Object[] outArgs = Arrays.copyOfRange(names, ARG_BASE, OUTARG_LIMIT + PREPEND_COUNT, Object[].class);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   537
        // prepend MH argument:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   538
        System.arraycopy(outArgs, 0, outArgs, PREPEND_COUNT, outArgs.length - PREPEND_COUNT);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   539
        outArgs[PREPEND_MH] = names[CALL_MH];
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   540
        names[LINKER_CALL] = new Name(mtype, outArgs);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   541
        lform = new LambdaForm((skipCallSite ? "linkToTargetMethod" : "linkToCallSite"), INARG_LIMIT, names);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   542
        lform.compileToBytecode();  // JVM needs a real methodOop
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 19804
diff changeset
   543
        lform = mtype.form().setCachedLambdaForm(which, lform);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   544
        return lform;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   545
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   546
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   547
    /** Static definition of MethodHandle.invokeGeneric checking code. */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   548
    /*non-public*/ static
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   549
    @ForceInline
35773
80def5fa4d65 8071368: Use more concrete types for NamedFunction constants in the code
srastogi
parents: 35252
diff changeset
   550
    MethodHandle getCallSiteTarget(CallSite site) {
80def5fa4d65 8071368: Use more concrete types for NamedFunction constants in the code
srastogi
parents: 35252
diff changeset
   551
        return site.getTarget();
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   552
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   553
29020
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   554
    /*non-public*/ static
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   555
    @ForceInline
35773
80def5fa4d65 8071368: Use more concrete types for NamedFunction constants in the code
srastogi
parents: 35252
diff changeset
   556
    void checkCustomized(MethodHandle mh) {
30336
36774c81a366 8075263: MHI::checkCustomized isn't eliminated for inlined MethodHandles
vlivanov
parents: 29020
diff changeset
   557
        if (MethodHandleImpl.isCompileConstant(mh)) return;
29020
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   558
        if (mh.form.customized == null) {
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   559
            maybeCustomize(mh);
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   560
        }
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   561
    }
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   562
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   563
    /*non-public*/ static
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   564
    @DontInline
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   565
    void maybeCustomize(MethodHandle mh) {
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   566
        byte count = mh.customizationCount;
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   567
        if (count >= CUSTOMIZE_THRESHOLD) {
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   568
            mh.customize();
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   569
        } else {
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   570
            mh.customizationCount = (byte)(count+1);
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   571
        }
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   572
    }
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   573
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   574
    // Local constant functions:
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   575
    private static final NamedFunction
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   576
        NF_checkExactType,
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   577
        NF_checkGenericType,
29020
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   578
        NF_getCallSiteTarget,
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   579
        NF_checkCustomized,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   580
        NF_checkVarHandleGenericType,
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37792
diff changeset
   581
        NF_checkVarHandleExactType;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   582
    static {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   583
        try {
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   584
            NamedFunction nfs[] = {
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   585
                NF_checkExactType = new NamedFunction(Invokers.class
35773
80def5fa4d65 8071368: Use more concrete types for NamedFunction constants in the code
srastogi
parents: 35252
diff changeset
   586
                        .getDeclaredMethod("checkExactType", MethodHandle.class,  MethodType.class)),
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   587
                NF_checkGenericType = new NamedFunction(Invokers.class
35773
80def5fa4d65 8071368: Use more concrete types for NamedFunction constants in the code
srastogi
parents: 35252
diff changeset
   588
                        .getDeclaredMethod("checkGenericType", MethodHandle.class,  MethodType.class)),
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   589
                NF_getCallSiteTarget = new NamedFunction(Invokers.class
35773
80def5fa4d65 8071368: Use more concrete types for NamedFunction constants in the code
srastogi
parents: 35252
diff changeset
   590
                        .getDeclaredMethod("getCallSiteTarget", CallSite.class)),
29020
9f6d43586ccb 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents: 26479
diff changeset
   591
                NF_checkCustomized = new NamedFunction(Invokers.class
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   592
                        .getDeclaredMethod("checkCustomized", MethodHandle.class)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   593
                NF_checkVarHandleGenericType = new NamedFunction(Invokers.class
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   594
                        .getDeclaredMethod("checkVarHandleGenericType", VarHandle.class, VarHandle.AccessDescriptor.class)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   595
                NF_checkVarHandleExactType = new NamedFunction(Invokers.class
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 35773
diff changeset
   596
                        .getDeclaredMethod("checkVarHandleExactType", VarHandle.class, VarHandle.AccessDescriptor.class)),
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   597
            };
33841
1d1d1ea6a5f2 8142334: Improve lazy initialization of java.lang.invoke
redestad
parents: 30363
diff changeset
   598
            // Each nf must be statically invocable or we get tied up in our bootstraps.
1d1d1ea6a5f2 8142334: Improve lazy initialization of java.lang.invoke
redestad
parents: 30363
diff changeset
   599
            assert(InvokerBytecodeGenerator.isStaticallyInvocable(nfs));
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   600
        } catch (ReflectiveOperationException ex) {
14089
0a41b980d62a 8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents: 13610
diff changeset
   601
            throw newInternalError(ex);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   602
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   603
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   604
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   605
    private static class Lazy {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   606
        private static final MethodHandle MH_asSpreader;
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   607
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   608
        static {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   609
            try {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   610
                MH_asSpreader = IMPL_LOOKUP.findVirtual(MethodHandle.class, "asSpreader",
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   611
                        MethodType.methodType(MethodHandle.class, Class.class, int.class));
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   612
            } catch (ReflectiveOperationException ex) {
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   613
                throw newInternalError(ex);
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   614
            }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   615
        }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   616
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   617
}