author | shade |
Tue, 17 May 2016 22:28:00 +0300 | |
changeset 38372 | 017d7578731c |
parent 38328 | 40435a469d25 |
child 40543 | 629f1f599595 |
permissions | -rw-r--r-- |
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 | 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 | 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 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
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 | 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 | 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 | 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 | 48 |
// Cached adapter information: |
49 |
private final @Stable MethodHandle[] invokers = new MethodHandle[INV_LIMIT]; |
|
50 |
// Indexes into invokers: |
|
51 |
static final int |
|
52 |
INV_EXACT = 0, // MethodHandles.exactInvoker |
|
53 |
INV_GENERIC = 1, // MethodHandles.invoker (generic invocation) |
|
54 |
INV_BASIC = 2, // MethodHandles.basicInvoker |
|
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 | 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 | 68 |
return setCachedInvoker(INV_EXACT, invoker); |
69 |
} |
|
70 |
||
71 |
/*non-public*/ MethodHandle genericInvoker() { |
|
72 |
MethodHandle invoker = cachedInvoker(INV_GENERIC); |
|
73 |
if (invoker != null) return invoker; |
|
74 |
invoker = makeExactOrGeneralInvoker(false); |
|
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 | 78 |
/*non-public*/ MethodHandle basicInvoker() { |
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 | 81 |
MethodType basicType = targetType.basicType(); |
82 |
if (basicType != targetType) { |
|
83 |
// double cache; not used significantly |
|
84 |
return setCachedInvoker(INV_BASIC, basicType.invokers().basicInvoker()); |
|
85 |
} |
|
86 |
invoker = basicType.form().cachedMethodHandle(MethodTypeForm.MH_BASIC_INV); |
|
87 |
if (invoker == null) { |
|
88 |
MemberName method = invokeBasicMethod(basicType); |
|
89 |
invoker = DirectMethodHandle.make(method); |
|
90 |
assert(checkInvoker(invoker)); |
|
91 |
invoker = basicType.form().setCachedMethodHandle(MethodTypeForm.MH_BASIC_INV, invoker); |
|
92 |
} |
|
93 |
return setCachedInvoker(INV_BASIC, invoker); |
|
94 |
} |
|
95 |
||
36934 | 96 |
/*non-public*/ MethodHandle varHandleMethodInvoker(VarHandle.AccessMode ak) { |
97 |
// TODO cache invoker |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37792
diff
changeset
|
98 |
return makeVarHandleMethodInvoker(ak, false); |
36934 | 99 |
} |
100 |
||
101 |
/*non-public*/ MethodHandle varHandleMethodExactInvoker(VarHandle.AccessMode ak) { |
|
102 |
// TODO cache invoker |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37792
diff
changeset
|
103 |
return makeVarHandleMethodInvoker(ak, true); |
36934 | 104 |
} |
105 |
||
26468 | 106 |
private MethodHandle cachedInvoker(int idx) { |
107 |
return invokers[idx]; |
|
108 |
} |
|
109 |
||
110 |
private synchronized MethodHandle setCachedInvoker(int idx, final MethodHandle invoker) { |
|
111 |
// Simulate a CAS, to avoid racy duplication of results. |
|
112 |
MethodHandle prev = invokers[idx]; |
|
113 |
if (prev != null) return prev; |
|
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 | 131 |
MethodType mtype = targetType; |
132 |
MethodType invokerType = mtype.insertParameterTypes(0, VarHandle.class); |
|
133 |
||
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37792
diff
changeset
|
134 |
LambdaForm lform = varHandleMethodInvokerHandleForm(ak.methodName(), mtype, isExact); |
36934 | 135 |
VarHandle.AccessDescriptor ad = new VarHandle.AccessDescriptor(mtype, ak.at.ordinal(), ak.ordinal()); |
136 |
MethodHandle invoker = BoundMethodHandle.bindSingle(invokerType, lform, ad); |
|
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 | 139 |
assert(checkVarHandleInvoker(invoker)); |
140 |
||
141 |
maybeCompileToBytecode(invoker); |
|
142 |
return invoker; |
|
143 |
} |
|
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 | 174 |
private boolean checkVarHandleInvoker(MethodHandle invoker) { |
175 |
MethodType invokerType = targetType.insertParameterTypes(0, VarHandle.class); |
|
176 |
assert(invokerType.equals(invoker.type())) |
|
177 |
: java.util.Arrays.asList(targetType, invokerType, invoker); |
|
178 |
assert(invoker.internalMemberName() == null || |
|
179 |
invoker.internalMemberName().getMethodType().equals(targetType)); |
|
180 |
assert(!invoker.isVarargsCollector()); |
|
181 |
return true; |
|
182 |
} |
|
183 |
||
26468 | 184 |
/** |
185 |
* Find or create an invoker which passes unchanged a given number of arguments |
|
186 |
* and spreads the rest from a trailing array argument. |
|
187 |
* The invoker target type is the post-spread type {@code (TYPEOF(uarg*), TYPEOF(sarg*))=>RT}. |
|
188 |
* All the {@code sarg}s must have a common type {@code C}. (If there are none, {@code Object} is assumed.} |
|
189 |
* @param leadingArgCount the number of unchanged (non-spread) arguments |
|
190 |
* @return {@code invoker.invokeExact(mh, uarg*, C[]{sarg*}) := (RT)mh.invoke(uarg*, sarg*)} |
|
191 |
*/ |
|
192 |
/*non-public*/ MethodHandle spreadInvoker(int leadingArgCount) { |
|
193 |
int spreadArgCount = targetType.parameterCount() - leadingArgCount; |
|
194 |
MethodType postSpreadType = targetType; |
|
195 |
Class<?> argArrayType = impliedRestargType(postSpreadType, leadingArgCount); |
|
196 |
if (postSpreadType.parameterSlotCount() <= MethodType.MAX_MH_INVOKER_ARITY) { |
|
197 |
return genericInvoker().asSpreader(argArrayType, spreadArgCount); |
|
198 |
} |
|
199 |
// Cannot build a generic invoker here of type ginvoker.invoke(mh, a*[254]). |
|
200 |
// Instead, factor sinvoker.invoke(mh, a) into ainvoker.invoke(filter(mh), a) |
|
201 |
// where filter(mh) == mh.asSpreader(Object[], spreadArgCount) |
|
202 |
MethodType preSpreadType = postSpreadType |
|
203 |
.replaceParameterTypes(leadingArgCount, postSpreadType.parameterCount(), argArrayType); |
|
204 |
MethodHandle arrayInvoker = MethodHandles.invoker(preSpreadType); |
|
205 |
MethodHandle makeSpreader = MethodHandles.insertArguments(Lazy.MH_asSpreader, 1, argArrayType, spreadArgCount); |
|
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 | 209 |
private static Class<?> impliedRestargType(MethodType restargType, int fromPos) { |
210 |
if (restargType.isGeneric()) return Object[].class; // can be nothing else |
|
211 |
int maxPos = restargType.parameterCount(); |
|
212 |
if (fromPos >= maxPos) return Object[].class; // reasonable default |
|
213 |
Class<?> argType = restargType.parameterType(fromPos); |
|
214 |
for (int i = fromPos+1; i < maxPos; i++) { |
|
215 |
if (argType != restargType.parameterType(i)) |
|
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 | 218 |
if (argType == Object.class) return Object[].class; |
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 | 231 |
case "invokeExact": which = MethodTypeForm.LF_EX_LINKER; break; |
232 |
case "invoke": which = MethodTypeForm.LF_GEN_LINKER; break; |
|
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 | 334 |
|
335 |
static MemberName varHandleInvokeLinkerMethod(String name, |
|
336 |
MethodType mtype) { |
|
337 |
LambdaForm lform; |
|
338 |
if (mtype.parameterSlotCount() <= MethodType.MAX_MH_ARITY - MH_LINKER_ARG_APPENDED) { |
|
339 |
lform = varHandleMethodGenericLinkerHandleForm(name, mtype); |
|
340 |
} else { |
|
341 |
// TODO |
|
342 |
throw newInternalError("Unsupported parameter slot count " + mtype.parameterSlotCount()); |
|
343 |
} |
|
344 |
return lform.vmentry; |
|
345 |
} |
|
346 |
||
347 |
private static LambdaForm varHandleMethodGenericLinkerHandleForm(String name, MethodType mtype) { |
|
348 |
// TODO Cache form? |
|
349 |
||
350 |
final int THIS_VH = 0; |
|
351 |
final int ARG_BASE = THIS_VH + 1; |
|
352 |
final int ARG_LIMIT = ARG_BASE + mtype.parameterCount(); |
|
353 |
int nameCursor = ARG_LIMIT; |
|
354 |
final int VAD_ARG = nameCursor++; |
|
355 |
final int CHECK_TYPE = nameCursor++; |
|
356 |
final int CHECK_CUSTOM = (CUSTOMIZE_THRESHOLD >= 0) ? nameCursor++ : -1; |
|
357 |
final int LINKER_CALL = nameCursor++; |
|
358 |
||
359 |
Name[] names = new Name[LINKER_CALL + 1]; |
|
360 |
names[THIS_VH] = argument(THIS_VH, BasicType.basicType(Object.class)); |
|
361 |
for (int i = 0; i < mtype.parameterCount(); i++) { |
|
362 |
names[ARG_BASE + i] = argument(ARG_BASE + i, BasicType.basicType(mtype.parameterType(i))); |
|
363 |
} |
|
364 |
names[VAD_ARG] = new Name(ARG_LIMIT, BasicType.basicType(Object.class)); |
|
365 |
||
366 |
names[CHECK_TYPE] = new Name(NF_checkVarHandleGenericType, names[THIS_VH], names[VAD_ARG]); |
|
367 |
||
368 |
Object[] outArgs = new Object[ARG_LIMIT + 1]; |
|
369 |
outArgs[0] = names[CHECK_TYPE]; |
|
370 |
for (int i = 0; i < ARG_LIMIT; i++) { |
|
371 |
outArgs[i + 1] = names[i]; |
|
372 |
} |
|
373 |
||
374 |
if (CHECK_CUSTOM != -1) { |
|
375 |
names[CHECK_CUSTOM] = new Name(NF_checkCustomized, outArgs[0]); |
|
376 |
} |
|
377 |
||
378 |
MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class) |
|
379 |
.basicType(); |
|
380 |
names[LINKER_CALL] = new Name(outCallType, outArgs); |
|
381 |
LambdaForm lform = new LambdaForm(name + ":VarHandle_invoke_MT_" + shortenSignature(basicTypeSignature(mtype)), |
|
382 |
ARG_LIMIT + 1, names); |
|
383 |
||
37792 | 384 |
lform.compileToBytecode(); |
36934 | 385 |
return lform; |
386 |
} |
|
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 | 389 |
// TODO Cache form? |
390 |
||
391 |
final int THIS_MH = 0; |
|
392 |
final int CALL_VH = THIS_MH + 1; |
|
393 |
final int ARG_BASE = CALL_VH + 1; |
|
394 |
final int ARG_LIMIT = ARG_BASE + mtype.parameterCount(); |
|
395 |
int nameCursor = ARG_LIMIT; |
|
396 |
final int VAD_ARG = nameCursor++; |
|
397 |
final int CHECK_TYPE = nameCursor++; |
|
398 |
final int LINKER_CALL = nameCursor++; |
|
399 |
||
400 |
Name[] names = new Name[LINKER_CALL + 1]; |
|
401 |
names[THIS_MH] = argument(THIS_MH, BasicType.basicType(Object.class)); |
|
402 |
names[CALL_VH] = argument(CALL_VH, BasicType.basicType(Object.class)); |
|
403 |
for (int i = 0; i < mtype.parameterCount(); i++) { |
|
404 |
names[ARG_BASE + i] = argument(ARG_BASE + i, BasicType.basicType(mtype.parameterType(i))); |
|
405 |
} |
|
406 |
||
407 |
BoundMethodHandle.SpeciesData speciesData = BoundMethodHandle.speciesData_L(); |
|
408 |
names[THIS_MH] = names[THIS_MH].withConstraint(speciesData); |
|
409 |
||
410 |
NamedFunction getter = speciesData.getterFunction(0); |
|
411 |
names[VAD_ARG] = new Name(getter, names[THIS_MH]); |
|
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 | 418 |
Object[] outArgs = new Object[ARG_LIMIT]; |
419 |
outArgs[0] = names[CHECK_TYPE]; |
|
420 |
for (int i = 1; i < ARG_LIMIT; i++) { |
|
421 |
outArgs[i] = names[i]; |
|
422 |
} |
|
423 |
||
424 |
MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class) |
|
425 |
.basicType(); |
|
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 | 429 |
ARG_LIMIT, names); |
430 |
||
431 |
lform.prepare(); |
|
432 |
return lform; |
|
433 |
} |
|
434 |
||
435 |
/*non-public*/ static |
|
436 |
@ForceInline |
|
37792 | 437 |
MethodHandle checkVarHandleGenericType(VarHandle handle, VarHandle.AccessDescriptor ad) { |
438 |
// Test for exact match on invoker types |
|
439 |
// TODO match with erased types and add cast of return value to lambda form |
|
440 |
MethodHandle mh = handle.getMethodHandle(ad.mode); |
|
441 |
if (mh.type() == ad.symbolicMethodTypeInvoker) { |
|
36934 | 442 |
return mh; |
443 |
} |
|
444 |
else { |
|
37792 | 445 |
return mh.asType(ad.symbolicMethodTypeInvoker); |
36934 | 446 |
} |
447 |
} |
|
448 |
||
449 |
/*non-public*/ static |
|
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 | 456 |
} |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37792
diff
changeset
|
457 |
return mh; |
36934 | 458 |
} |
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 | 579 |
NF_checkCustomized, |
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 | 592 |
.getDeclaredMethod("checkCustomized", MethodHandle.class)), |
593 |
NF_checkVarHandleGenericType = new NamedFunction(Invokers.class |
|
594 |
.getDeclaredMethod("checkVarHandleGenericType", VarHandle.class, VarHandle.AccessDescriptor.class)), |
|
595 |
NF_checkVarHandleExactType = new NamedFunction(Invokers.class |
|
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 | 605 |
private static class Lazy { |
606 |
private static final MethodHandle MH_asSpreader; |
|
607 |
||
608 |
static { |
|
609 |
try { |
|
610 |
MH_asSpreader = IMPL_LOOKUP.findVirtual(MethodHandle.class, "asSpreader", |
|
611 |
MethodType.methodType(MethodHandle.class, Class.class, int.class)); |
|
612 |
} catch (ReflectiveOperationException ex) { |
|
613 |
throw newInternalError(ex); |
|
614 |
} |
|
615 |
} |
|
616 |
} |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
617 |
} |