author | jboes |
Thu, 21 Nov 2019 09:10:21 +0000 | |
changeset 59201 | b24f4caa1411 |
parent 50305 | 02934b0d661b |
permissions | -rw-r--r-- |
48826 | 1 |
/* |
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
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. |
|
24 |
*/ |
|
25 |
package java.lang.invoke; |
|
26 |
||
27 |
import sun.invoke.util.Wrapper; |
|
28 |
||
29 |
import java.lang.invoke.AbstractConstantGroup.BSCIWithCache; |
|
30 |
import java.util.Arrays; |
|
31 |
||
32 |
import static java.lang.invoke.BootstrapCallInfo.makeBootstrapCallInfo; |
|
33 |
import static java.lang.invoke.ConstantGroup.makeConstantGroup; |
|
34 |
import static java.lang.invoke.MethodHandleNatives.*; |
|
35 |
import static java.lang.invoke.MethodHandleStatics.TRACE_METHOD_LINKAGE; |
|
36 |
import static java.lang.invoke.MethodHandles.Lookup; |
|
37 |
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; |
|
38 |
||
39 |
final class BootstrapMethodInvoker { |
|
48930
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
40 |
|
48826 | 41 |
/** |
42 |
* Factored code for invoking a bootstrap method for invokedynamic |
|
43 |
* or a dynamic constant. |
|
44 |
* @param resultType the expected return type (either CallSite or a constant type) |
|
45 |
* @param bootstrapMethod the BSM to call |
|
46 |
* @param name the method name or constant name |
|
47 |
* @param type the method type or constant type |
|
48 |
* @param info information passed up from the JVM, to derive static arguments |
|
49 |
* @param callerClass the class containing the resolved method call or constant load |
|
50 |
* @param <T> the expected return type |
|
51 |
* @return the expected value, either a CallSite or a constant value |
|
52 |
*/ |
|
53 |
static <T> T invoke(Class<T> resultType, |
|
54 |
MethodHandle bootstrapMethod, |
|
55 |
// Callee information: |
|
56 |
String name, Object type, |
|
57 |
// Extra arguments for BSM, if any: |
|
58 |
Object info, |
|
59 |
// Caller information: |
|
60 |
Class<?> callerClass) { |
|
61 |
MethodHandles.Lookup caller = IMPL_LOOKUP.in(callerClass); |
|
62 |
Object result; |
|
63 |
boolean pullMode = isPullModeBSM(bootstrapMethod); // default value is false |
|
64 |
boolean vmIsPushing = !staticArgumentsPulled(info); // default value is true |
|
65 |
MethodHandle pullModeBSM; |
|
66 |
// match the VM with the BSM |
|
67 |
if (vmIsPushing) { |
|
68 |
// VM is pushing arguments at us |
|
69 |
pullModeBSM = null; |
|
70 |
if (pullMode) { |
|
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
71 |
bootstrapMethod = pushMePullYou(bootstrapMethod, true); |
48826 | 72 |
} |
73 |
} else { |
|
74 |
// VM wants us to pull args from it |
|
75 |
pullModeBSM = pullMode ? bootstrapMethod : |
|
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
76 |
pushMePullYou(bootstrapMethod, false); |
48826 | 77 |
bootstrapMethod = null; |
78 |
} |
|
79 |
try { |
|
48930
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
80 |
// As an optimization we special case various known BSMs, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
81 |
// such as LambdaMetafactory::metafactory and |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
82 |
// StringConcatFactory::makeConcatWithConstants. |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
83 |
// |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
84 |
// By providing static type information or even invoking |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
85 |
// exactly, we avoid emitting code to perform runtime |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
86 |
// checking. |
48826 | 87 |
info = maybeReBox(info); |
88 |
if (info == null) { |
|
89 |
// VM is allowed to pass up a null meaning no BSM args |
|
48930
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
90 |
result = invoke(bootstrapMethod, caller, name, type); |
48826 | 91 |
} |
92 |
else if (!info.getClass().isArray()) { |
|
93 |
// VM is allowed to pass up a single BSM arg directly |
|
48930
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
94 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
95 |
// Call to StringConcatFactory::makeConcatWithConstants |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
96 |
// with empty constant arguments? |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
97 |
if (isStringConcatFactoryBSM(bootstrapMethod.type())) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
98 |
result = (CallSite)bootstrapMethod |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
99 |
.invokeExact(caller, name, (MethodType)type, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
100 |
(String)info, new Object[0]); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
101 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
102 |
result = invoke(bootstrapMethod, caller, name, type, info); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
103 |
} |
48826 | 104 |
} |
105 |
else if (info.getClass() == int[].class) { |
|
106 |
// VM is allowed to pass up a pair {argc, index} |
|
107 |
// referring to 'argc' BSM args at some place 'index' |
|
108 |
// in the guts of the VM (associated with callerClass). |
|
109 |
// The format of this index pair is private to the |
|
110 |
// handshake between the VM and this class only. |
|
111 |
// This supports "pulling" of arguments. |
|
112 |
// The VM is allowed to do this for any reason. |
|
113 |
// The code in this method makes up for any mismatches. |
|
114 |
BootstrapCallInfo<Object> bsci |
|
115 |
= new VM_BSCI<>(bootstrapMethod, name, type, caller, (int[])info); |
|
116 |
// Pull-mode API is (Lookup, BootstrapCallInfo) -> Object |
|
117 |
result = pullModeBSM.invoke(caller, bsci); |
|
118 |
} |
|
119 |
else { |
|
120 |
// VM is allowed to pass up a full array of resolved BSM args |
|
121 |
Object[] argv = (Object[]) info; |
|
122 |
maybeReBoxElements(argv); |
|
48930
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
123 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
124 |
MethodType bsmType = bootstrapMethod.type(); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
125 |
if (isLambdaMetafactoryIndyBSM(bsmType) && argv.length == 3) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
126 |
result = (CallSite)bootstrapMethod |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
127 |
.invokeExact(caller, name, (MethodType)type, (MethodType)argv[0], |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
128 |
(MethodHandle)argv[1], (MethodType)argv[2]); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
129 |
} else if (isLambdaMetafactoryCondyBSM(bsmType) && argv.length == 3) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
130 |
result = bootstrapMethod |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
131 |
.invokeExact(caller, name, (Class<?>)type, (MethodType)argv[0], |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
132 |
(MethodHandle)argv[1], (MethodType)argv[2]); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
133 |
} else if (isStringConcatFactoryBSM(bsmType) && argv.length >= 1) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
134 |
String recipe = (String)argv[0]; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
135 |
Object[] shiftedArgs = Arrays.copyOfRange(argv, 1, argv.length); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
136 |
result = (CallSite)bootstrapMethod.invokeExact(caller, name, (MethodType)type, recipe, shiftedArgs); |
50305
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
137 |
} else if (isLambdaMetafactoryAltMetafactoryBSM(bsmType)) { |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
138 |
result = (CallSite)bootstrapMethod.invokeExact(caller, name, (MethodType)type, argv); |
48930
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
139 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
140 |
switch (argv.length) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
141 |
case 0: |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
142 |
result = invoke(bootstrapMethod, caller, name, type); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
143 |
break; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
144 |
case 1: |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
145 |
result = invoke(bootstrapMethod, caller, name, type, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
146 |
argv[0]); |
48826 | 147 |
break; |
48930
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
148 |
case 2: |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
149 |
result = invoke(bootstrapMethod, caller, name, type, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
150 |
argv[0], argv[1]); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
151 |
break; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
152 |
case 3: |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
153 |
result = invoke(bootstrapMethod, caller, name, type, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
154 |
argv[0], argv[1], argv[2]); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
155 |
break; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
156 |
case 4: |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
157 |
result = invoke(bootstrapMethod, caller, name, type, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
158 |
argv[0], argv[1], argv[2], argv[3]); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
159 |
break; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
160 |
case 5: |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
161 |
result = invoke(bootstrapMethod, caller, name, type, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
162 |
argv[0], argv[1], argv[2], argv[3], argv[4]); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
163 |
break; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
164 |
case 6: |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
165 |
result = invoke(bootstrapMethod, caller, name, type, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
166 |
argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
167 |
break; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
168 |
default: |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
169 |
result = invokeWithManyArguments(bootstrapMethod, caller, name, type, argv); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
170 |
} |
48826 | 171 |
} |
172 |
} |
|
173 |
if (resultType.isPrimitive()) { |
|
174 |
// Non-reference conversions are more than just plain casts. |
|
175 |
// By pushing the value through a funnel of the form (T x)->x, |
|
176 |
// the boxed result can be widened as needed. See MH::asType. |
|
177 |
MethodHandle funnel = MethodHandles.identity(resultType); |
|
178 |
result = funnel.invoke(result); |
|
179 |
// Now it is the wrapper type for resultType. |
|
180 |
resultType = Wrapper.asWrapperType(resultType); |
|
181 |
} |
|
182 |
return resultType.cast(result); |
|
183 |
} |
|
184 |
catch (Error e) { |
|
185 |
// Pass through an Error, including BootstrapMethodError, any other |
|
186 |
// form of linkage error, such as IllegalAccessError if the bootstrap |
|
187 |
// method is inaccessible, or say ThreadDeath/OutOfMemoryError |
|
188 |
// See the "Linking Exceptions" section for the invokedynamic |
|
189 |
// instruction in JVMS 6.5. |
|
190 |
throw e; |
|
191 |
} |
|
192 |
catch (Throwable ex) { |
|
193 |
// Wrap anything else in BootstrapMethodError |
|
194 |
throw new BootstrapMethodError("bootstrap method initialization exception", ex); |
|
195 |
} |
|
196 |
} |
|
197 |
||
48930
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
198 |
// If we don't provide static type information for type, we'll generate runtime |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
199 |
// checks. Let's try not to... |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
200 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
201 |
private static Object invoke(MethodHandle bootstrapMethod, Lookup caller, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
202 |
String name, Object type) throws Throwable { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
203 |
if (type instanceof Class) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
204 |
return bootstrapMethod.invoke(caller, name, (Class<?>)type); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
205 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
206 |
return bootstrapMethod.invoke(caller, name, (MethodType)type); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
207 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
208 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
209 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
210 |
private static Object invoke(MethodHandle bootstrapMethod, Lookup caller, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
211 |
String name, Object type, Object arg0) throws Throwable { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
212 |
if (type instanceof Class) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
213 |
return bootstrapMethod.invoke(caller, name, (Class<?>)type, arg0); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
214 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
215 |
return bootstrapMethod.invoke(caller, name, (MethodType)type, arg0); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
216 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
217 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
218 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
219 |
private static Object invoke(MethodHandle bootstrapMethod, Lookup caller, String name, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
220 |
Object type, Object arg0, Object arg1) throws Throwable { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
221 |
if (type instanceof Class) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
222 |
return bootstrapMethod.invoke(caller, name, (Class<?>)type, arg0, arg1); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
223 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
224 |
return bootstrapMethod.invoke(caller, name, (MethodType)type, arg0, arg1); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
225 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
226 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
227 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
228 |
private static Object invoke(MethodHandle bootstrapMethod, Lookup caller, String name, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
229 |
Object type, Object arg0, Object arg1, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
230 |
Object arg2) throws Throwable { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
231 |
if (type instanceof Class) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
232 |
return bootstrapMethod.invoke(caller, name, (Class<?>)type, arg0, arg1, arg2); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
233 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
234 |
return bootstrapMethod.invoke(caller, name, (MethodType)type, arg0, arg1, arg2); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
235 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
236 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
237 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
238 |
private static Object invoke(MethodHandle bootstrapMethod, Lookup caller, String name, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
239 |
Object type, Object arg0, Object arg1, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
240 |
Object arg2, Object arg3) throws Throwable { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
241 |
if (type instanceof Class) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
242 |
return bootstrapMethod.invoke(caller, name, (Class<?>)type, arg0, arg1, arg2, arg3); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
243 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
244 |
return bootstrapMethod.invoke(caller, name, (MethodType)type, arg0, arg1, arg2, arg3); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
245 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
246 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
247 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
248 |
private static Object invoke(MethodHandle bootstrapMethod, Lookup caller, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
249 |
String name, Object type, Object arg0, Object arg1, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
250 |
Object arg2, Object arg3, Object arg4) throws Throwable { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
251 |
if (type instanceof Class) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
252 |
return bootstrapMethod.invoke(caller, name, (Class<?>)type, arg0, arg1, arg2, arg3, arg4); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
253 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
254 |
return bootstrapMethod.invoke(caller, name, (MethodType)type, arg0, arg1, arg2, arg3, arg4); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
255 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
256 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
257 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
258 |
private static Object invoke(MethodHandle bootstrapMethod, Lookup caller, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
259 |
String name, Object type, Object arg0, Object arg1, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
260 |
Object arg2, Object arg3, Object arg4, Object arg5) throws Throwable { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
261 |
if (type instanceof Class) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
262 |
return bootstrapMethod.invoke(caller, name, (Class<?>)type, arg0, arg1, arg2, arg3, arg4, arg5); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
263 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
264 |
return bootstrapMethod.invoke(caller, name, (MethodType)type, arg0, arg1, arg2, arg3, arg4, arg5); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
265 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
266 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
267 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
268 |
private static Object invokeWithManyArguments(MethodHandle bootstrapMethod, Lookup caller, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
269 |
String name, Object type, Object[] argv) throws Throwable { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
270 |
final int NON_SPREAD_ARG_COUNT = 3; // (caller, name, type) |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
271 |
final int MAX_SAFE_SIZE = MethodType.MAX_MH_ARITY / 2 - NON_SPREAD_ARG_COUNT; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
272 |
if (argv.length >= MAX_SAFE_SIZE) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
273 |
// to be on the safe side, use invokeWithArguments which handles jumbo lists |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
274 |
Object[] newargv = new Object[NON_SPREAD_ARG_COUNT + argv.length]; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
275 |
newargv[0] = caller; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
276 |
newargv[1] = name; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
277 |
newargv[2] = type; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
278 |
System.arraycopy(argv, 0, newargv, NON_SPREAD_ARG_COUNT, argv.length); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
279 |
return bootstrapMethod.invokeWithArguments(newargv); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
280 |
} else { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
281 |
MethodType invocationType = MethodType.genericMethodType(NON_SPREAD_ARG_COUNT + argv.length); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
282 |
MethodHandle typedBSM = bootstrapMethod.asType(invocationType); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
283 |
MethodHandle spreader = invocationType.invokers().spreadInvoker(NON_SPREAD_ARG_COUNT); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
284 |
return spreader.invokeExact(typedBSM, (Object) caller, (Object) name, type, argv); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
285 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
286 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
287 |
|
48921
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
288 |
private static final MethodType LMF_INDY_MT = MethodType.methodType(CallSite.class, |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
289 |
Lookup.class, String.class, MethodType.class, MethodType.class, MethodHandle.class, MethodType.class); |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
290 |
|
50305
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
291 |
private static final MethodType LMF_ALT_MT = MethodType.methodType(CallSite.class, |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
292 |
Lookup.class, String.class, MethodType.class, Object[].class); |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
293 |
|
48921
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
294 |
private static final MethodType LMF_CONDY_MT = MethodType.methodType(Object.class, |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
295 |
Lookup.class, String.class, Class.class, MethodType.class, MethodHandle.class, MethodType.class); |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
296 |
|
48930
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
297 |
private static final MethodType SCF_MT = MethodType.methodType(CallSite.class, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
298 |
Lookup.class, String.class, MethodType.class, String.class, Object[].class); |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
299 |
|
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
300 |
/** |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
301 |
* @return true iff the BSM method type exactly matches |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
302 |
* {@see java.lang.invoke.StringConcatFactory#makeConcatWithConstants(MethodHandles.Lookup, |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
303 |
* String,MethodType,String,Object...))} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
304 |
*/ |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
305 |
private static boolean isStringConcatFactoryBSM(MethodType bsmType) { |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
306 |
return bsmType == SCF_MT; |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
307 |
} |
b1a5b4ad7427
8198523: Refactor BootstrapMethodInvoker to further avoid runtime type checks
redestad
parents:
48921
diff
changeset
|
308 |
|
48921
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
309 |
/** |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
310 |
* @return true iff the BSM method type exactly matches |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
311 |
* {@see java.lang.invoke.LambdaMetafactory#metafactory( |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
312 |
* MethodHandles.Lookup,String,Class,MethodType,MethodHandle,MethodType)} |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
313 |
*/ |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
314 |
private static boolean isLambdaMetafactoryCondyBSM(MethodType bsmType) { |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
315 |
return bsmType == LMF_CONDY_MT; |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
316 |
} |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
317 |
|
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
318 |
/** |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
319 |
* @return true iff the BSM method type exactly matches |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
320 |
* {@see java.lang.invoke.LambdaMetafactory#metafactory( |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
321 |
* MethodHandles.Lookup,String,MethodType,MethodType,MethodHandle,MethodType)} |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
322 |
*/ |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
323 |
private static boolean isLambdaMetafactoryIndyBSM(MethodType bsmType) { |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
324 |
return bsmType == LMF_INDY_MT; |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
325 |
} |
576e024f10b6
8198418: Invoke LambdaMetafactory::metafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48895
diff
changeset
|
326 |
|
50305
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
327 |
/** |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
328 |
* @return true iff the BSM method type exactly matches |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
329 |
* {@see java.lang.invoke.LambdaMetafactory#altMetafactory( |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
330 |
* MethodHandles.Lookup,String,MethodType,Object[])} |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
331 |
*/ |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
332 |
private static boolean isLambdaMetafactoryAltMetafactoryBSM(MethodType bsmType) { |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
333 |
return bsmType == LMF_ALT_MT; |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
334 |
} |
02934b0d661b
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker
redestad
parents:
48930
diff
changeset
|
335 |
|
48826 | 336 |
/** The JVM produces java.lang.Integer values to box |
337 |
* CONSTANT_Integer boxes but does not intern them. |
|
338 |
* Let's intern them. This is slightly wrong for |
|
339 |
* a {@code CONSTANT_Dynamic} which produces an |
|
340 |
* un-interned integer (e.g., {@code new Integer(0)}). |
|
341 |
*/ |
|
342 |
private static Object maybeReBox(Object x) { |
|
343 |
if (x instanceof Integer) { |
|
344 |
int xi = (int) x; |
|
345 |
if (xi == (byte) xi) |
|
346 |
x = xi; // must rebox; see JLS 5.1.7 |
|
347 |
} |
|
348 |
return x; |
|
349 |
} |
|
350 |
||
351 |
private static void maybeReBoxElements(Object[] xa) { |
|
352 |
for (int i = 0; i < xa.length; i++) { |
|
353 |
xa[i] = maybeReBox(xa[i]); |
|
354 |
} |
|
355 |
} |
|
356 |
||
357 |
/** Canonical VM-aware implementation of BootstrapCallInfo. |
|
358 |
* Knows how to dig into the JVM for lazily resolved (pull-mode) constants. |
|
359 |
*/ |
|
360 |
private static final class VM_BSCI<T> extends BSCIWithCache<T> { |
|
361 |
private final int[] indexInfo; |
|
362 |
private final Class<?> caller; // for index resolution only |
|
363 |
||
364 |
VM_BSCI(MethodHandle bsm, String name, T type, |
|
365 |
Lookup lookup, int[] indexInfo) { |
|
366 |
super(bsm, name, type, indexInfo[0]); |
|
367 |
if (!lookup.hasPrivateAccess()) //D.I.D. |
|
368 |
throw new AssertionError("bad Lookup object"); |
|
369 |
this.caller = lookup.lookupClass(); |
|
370 |
this.indexInfo = indexInfo; |
|
371 |
// scoop up all the easy stuff right away: |
|
372 |
prefetchIntoCache(0, size()); |
|
373 |
} |
|
374 |
||
375 |
@Override Object fillCache(int i) { |
|
376 |
Object[] buf = { null }; |
|
377 |
copyConstants(i, i+1, buf, 0); |
|
378 |
Object res = wrapNull(buf[0]); |
|
379 |
cache[i] = res; |
|
380 |
int next = i + 1; |
|
381 |
if (next < cache.length && cache[next] == null) |
|
382 |
maybePrefetchIntoCache(next, false); // try to prefetch |
|
383 |
return res; |
|
384 |
} |
|
385 |
||
386 |
@Override public int copyConstants(int start, int end, |
|
387 |
Object[] buf, int pos) { |
|
388 |
int i = start, bufi = pos; |
|
389 |
while (i < end) { |
|
390 |
Object x = cache[i]; |
|
391 |
if (x == null) break; |
|
392 |
buf[bufi++] = unwrapNull(x); |
|
393 |
i++; |
|
394 |
} |
|
395 |
// give up at first null and grab the rest in one big block |
|
396 |
if (i >= end) return i; |
|
397 |
Object[] temp = new Object[end - i]; |
|
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
398 |
if (TRACE_METHOD_LINKAGE) { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
399 |
System.out.println("resolving more BSM arguments: " + |
48826 | 400 |
Arrays.asList(caller.getSimpleName(), Arrays.toString(indexInfo), i, end)); |
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
401 |
} |
48826 | 402 |
copyOutBootstrapArguments(caller, indexInfo, |
403 |
i, end, temp, 0, |
|
404 |
true, null); |
|
405 |
for (Object x : temp) { |
|
406 |
x = maybeReBox(x); |
|
407 |
buf[bufi++] = x; |
|
408 |
cache[i++] = wrapNull(x); |
|
409 |
} |
|
410 |
if (end < cache.length && cache[end] == null) |
|
411 |
maybePrefetchIntoCache(end, true); // try to prefetch |
|
412 |
return i; |
|
413 |
} |
|
414 |
||
415 |
private static final int MIN_PF = 4; |
|
416 |
private void maybePrefetchIntoCache(int i, boolean bulk) { |
|
417 |
int len = cache.length; |
|
418 |
assert(0 <= i && i <= len); |
|
419 |
int pfLimit = i; |
|
420 |
if (bulk) pfLimit += i; // exponential prefetch expansion |
|
421 |
// try to prefetch at least MIN_PF elements |
|
422 |
if (pfLimit < i + MIN_PF) pfLimit = i + MIN_PF; |
|
423 |
if (pfLimit > len || pfLimit < 0) pfLimit = len; |
|
424 |
// stop prefetching where cache is more full than empty |
|
425 |
int empty = 0, nonEmpty = 0, lastEmpty = i; |
|
426 |
for (int j = i; j < pfLimit; j++) { |
|
427 |
if (cache[j] == null) { |
|
428 |
empty++; |
|
429 |
lastEmpty = j; |
|
430 |
} else { |
|
431 |
nonEmpty++; |
|
432 |
if (nonEmpty > empty) { |
|
433 |
pfLimit = lastEmpty + 1; |
|
434 |
break; |
|
435 |
} |
|
436 |
if (pfLimit < len) pfLimit++; |
|
437 |
} |
|
438 |
} |
|
439 |
if (bulk && empty < MIN_PF && pfLimit < len) |
|
440 |
return; // not worth the effort |
|
441 |
prefetchIntoCache(i, pfLimit); |
|
442 |
} |
|
443 |
||
444 |
private void prefetchIntoCache(int i, int pfLimit) { |
|
445 |
if (pfLimit <= i) return; // corner case |
|
446 |
Object[] temp = new Object[pfLimit - i]; |
|
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
447 |
if (TRACE_METHOD_LINKAGE) { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
448 |
System.out.println("prefetching BSM arguments: " + |
48826 | 449 |
Arrays.asList(caller.getSimpleName(), Arrays.toString(indexInfo), i, pfLimit)); |
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
450 |
} |
48826 | 451 |
copyOutBootstrapArguments(caller, indexInfo, |
452 |
i, pfLimit, temp, 0, |
|
453 |
false, NOT_PRESENT); |
|
454 |
for (Object x : temp) { |
|
455 |
if (x != NOT_PRESENT && cache[i] == null) { |
|
456 |
cache[i] = wrapNull(maybeReBox(x)); |
|
457 |
} |
|
458 |
i++; |
|
459 |
} |
|
460 |
} |
|
461 |
} |
|
462 |
||
59201
b24f4caa1411
8234335: Remove line break in class declaration in java.base
jboes
parents:
50305
diff
changeset
|
463 |
/*non-public*/ |
b24f4caa1411
8234335: Remove line break in class declaration in java.base
jboes
parents:
50305
diff
changeset
|
464 |
static final class PushAdapter { |
48826 | 465 |
// skeleton for push-mode BSM which wraps a pull-mode BSM: |
466 |
static Object pushToBootstrapMethod(MethodHandle pullModeBSM, |
|
467 |
MethodHandles.Lookup lookup, String name, Object type, |
|
468 |
Object... arguments) throws Throwable { |
|
469 |
ConstantGroup cons = makeConstantGroup(Arrays.asList(arguments)); |
|
470 |
BootstrapCallInfo<?> bsci = makeBootstrapCallInfo(pullModeBSM, name, type, cons); |
|
471 |
if (TRACE_METHOD_LINKAGE) |
|
472 |
System.out.println("pull-mode BSM gets pushed arguments from fake BSCI"); |
|
473 |
return pullModeBSM.invoke(lookup, bsci); |
|
474 |
} |
|
475 |
||
476 |
static final MethodHandle MH_pushToBootstrapMethod; |
|
477 |
static { |
|
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
478 |
final Class<?> THIS_CLASS = PushAdapter.class; |
48826 | 479 |
try { |
480 |
MH_pushToBootstrapMethod = IMPL_LOOKUP |
|
481 |
.findStatic(THIS_CLASS, "pushToBootstrapMethod", |
|
482 |
MethodType.methodType(Object.class, MethodHandle.class, |
|
483 |
Lookup.class, String.class, Object.class, Object[].class)); |
|
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
484 |
} catch (Throwable ex) { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
485 |
throw new InternalError(ex); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
486 |
} |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
487 |
} |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
488 |
} |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
489 |
|
59201
b24f4caa1411
8234335: Remove line break in class declaration in java.base
jboes
parents:
50305
diff
changeset
|
490 |
/*non-public*/ |
b24f4caa1411
8234335: Remove line break in class declaration in java.base
jboes
parents:
50305
diff
changeset
|
491 |
static final class PullAdapter { |
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
492 |
// skeleton for pull-mode BSM which wraps a push-mode BSM: |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
493 |
static Object pullFromBootstrapMethod(MethodHandle pushModeBSM, |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
494 |
MethodHandles.Lookup lookup, |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
495 |
BootstrapCallInfo<?> bsci) |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
496 |
throws Throwable { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
497 |
int argc = bsci.size(); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
498 |
switch (argc) { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
499 |
case 0: |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
500 |
return pushModeBSM.invoke(lookup, bsci.invocationName(), bsci.invocationType()); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
501 |
case 1: |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
502 |
return pushModeBSM.invoke(lookup, bsci.invocationName(), bsci.invocationType(), |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
503 |
bsci.get(0)); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
504 |
case 2: |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
505 |
return pushModeBSM.invoke(lookup, bsci.invocationName(), bsci.invocationType(), |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
506 |
bsci.get(0), bsci.get(1)); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
507 |
case 3: |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
508 |
return pushModeBSM.invoke(lookup, bsci.invocationName(), bsci.invocationType(), |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
509 |
bsci.get(0), bsci.get(1), bsci.get(2)); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
510 |
case 4: |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
511 |
return pushModeBSM.invoke(lookup, bsci.invocationName(), bsci.invocationType(), |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
512 |
bsci.get(0), bsci.get(1), bsci.get(2), bsci.get(3)); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
513 |
case 5: |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
514 |
return pushModeBSM.invoke(lookup, bsci.invocationName(), bsci.invocationType(), |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
515 |
bsci.get(0), bsci.get(1), bsci.get(2), bsci.get(3), bsci.get(4)); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
516 |
case 6: |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
517 |
return pushModeBSM.invoke(lookup, bsci.invocationName(), bsci.invocationType(), |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
518 |
bsci.get(0), bsci.get(1), bsci.get(2), bsci.get(3), bsci.get(4), bsci.get(5)); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
519 |
default: |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
520 |
final int NON_SPREAD_ARG_COUNT = 3; // (lookup, name, type) |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
521 |
final int MAX_SAFE_SIZE = MethodType.MAX_MH_ARITY / 2 - NON_SPREAD_ARG_COUNT; |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
522 |
if (argc >= MAX_SAFE_SIZE) { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
523 |
// to be on the safe side, use invokeWithArguments which handles jumbo lists |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
524 |
Object[] newargv = new Object[NON_SPREAD_ARG_COUNT + argc]; |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
525 |
newargv[0] = lookup; |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
526 |
newargv[1] = bsci.invocationName(); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
527 |
newargv[2] = bsci.invocationType(); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
528 |
bsci.copyConstants(0, argc, newargv, NON_SPREAD_ARG_COUNT); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
529 |
return pushModeBSM.invokeWithArguments(newargv); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
530 |
} |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
531 |
MethodType invocationType = MethodType.genericMethodType(NON_SPREAD_ARG_COUNT + argc); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
532 |
MethodHandle typedBSM = pushModeBSM.asType(invocationType); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
533 |
MethodHandle spreader = invocationType.invokers().spreadInvoker(NON_SPREAD_ARG_COUNT); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
534 |
Object[] argv = new Object[argc]; |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
535 |
bsci.copyConstants(0, argc, argv, 0); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
536 |
return spreader.invokeExact(typedBSM, (Object) lookup, (Object) bsci.invocationName(), bsci.invocationType(), argv); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
537 |
} |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
538 |
} |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
539 |
|
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
540 |
static final MethodHandle MH_pullFromBootstrapMethod; |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
541 |
|
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
542 |
static { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
543 |
final Class<?> THIS_CLASS = PullAdapter.class; |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
544 |
try { |
48826 | 545 |
MH_pullFromBootstrapMethod = IMPL_LOOKUP |
546 |
.findStatic(THIS_CLASS, "pullFromBootstrapMethod", |
|
547 |
MethodType.methodType(Object.class, MethodHandle.class, |
|
548 |
Lookup.class, BootstrapCallInfo.class)); |
|
549 |
} catch (Throwable ex) { |
|
550 |
throw new InternalError(ex); |
|
551 |
} |
|
552 |
} |
|
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
553 |
} |
48826 | 554 |
|
48895
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
555 |
/** Given a push-mode BSM (taking one argument) convert it to a |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
556 |
* pull-mode BSM (taking N pre-resolved arguments). |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
557 |
* This method is used when, in fact, the JVM is passing up |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
558 |
* pre-resolved arguments, but the BSM is expecting lazy stuff. |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
559 |
* Or, when goToPushMode is true, do the reverse transform. |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
560 |
* (The two transforms are exactly inverse.) |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
561 |
*/ |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
562 |
static MethodHandle pushMePullYou(MethodHandle bsm, boolean goToPushMode) { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
563 |
if (TRACE_METHOD_LINKAGE) { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
564 |
System.out.println("converting BSM of type " + bsm.type() + " to " |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
565 |
+ (goToPushMode ? "push mode" : "pull mode")); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
566 |
} |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
567 |
assert(isPullModeBSM(bsm) == goToPushMode); // there must be a change |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
568 |
if (goToPushMode) { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
569 |
return PushAdapter.MH_pushToBootstrapMethod.bindTo(bsm).withVarargs(true); |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
570 |
} else { |
7a1916641c0c
8195850: Improve startup of code to pull arguments from BootstrapMethodInvoker
redestad
parents:
48826
diff
changeset
|
571 |
return PullAdapter.MH_pullFromBootstrapMethod.bindTo(bsm).withVarargs(false); |
48826 | 572 |
} |
573 |
} |
|
574 |
} |