author | darcy |
Thu, 27 Jun 2013 19:02:02 -0700 | |
changeset 18569 | 0e46c17766b7 |
parent 14342 | 8435a30053c1 |
child 19804 | 83170920c07b |
permissions | -rw-r--r-- |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
14089
diff
changeset
|
2 |
* Copyright (c) 2008, 2012, 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 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
28 |
import java.util.Arrays; |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
29 |
import sun.invoke.empty.Empty; |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
import static java.lang.invoke.LambdaForm.*; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
34 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
35 |
/** |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
36 |
* Construction and caching of often-used invokers. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
37 |
* @author jrose |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
38 |
*/ |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
39 |
class Invokers { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
40 |
// exact type (sans leading taget MH) for the outgoing call |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
41 |
private final MethodType targetType; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
42 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
43 |
// FIXME: Get rid of the invokers that are not useful. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
44 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
45 |
// exact invoker for the outgoing call |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
46 |
private /*lazy*/ MethodHandle exactInvoker; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
47 |
|
7554
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
48 |
// erased (partially untyped but with primitives) invoker for the outgoing call |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
49 |
// FIXME: get rid of |
7554
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
50 |
private /*lazy*/ MethodHandle erasedInvoker; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
51 |
// FIXME: get rid of |
7554
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
52 |
/*lazy*/ MethodHandle erasedInvokerWithDrops; // for InvokeGeneric |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
53 |
|
9645
dabb5e4edc4c
7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents:
8822
diff
changeset
|
54 |
// general invoker for the outgoing call |
dabb5e4edc4c
7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents:
8822
diff
changeset
|
55 |
private /*lazy*/ MethodHandle generalInvoker; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
56 |
|
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
57 |
// general invoker for the outgoing call, uses varargs |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
58 |
private /*lazy*/ MethodHandle varargsInvoker; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
59 |
|
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
60 |
// general invoker for the outgoing call; accepts a trailing Object[] |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
61 |
private final /*lazy*/ MethodHandle[] spreadInvokers; |
4537 | 62 |
|
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
63 |
// invoker for an unbound callsite |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
64 |
private /*lazy*/ MethodHandle uninitializedCallSite; |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
65 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
66 |
/** Compute and cache information common to all collecting adapters |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
67 |
* 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
|
68 |
*/ |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
69 |
/*non-public*/ Invokers(MethodType targetType) { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
70 |
this.targetType = targetType; |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
71 |
this.spreadInvokers = new MethodHandle[targetType.parameterCount()+1]; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
72 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
73 |
|
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
74 |
/*non-public*/ MethodHandle exactInvoker() { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
75 |
MethodHandle invoker = exactInvoker; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
76 |
if (invoker != null) return invoker; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
77 |
MethodType mtype = targetType; |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
78 |
MethodType invokerType = mtype.invokerType(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
79 |
LambdaForm lform; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
80 |
final int MTYPE_ARG_APPENDED = 1; // argument count for appended mtype value |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
81 |
if (mtype.parameterSlotCount() <= MethodType.MAX_MH_INVOKER_ARITY - MTYPE_ARG_APPENDED) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
82 |
lform = invokeForm(mtype, false, MethodTypeForm.LF_EX_INVOKER); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
83 |
invoker = BoundMethodHandle.bindSingle(invokerType, lform, mtype); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
84 |
} else { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
85 |
// At maximum arity, we cannot afford an extra mtype argument, |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
86 |
// so build a fully customized (non-cached) invoker form. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
87 |
lform = invokeForm(mtype, true, MethodTypeForm.LF_EX_INVOKER); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
88 |
invoker = SimpleMethodHandle.make(invokerType, lform); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
89 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
90 |
assert(checkInvoker(invoker)); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
91 |
exactInvoker = invoker; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
92 |
return invoker; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
93 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
94 |
|
9645
dabb5e4edc4c
7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents:
8822
diff
changeset
|
95 |
/*non-public*/ MethodHandle generalInvoker() { |
dabb5e4edc4c
7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents:
8822
diff
changeset
|
96 |
MethodHandle invoker = generalInvoker; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
97 |
if (invoker != null) return invoker; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
98 |
MethodType mtype = targetType; |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
99 |
MethodType invokerType = mtype.invokerType(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
100 |
LambdaForm lform; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
101 |
final int MTYPE_ARG_APPENDED = 1; // argument count for appended mtype value |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
102 |
assert(GENERIC_INVOKER_SLOP >= MTYPE_ARG_APPENDED); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
103 |
if (mtype.parameterSlotCount() <= MethodType.MAX_MH_INVOKER_ARITY - GENERIC_INVOKER_SLOP) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
104 |
prepareForGenericCall(mtype); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
105 |
lform = invokeForm(mtype, false, MethodTypeForm.LF_GEN_INVOKER); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
106 |
invoker = BoundMethodHandle.bindSingle(invokerType, lform, mtype); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
107 |
} else { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
108 |
// At maximum arity, we cannot afford an extra mtype argument, |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
109 |
// so build a fully customized (non-cached) invoker form. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
110 |
lform = invokeForm(mtype, true, MethodTypeForm.LF_GEN_INVOKER); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
111 |
invoker = SimpleMethodHandle.make(invokerType, lform); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
112 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
113 |
assert(checkInvoker(invoker)); |
9645
dabb5e4edc4c
7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents:
8822
diff
changeset
|
114 |
generalInvoker = invoker; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
115 |
return invoker; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
116 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
117 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
118 |
/*non-public*/ MethodHandle makeBasicInvoker() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
119 |
MethodHandle invoker = DirectMethodHandle.make(invokeBasicMethod(targetType)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
120 |
assert(targetType == targetType.basicType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
121 |
// Note: This is not cached here. It is cached by the calling MethodTypeForm. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
122 |
assert(checkInvoker(invoker)); |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
123 |
return invoker; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
124 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
125 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
126 |
static MemberName invokeBasicMethod(MethodType type) { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
127 |
type = type.basicType(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
128 |
String name = "invokeBasic"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
129 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
130 |
//Lookup.findVirtual(MethodHandle.class, name, type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
131 |
return IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, MethodHandle.class, name, type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
132 |
} catch (ReflectiveOperationException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
133 |
throw newInternalError("JVM cannot find invoker for "+type, ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
134 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
135 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
136 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
137 |
private boolean checkInvoker(MethodHandle invoker) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
138 |
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
|
139 |
: 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
|
140 |
assert(invoker.internalMemberName() == null || |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
141 |
invoker.internalMemberName().getMethodType().equals(targetType)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
142 |
assert(!invoker.isVarargsCollector()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
143 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
144 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
145 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
146 |
// FIXME: get rid of |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
147 |
/*non-public*/ MethodHandle erasedInvoker() { |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
148 |
MethodHandle xinvoker = exactInvoker(); |
7554
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
149 |
MethodHandle invoker = erasedInvoker; |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
150 |
if (invoker != null) return invoker; |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
151 |
MethodType erasedType = targetType.erase(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
152 |
invoker = xinvoker.asType(erasedType.invokerType()); |
7554
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
153 |
erasedInvoker = invoker; |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
154 |
return invoker; |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
155 |
} |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
156 |
|
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
157 |
/*non-public*/ MethodHandle spreadInvoker(int leadingArgCount) { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
158 |
MethodHandle vaInvoker = spreadInvokers[leadingArgCount]; |
4537 | 159 |
if (vaInvoker != null) return vaInvoker; |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
160 |
int spreadArgCount = targetType.parameterCount() - leadingArgCount; |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
161 |
MethodType spreadInvokerType = targetType |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
162 |
.replaceParameterTypes(leadingArgCount, targetType.parameterCount(), Object[].class); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
163 |
if (targetType.parameterSlotCount() <= MethodType.MAX_MH_INVOKER_ARITY) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
164 |
// Factor sinvoker.invoke(mh, a) into ginvoker.asSpreader().invoke(mh, a) |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
165 |
// where ginvoker.invoke(mh, a*) => mh.invoke(a*). |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
166 |
MethodHandle genInvoker = generalInvoker(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
167 |
vaInvoker = genInvoker.asSpreader(Object[].class, spreadArgCount); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
168 |
} else { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
169 |
// Cannot build a general invoker here of type ginvoker.invoke(mh, a*[254]). |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
170 |
// Instead, factor sinvoker.invoke(mh, a) into ainvoker.invoke(filter(mh), a) |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
171 |
// where filter(mh) == mh.asSpreader(Object[], spreadArgCount) |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
172 |
MethodHandle arrayInvoker = MethodHandles.exactInvoker(spreadInvokerType); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
173 |
MethodHandle makeSpreader; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
174 |
try { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
175 |
makeSpreader = IMPL_LOOKUP |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
176 |
.findVirtual(MethodHandle.class, "asSpreader", |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
177 |
MethodType.methodType(MethodHandle.class, Class.class, int.class)); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
178 |
} catch (ReflectiveOperationException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
179 |
throw newInternalError(ex); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
180 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
181 |
makeSpreader = MethodHandles.insertArguments(makeSpreader, 1, Object[].class, spreadArgCount); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
182 |
vaInvoker = MethodHandles.filterArgument(arrayInvoker, 0, makeSpreader); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
183 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
184 |
assert(vaInvoker.type().equals(spreadInvokerType.invokerType())); |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
185 |
spreadInvokers[leadingArgCount] = vaInvoker; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
186 |
return vaInvoker; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
187 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
188 |
|
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
189 |
/*non-public*/ MethodHandle varargsInvoker() { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
190 |
MethodHandle vaInvoker = varargsInvoker; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
191 |
if (vaInvoker != null) return vaInvoker; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
192 |
vaInvoker = spreadInvoker(0).asType(MethodType.genericMethodType(0, true).invokerType()); |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
193 |
varargsInvoker = vaInvoker; |
4537 | 194 |
return vaInvoker; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
195 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
196 |
|
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
197 |
private static MethodHandle THROW_UCS = null; |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
198 |
|
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
199 |
/*non-public*/ MethodHandle uninitializedCallSite() { |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
200 |
MethodHandle invoker = uninitializedCallSite; |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
201 |
if (invoker != null) return invoker; |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
202 |
if (targetType.parameterCount() > 0) { |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
203 |
MethodType type0 = targetType.dropParameterTypes(0, targetType.parameterCount()); |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
204 |
Invokers invokers0 = type0.invokers(); |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
205 |
invoker = MethodHandles.dropArguments(invokers0.uninitializedCallSite(), |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
206 |
0, targetType.parameterList()); |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
207 |
assert(invoker.type().equals(targetType)); |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
208 |
uninitializedCallSite = invoker; |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
209 |
return invoker; |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
210 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
211 |
invoker = THROW_UCS; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
212 |
if (invoker == null) { |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
213 |
try { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
214 |
THROW_UCS = invoker = IMPL_LOOKUP |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
215 |
.findStatic(CallSite.class, "uninitializedCallSite", |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
216 |
MethodType.methodType(Empty.class)); |
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
8346
diff
changeset
|
217 |
} catch (ReflectiveOperationException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
218 |
throw newInternalError(ex); |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
219 |
} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
220 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
221 |
invoker = MethodHandles.explicitCastArguments(invoker, MethodType.methodType(targetType.returnType())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
222 |
invoker = invoker.dropArguments(targetType, 0, targetType.parameterCount()); |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
223 |
assert(invoker.type().equals(targetType)); |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
224 |
uninitializedCallSite = invoker; |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
225 |
return invoker; |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
226 |
} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
227 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
228 |
public String toString() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
229 |
return "Invokers"+targetType; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
230 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
231 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
232 |
static MemberName exactInvokerMethod(MethodType mtype, Object[] appendixResult) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
233 |
LambdaForm lform; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
234 |
final int MTYPE_ARG_APPENDED = 1; // argument count for appended mtype value |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
235 |
if (mtype.parameterSlotCount() <= MethodType.MAX_MH_ARITY - MTYPE_ARG_APPENDED) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
236 |
lform = invokeForm(mtype, false, MethodTypeForm.LF_EX_LINKER); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
237 |
appendixResult[0] = mtype; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
238 |
} else { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
239 |
lform = invokeForm(mtype, true, MethodTypeForm.LF_EX_LINKER); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
240 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
241 |
return lform.vmentry; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
242 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
243 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
244 |
static MemberName genericInvokerMethod(MethodType mtype, Object[] appendixResult) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
245 |
LambdaForm lform; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
246 |
final int MTYPE_ARG_APPENDED = 1; // argument count for appended mtype value |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
247 |
if (mtype.parameterSlotCount() <= MethodType.MAX_MH_ARITY - (MTYPE_ARG_APPENDED + GENERIC_INVOKER_SLOP)) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
248 |
lform = invokeForm(mtype, false, MethodTypeForm.LF_GEN_LINKER); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
249 |
appendixResult[0] = mtype; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
250 |
prepareForGenericCall(mtype); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
251 |
} else { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
252 |
lform = invokeForm(mtype, true, MethodTypeForm.LF_GEN_LINKER); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
253 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
254 |
return lform.vmentry; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
255 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
256 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
257 |
private static LambdaForm invokeForm(MethodType mtype, boolean customized, int which) { |
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++; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
289 |
final int LINKER_CALL = nameCursor++; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
290 |
MethodType invokerFormType = mtype.invokerType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
291 |
if (isLinker) { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
292 |
if (!customized) |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
293 |
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
|
294 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
295 |
invokerFormType = invokerFormType.invokerType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
296 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
297 |
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
|
298 |
assert(names.length == nameCursor) |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
299 |
: 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
|
300 |
if (MTYPE_ARG >= INARG_LIMIT) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
301 |
assert(names[MTYPE_ARG] == null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
302 |
names[MTYPE_ARG] = BoundMethodHandle.getSpeciesData("L").getterName(names[THIS_MH], 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
303 |
// 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
|
304 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
305 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
306 |
// Make the final call. If isGeneric, then prepend the result of type checking. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
307 |
MethodType outCallType; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
308 |
Object[] outArgs; |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
309 |
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
|
310 |
if (!isGeneric) { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
311 |
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
|
312 |
// 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
|
313 |
outArgs = Arrays.copyOfRange(names, CALL_MH, OUTARG_LIMIT, Object[].class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
314 |
outCallType = mtype; |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
315 |
} else if (customized) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
316 |
names[CHECK_TYPE] = new Name(NF_asType, names[CALL_MH], mtypeArg); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
317 |
// mh.invokeGeneric(a*):R => |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
318 |
// let mt=TYPEOF(a*:R), tmh=asType(mh, mt); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
319 |
// tmh.invokeBasic(a*) |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
320 |
outArgs = Arrays.copyOfRange(names, CALL_MH, OUTARG_LIMIT, Object[].class); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
321 |
outCallType = mtype; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
322 |
} else { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
323 |
names[CHECK_TYPE] = new Name(NF_checkGenericType, names[CALL_MH], mtypeArg); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
324 |
// mh.invokeGeneric(a*):R => |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
325 |
// let mt=TYPEOF(a*:R), gamh=checkGenericType(mh, mt); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
326 |
// gamh.invokeBasic(mt, mh, a*) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
327 |
final int PREPEND_GAMH = 0, PREPEND_MT = 1, PREPEND_COUNT = 2; |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
328 |
assert(GENERIC_INVOKER_SLOP == PREPEND_COUNT); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
329 |
outArgs = Arrays.copyOfRange(names, CALL_MH, 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
|
330 |
// prepend arguments: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
331 |
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
|
332 |
outArgs[PREPEND_GAMH] = names[CHECK_TYPE]; |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
333 |
outArgs[PREPEND_MT] = mtypeArg; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
334 |
outCallType = mtype.insertParameterTypes(0, MethodType.class, MethodHandle.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
335 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
336 |
names[LINKER_CALL] = new Name(invokeBasicMethod(outCallType), outArgs); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
337 |
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
|
338 |
if (isLinker) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
339 |
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
|
340 |
if (isCached) |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
341 |
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
|
342 |
return lform; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
343 |
} |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
344 |
private static final int GENERIC_INVOKER_SLOP = 2; // used elsewhere to avoid arity problems |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
345 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
346 |
/*non-public*/ static |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
347 |
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
|
348 |
// 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
|
349 |
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
|
350 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
351 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
352 |
/** 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
|
353 |
/*non-public*/ static |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
354 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
355 |
void checkExactType(Object mhObj, Object expectedObj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
356 |
MethodHandle mh = (MethodHandle) mhObj; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
357 |
MethodType expected = (MethodType) expectedObj; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
358 |
MethodType actual = mh.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
359 |
if (actual != expected) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
360 |
throw newWrongMethodTypeException(expected, actual); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
361 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
362 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
363 |
/** 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
|
364 |
/*non-public*/ static |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
365 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
366 |
Object checkGenericType(Object mhObj, Object expectedObj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
367 |
MethodHandle mh = (MethodHandle) mhObj; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
368 |
MethodType expected = (MethodType) expectedObj; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
369 |
//MethodType actual = mh.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
370 |
MethodHandle gamh = expected.form().genericInvoker; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
371 |
if (gamh != null) return gamh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
372 |
return prepareForGenericCall(expected); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
373 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
374 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
375 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
376 |
* Returns an adapter GA for invoking a MH with type adjustments. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
377 |
* The MethodType of the generic invocation site is prepended to MH |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
378 |
* and its arguments as follows: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
379 |
* {@code (R)MH.invoke(A*) => GA.invokeBasic(TYPEOF<A*,R>, MH, A*)} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
380 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
381 |
/*non-public*/ static MethodHandle prepareForGenericCall(MethodType mtype) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
382 |
// force any needed adapters to be preconstructed |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
383 |
MethodTypeForm form = mtype.form(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
384 |
MethodHandle gamh = form.genericInvoker; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
385 |
if (gamh != null) return gamh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
386 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
387 |
// Trigger adapter creation. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
388 |
gamh = InvokeGeneric.generalInvokerOf(form.erasedType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
389 |
form.genericInvoker = gamh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
390 |
return gamh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
391 |
} catch (Exception ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
392 |
throw newInternalError("Exception while resolving inexact invoke", ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
393 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
394 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
395 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
396 |
static MemberName linkToCallSiteMethod(MethodType mtype) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
397 |
LambdaForm lform = callSiteForm(mtype); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
398 |
return lform.vmentry; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
399 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
400 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
401 |
private static LambdaForm callSiteForm(MethodType mtype) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
402 |
mtype = mtype.basicType(); // normalize Z to I, String to Object, etc. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
403 |
LambdaForm lform = mtype.form().cachedLambdaForm(MethodTypeForm.LF_CS_LINKER); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
404 |
if (lform != null) return lform; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
405 |
// exactInvokerForm (Object,Object)Object |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
406 |
// 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
|
407 |
final int ARG_BASE = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
408 |
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
|
409 |
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
|
410 |
int nameCursor = OUTARG_LIMIT; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
411 |
final int CSITE_ARG = nameCursor++; // the last in-argument |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
412 |
final int CALL_MH = nameCursor++; // result of getTarget |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
413 |
final int LINKER_CALL = nameCursor++; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
414 |
MethodType invokerFormType = mtype.appendParameterTypes(CallSite.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
415 |
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
|
416 |
assert(names.length == nameCursor); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
417 |
assert(names[CSITE_ARG] != null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
418 |
names[CALL_MH] = new Name(NF_getCallSiteTarget, names[CSITE_ARG]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
419 |
// (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
|
420 |
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
|
421 |
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
|
422 |
// prepend MH argument: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
423 |
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
|
424 |
outArgs[PREPEND_MH] = names[CALL_MH]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
425 |
names[LINKER_CALL] = new Name(invokeBasicMethod(mtype), outArgs); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
426 |
lform = new LambdaForm("linkToCallSite", INARG_LIMIT, names); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
427 |
lform.compileToBytecode(); // JVM needs a real methodOop |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
428 |
lform = mtype.form().setCachedLambdaForm(MethodTypeForm.LF_CS_LINKER, lform); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
429 |
return lform; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
430 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
431 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
432 |
/** 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
|
433 |
/*non-public*/ static |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
434 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
435 |
Object getCallSiteTarget(Object site) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
436 |
return ((CallSite)site).getTarget(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
437 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
438 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
439 |
// Local constant functions: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
440 |
private static final NamedFunction NF_checkExactType; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
441 |
private static final NamedFunction NF_checkGenericType; |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
442 |
private static final NamedFunction NF_asType; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
443 |
private static final NamedFunction NF_getCallSiteTarget; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
444 |
static { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
445 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
446 |
NF_checkExactType = new NamedFunction(Invokers.class |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
447 |
.getDeclaredMethod("checkExactType", Object.class, Object.class)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
448 |
NF_checkGenericType = new NamedFunction(Invokers.class |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
449 |
.getDeclaredMethod("checkGenericType", Object.class, Object.class)); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
450 |
NF_asType = new NamedFunction(MethodHandle.class |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
451 |
.getDeclaredMethod("asType", MethodType.class)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
452 |
NF_getCallSiteTarget = new NamedFunction(Invokers.class |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
453 |
.getDeclaredMethod("getCallSiteTarget", Object.class)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
454 |
NF_checkExactType.resolve(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
455 |
NF_checkGenericType.resolve(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
456 |
NF_getCallSiteTarget.resolve(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
457 |
// bound |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
458 |
} catch (ReflectiveOperationException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
459 |
throw newInternalError(ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
460 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
461 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10419
diff
changeset
|
462 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
463 |
} |