1
25
26 package java.lang.invoke;
27
28 import jdk.internal.vm.annotation.DontInline;
29 import jdk.internal.vm.annotation.ForceInline;
30 import jdk.internal.vm.annotation.Stable;
31
32 import java.lang.reflect.Array;
33 import java.util.Arrays;
34
35 import static java.lang.invoke.MethodHandleStatics.*;
36 import static java.lang.invoke.MethodHandleNatives.Constants.*;
37 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
38 import static java.lang.invoke.LambdaForm.*;
39 import static java.lang.invoke.LambdaForm.Kind.*;
40
41
45 class Invokers {
46
47 private final MethodType targetType;
48
49
50 private final @Stable MethodHandle[] invokers = new MethodHandle[INV_LIMIT];
51
52 static final int
53 INV_EXACT = 0,
54 INV_GENERIC = 1,
55 INV_BASIC = 2,
56 INV_LIMIT = 3;
57
58
61 Invokers(MethodType targetType) {
62 this.targetType = targetType;
63 }
64
65 MethodHandle exactInvoker() {
66 MethodHandle invoker = cachedInvoker(INV_EXACT);
67 if (invoker != null) return invoker;
68 invoker = makeExactOrGeneralInvoker(true);
69 return setCachedInvoker(INV_EXACT, invoker);
70 }
71
72 MethodHandle genericInvoker() {
73 MethodHandle invoker = cachedInvoker(INV_GENERIC);
74 if (invoker != null) return invoker;
75 invoker = makeExactOrGeneralInvoker(false);
76 return setCachedInvoker(INV_GENERIC, invoker);
77 }
78
79 MethodHandle basicInvoker() {
80 MethodHandle invoker = cachedInvoker(INV_BASIC);
81 if (invoker != null) return invoker;
82 MethodType basicType = targetType.basicType();
83 if (basicType != targetType) {
84
85 return setCachedInvoker(INV_BASIC, basicType.invokers().basicInvoker());
86 }
87 invoker = basicType.form().cachedMethodHandle(MethodTypeForm.MH_BASIC_INV);
88 if (invoker == null) {
89 MemberName method = invokeBasicMethod(basicType);
90 invoker = DirectMethodHandle.make(method);
91 assert(checkInvoker(invoker));
92 invoker = basicType.form().setCachedMethodHandle(MethodTypeForm.MH_BASIC_INV, invoker);
93 }
94 return setCachedInvoker(INV_BASIC, invoker);
95 }
96
97 MethodHandle varHandleMethodInvoker(VarHandle.AccessMode ak) {
98
99 return makeVarHandleMethodInvoker(ak, false);
100 }
101
102 MethodHandle varHandleMethodExactInvoker(VarHandle.AccessMode ak) {
103
104 return makeVarHandleMethodInvoker(ak, true);
105 }
106
107 private MethodHandle cachedInvoker(int idx) {
108 return invokers[idx];
109 }
110
111 private synchronized MethodHandle setCachedInvoker(int idx, final MethodHandle invoker) {
112
113 MethodHandle prev = invokers[idx];
114 if (prev != null) return prev;
115 return invokers[idx] = invoker;
116 }
117
118 private MethodHandle makeExactOrGeneralInvoker(boolean isExact) {
119 MethodType mtype = targetType;
120 MethodType invokerType = mtype.invokerType();
121 int which = (isExact ? MethodTypeForm.LF_EX_INVOKER : MethodTypeForm.LF_GEN_INVOKER);
122 LambdaForm lform = invokeHandleForm(mtype, false, which);
123 MethodHandle invoker = BoundMethodHandle.bindSingle(invokerType, lform, mtype);
124 String whichName = (isExact ? "invokeExact" : "invoke");
125 invoker = invoker.withInternalMemberName(MemberName.makeMethodHandleInvoke(whichName, mtype), false);
126 assert(checkInvoker(invoker));
127 maybeCompileToBytecode(invoker);
128 return invoker;
129 }
130
131 private MethodHandle makeVarHandleMethodInvoker(VarHandle.AccessMode ak, boolean isExact) {
132 MethodType mtype = targetType;
133 MethodType invokerType = mtype.insertParameterTypes(0, VarHandle.class);
134
135 LambdaForm lform = varHandleMethodInvokerHandleForm(ak, mtype, isExact);
136 VarHandle.AccessDescriptor ad = new VarHandle.AccessDescriptor(mtype, ak.at.ordinal(), ak.ordinal());
137 MethodHandle invoker = BoundMethodHandle.bindSingle(invokerType, lform, ad);
138
139 invoker = invoker.withInternalMemberName(MemberName.makeVarHandleMethodInvoke(ak.methodName(), mtype), false);
140 assert(checkVarHandleInvoker(invoker));
141
142 maybeCompileToBytecode(invoker);
143 return invoker;
144 }
145
146
147 private void maybeCompileToBytecode(MethodHandle invoker) {
148 final int EAGER_COMPILE_ARITY_LIMIT = 10;
149 if (targetType == targetType.erase() &&
150 targetType.parameterCount() < EAGER_COMPILE_ARITY_LIMIT) {
151 invoker.form.compileToBytecode();
152 }
153 }
154
155
156 static MemberName invokeBasicMethod(MethodType basicType) {
157 assert(basicType == basicType.basicType());
158 try {
159
160 return IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, MethodHandle.class, "invokeBasic", basicType);
161 } catch (ReflectiveOperationException ex) {
162 throw newInternalError("JVM cannot find invoker for "+basicType, ex);
163 }
164 }
165
166 private boolean checkInvoker(MethodHandle invoker) {
167 assert(targetType.invokerType().equals(invoker.type()))
168 : java.util.Arrays.asList(targetType, targetType.invokerType(), invoker);
169 assert(invoker.internalMemberName() == null ||
170 invoker.internalMemberName().getMethodType().equals(targetType));
171 assert(!invoker.isVarargsCollector());
172 return true;
173 }
174
175 private boolean checkVarHandleInvoker(MethodHandle invoker) {
176 MethodType invokerType = targetType.insertParameterTypes(0, VarHandle.class);
177 assert(invokerType.equals(invoker.type()))
178 : java.util.Arrays.asList(targetType, invokerType, invoker);
179 assert(invoker.internalMemberName() == null ||
180 invoker.internalMemberName().getMethodType().equals(targetType));
181 assert(!invoker.isVarargsCollector());
182 return true;
183 }
184
185
193 MethodHandle spreadInvoker(int leadingArgCount) {
194 int spreadArgCount = targetType.parameterCount() - leadingArgCount;
195 MethodType postSpreadType = targetType;
196 Class<?> argArrayType = impliedRestargType(postSpreadType, leadingArgCount);
197 if (postSpreadType.parameterSlotCount() <= MethodType.MAX_MH_INVOKER_ARITY) {
198 return genericInvoker().asSpreader(argArrayType, spreadArgCount);
199 }
200
201
202
203 MethodType preSpreadType = postSpreadType
204 .replaceParameterTypes(leadingArgCount, postSpreadType.parameterCount(), argArrayType);
205 MethodHandle arrayInvoker = MethodHandles.invoker(preSpreadType);
206 MethodHandle makeSpreader = MethodHandles.insertArguments(Lazy.MH_asSpreader, 1, argArrayType, spreadArgCount);
207 return MethodHandles.filterArgument(arrayInvoker, 0, makeSpreader);
208 }
209
210 private static Class<?> impliedRestargType(MethodType restargType, int fromPos) {
211 if (restargType.isGeneric()) return Object[].class;
212 int maxPos = restargType.parameterCount();
213 if (fromPos >= maxPos) return Object[].class;
214 Class<?> argType = restargType.parameterType(fromPos);
215 for (int i = fromPos+1; i < maxPos; i++) {
216 if (argType != restargType.parameterType(i))
217 throw newIllegalArgumentException("need homogeneous rest arguments", restargType);
218 }
219 if (argType == Object.class) return Object[].class;
220 return Array.newInstance(argType, 0).getClass();
221 }
222
223 public String toString() {
224 return "Invokers"+targetType;
225 }
226
227 static MemberName methodHandleInvokeLinkerMethod(String name,
228 MethodType mtype,
229 Object[] appendixResult) {
230 int which;
231 switch (name) {
232 case "invokeExact": which = MethodTypeForm.LF_EX_LINKER; break;
233 case "invoke": which = MethodTypeForm.LF_GEN_LINKER; break;
234 default: throw new InternalError("not invoker: "+name);
235 }
236 LambdaForm lform;
237 if (mtype.parameterSlotCount() <= MethodType.MAX_MH_ARITY - MH_LINKER_ARG_APPENDED) {
238 lform = invokeHandleForm(mtype, false, which);
239 appendixResult[0] = mtype;
240 } else {
241 lform = invokeHandleForm(mtype, true, which);
242 }
243 return lform.vmentry;
244 }
245
246
247 private static final int MH_LINKER_ARG_APPENDED = 1;
248
249
258 static LambdaForm invokeHandleForm(MethodType mtype, boolean customized, int which) {
259 boolean isCached;
260 if (!customized) {
261 mtype = mtype.basicType();
262 isCached = true;
263 } else {
264 isCached = false;
265 }
266 boolean isLinker, isGeneric;
267 Kind kind;
268 switch (which) {
269 case MethodTypeForm.LF_EX_LINKER: isLinker = true; isGeneric = false; kind = EXACT_LINKER; break;
270 case MethodTypeForm.LF_EX_INVOKER: isLinker = false; isGeneric = false; kind = EXACT_INVOKER; break;
271 case MethodTypeForm.LF_GEN_LINKER: isLinker = true; isGeneric = true; kind = GENERIC_LINKER; break;
272 case MethodTypeForm.LF_GEN_INVOKER: isLinker = false; isGeneric = true; kind = GENERIC_INVOKER; break;
273 default: throw new InternalError();
274 }
275 LambdaForm lform;
276 if (isCached) {
277 lform = mtype.form().cachedLambdaForm(which);
278 if (lform != null) return lform;
279 }
280
281
282 final int THIS_MH = 0;
283 final int CALL_MH = THIS_MH + (isLinker ? 0 : 1);
284 final int ARG_BASE = CALL_MH + 1;
285 final int OUTARG_LIMIT = ARG_BASE + mtype.parameterCount();
286 final int INARG_LIMIT = OUTARG_LIMIT + (isLinker && !customized ? 1 : 0);
287 int nameCursor = OUTARG_LIMIT;
288 final int MTYPE_ARG = customized ? -1 : nameCursor++;
289 final int CHECK_TYPE = nameCursor++;
290 final int CHECK_CUSTOM = (CUSTOMIZE_THRESHOLD >= 0) ? nameCursor++ : -1;
291 final int LINKER_CALL = nameCursor++;
292 MethodType invokerFormType = mtype.invokerType();
293 if (isLinker) {
294 if (!customized)
295 invokerFormType = invokerFormType.appendParameterTypes(MemberName.class);
296 } else {
297 invokerFormType = invokerFormType.invokerType();
298 }
299 Name[] names = arguments(nameCursor - INARG_LIMIT, invokerFormType);
300 assert(names.length == nameCursor)
301 : Arrays.asList(mtype, customized, which, nameCursor, names.length);
302 if (MTYPE_ARG >= INARG_LIMIT) {
303 assert(names[MTYPE_ARG] == null);
304 BoundMethodHandle.SpeciesData speciesData = BoundMethodHandle.speciesData_L();
305 names[THIS_MH] = names[THIS_MH].withConstraint(speciesData);
306 NamedFunction getter = speciesData.getterFunction(0);
307 names[MTYPE_ARG] = new Name(getter, names[THIS_MH]);
308
309 }
310
311
312 MethodType outCallType = mtype.basicType();
313 Object[] outArgs = Arrays.copyOfRange(names, CALL_MH, OUTARG_LIMIT, Object[].class);
314 Object mtypeArg = (customized ? mtype : names[MTYPE_ARG]);
315 if (!isGeneric) {
316 names[CHECK_TYPE] = new Name(getFunction(NF_checkExactType), names[CALL_MH], mtypeArg);
317
318 } else {
319 names[CHECK_TYPE] = new Name(getFunction(NF_checkGenericType), names[CALL_MH], mtypeArg);
320
321 outArgs[0] = names[CHECK_TYPE];
322 }
323 if (CHECK_CUSTOM != -1) {
324 names[CHECK_CUSTOM] = new Name(getFunction(NF_checkCustomized), outArgs[0]);
325 }
326 names[LINKER_CALL] = new Name(outCallType, outArgs);
327 if (customized) {
328 lform = new LambdaForm(INARG_LIMIT, names);
329 } else {
330 lform = new LambdaForm(INARG_LIMIT, names, kind);
331 }
332 if (isLinker)
333 lform.compileToBytecode();
334 if (isCached)
335 lform = mtype.form().setCachedLambdaForm(which, lform);
336 return lform;
337 }
338
339
340 static MemberName varHandleInvokeLinkerMethod(VarHandle.AccessMode ak, MethodType mtype) {
341 LambdaForm lform;
342 if (mtype.parameterSlotCount() <= MethodType.MAX_MH_ARITY - MH_LINKER_ARG_APPENDED) {
343 lform = varHandleMethodGenericLinkerHandleForm(ak, mtype);
344 } else {
345
346 throw newInternalError("Unsupported parameter slot count " + mtype.parameterSlotCount());
347 }
348 return lform.vmentry;
349 }
350
351 private static LambdaForm varHandleMethodGenericLinkerHandleForm(VarHandle.AccessMode ak,
352 MethodType mtype) {
353
354
355 final int THIS_VH = 0;
356 final int ARG_BASE = THIS_VH + 1;
357 final int ARG_LIMIT = ARG_BASE + mtype.parameterCount();
358 int nameCursor = ARG_LIMIT;
359 final int VAD_ARG = nameCursor++;
360 final int CHECK_TYPE = nameCursor++;
361 final int CHECK_CUSTOM = (CUSTOMIZE_THRESHOLD >= 0) ? nameCursor++ : -1;
362 final int LINKER_CALL = nameCursor++;
363
364 Name[] names = new Name[LINKER_CALL + 1];
365 names[THIS_VH] = argument(THIS_VH, BasicType.basicType(Object.class));
366 for (int i = 0; i < mtype.parameterCount(); i++) {
367 names[ARG_BASE + i] = argument(ARG_BASE + i, BasicType.basicType(mtype.parameterType(i)));
368 }
369 names[VAD_ARG] = new Name(ARG_LIMIT, BasicType.basicType(Object.class));
370
371 names[CHECK_TYPE] = new Name(getFunction(NF_checkVarHandleGenericType), names[THIS_VH], names[VAD_ARG]);
372
373 Object[] outArgs = new Object[ARG_LIMIT + 1];
374 outArgs[0] = names[CHECK_TYPE];
375 for (int i = 0; i < ARG_LIMIT; i++) {
376 outArgs[i + 1] = names[i];
377 }
378
379 if (CHECK_CUSTOM != -1) {
380 names[CHECK_CUSTOM] = new Name(getFunction(NF_checkCustomized), outArgs[0]);
381 }
382
383 MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
384 .basicType();
385 names[LINKER_CALL] = new Name(outCallType, outArgs);
386 LambdaForm lform = new LambdaForm(ARG_LIMIT + 1, names, VARHANDLE_LINKER);
387 if (LambdaForm.debugNames()) {
388 String name = ak.methodName() + ":VarHandle_invoke_MT_" +
389 shortenSignature(basicTypeSignature(mtype));
390 LambdaForm.associateWithDebugName(lform, name);
391 }
392 lform.compileToBytecode();
393 return lform;
394 }
395
396 private static LambdaForm varHandleMethodInvokerHandleForm(VarHandle.AccessMode ak,
397 MethodType mtype, boolean isExact) {
398
399
400 final int THIS_MH = 0;
401 final int CALL_VH = THIS_MH + 1;
402 final int ARG_BASE = CALL_VH + 1;
403 final int ARG_LIMIT = ARG_BASE + mtype.parameterCount();
404 int nameCursor = ARG_LIMIT;
405 final int VAD_ARG = nameCursor++;
406 final int CHECK_TYPE = nameCursor++;
407 final int LINKER_CALL = nameCursor++;
408
409 Name[] names = new Name[LINKER_CALL + 1];
410 names[THIS_MH] = argument(THIS_MH, BasicType.basicType(Object.class));
411 names[CALL_VH] = argument(CALL_VH, BasicType.basicType(Object.class));
412 for (int i = 0; i < mtype.parameterCount(); i++) {
413 names[ARG_BASE + i] = argument(ARG_BASE + i, BasicType.basicType(mtype.parameterType(i)));
414 }
415
416 BoundMethodHandle.SpeciesData speciesData = BoundMethodHandle.speciesData_L();
417 names[THIS_MH] = names[THIS_MH].withConstraint(speciesData);
418
419 NamedFunction getter = speciesData.getterFunction(0);
420 names[VAD_ARG] = new Name(getter, names[THIS_MH]);
421
422 if (isExact) {
423 names[CHECK_TYPE] = new Name(getFunction(NF_checkVarHandleExactType), names[CALL_VH], names[VAD_ARG]);
424 } else {
425 names[CHECK_TYPE] = new Name(getFunction(NF_checkVarHandleGenericType), names[CALL_VH], names[VAD_ARG]);
426 }
427 Object[] outArgs = new Object[ARG_LIMIT];
428 outArgs[0] = names[CHECK_TYPE];
429 for (int i = 1; i < ARG_LIMIT; i++) {
430 outArgs[i] = names[i];
431 }
432
433 MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
434 .basicType();
435 names[LINKER_CALL] = new Name(outCallType, outArgs);
436 Kind kind = isExact ? VARHANDLE_EXACT_INVOKER : VARHANDLE_INVOKER;
437 LambdaForm lform = new LambdaForm(ARG_LIMIT, names, kind);
438 if (LambdaForm.debugNames()) {
439 String name = ak.methodName() +
440 (isExact ? ":VarHandle_exactInvoker_" : ":VarHandle_invoker_") +
441 shortenSignature(basicTypeSignature(mtype));
442 LambdaForm.associateWithDebugName(lform, name);
443 }
444 lform.prepare();
445 return lform;
446 }
447
448 static
449 @ForceInline
450 MethodHandle checkVarHandleGenericType(VarHandle handle, VarHandle.AccessDescriptor ad) {
451
452
453 MethodHandle mh = handle.getMethodHandle(ad.mode);
454 if (mh.type() == ad.symbolicMethodTypeInvoker) {
455 return mh;
456 }
457 else {
458 return mh.asType(ad.symbolicMethodTypeInvoker);
459 }
460 }
461
462 static
463 @ForceInline
464 MethodHandle checkVarHandleExactType(VarHandle handle, VarHandle.AccessDescriptor ad) {
465 MethodHandle mh = handle.getMethodHandle(ad.mode);
466 MethodType mt = mh.type();
467 if (mt != ad.symbolicMethodTypeInvoker) {
468 throw newWrongMethodTypeException(mt, ad.symbolicMethodTypeInvoker);
469 }
470 return mh;
471 }
472
473 static
474 WrongMethodTypeException newWrongMethodTypeException(MethodType actual, MethodType expected) {
475
476 return new WrongMethodTypeException("expected "+expected+" but found "+actual);
477 }
478
479
480 static
481 @ForceInline
482 void checkExactType(MethodHandle mh, MethodType expected) {
483 MethodType actual = mh.type();
484 if (actual != expected)
485 throw newWrongMethodTypeException(expected, actual);
486 }
487
488
492 static
493 @ForceInline
494 MethodHandle checkGenericType(MethodHandle mh, MethodType expected) {
495 return mh.asType(expected);
496
513 }
514
515 static MemberName linkToCallSiteMethod(MethodType mtype) {
516 LambdaForm lform = callSiteForm(mtype, false);
517 return lform.vmentry;
518 }
519
520 static MemberName linkToTargetMethod(MethodType mtype) {
521 LambdaForm lform = callSiteForm(mtype, true);
522 return lform.vmentry;
523 }
524
525
526 static LambdaForm callSiteForm(MethodType mtype, boolean skipCallSite) {
527 mtype = mtype.basicType();
528 final int which = (skipCallSite ? MethodTypeForm.LF_MH_LINKER : MethodTypeForm.LF_CS_LINKER);
529 LambdaForm lform = mtype.form().cachedLambdaForm(which);
530 if (lform != null) return lform;
531
532
533 final int ARG_BASE = 0;
534 final int OUTARG_LIMIT = ARG_BASE + mtype.parameterCount();
535 final int INARG_LIMIT = OUTARG_LIMIT + 1;
536 int nameCursor = OUTARG_LIMIT;
537 final int APPENDIX_ARG = nameCursor++;
538 final int CSITE_ARG = skipCallSite ? -1 : APPENDIX_ARG;
539 final int CALL_MH = skipCallSite ? APPENDIX_ARG : nameCursor++;
540 final int LINKER_CALL = nameCursor++;
541 MethodType invokerFormType = mtype.appendParameterTypes(skipCallSite ? MethodHandle.class : CallSite.class);
542 Name[] names = arguments(nameCursor - INARG_LIMIT, invokerFormType);
543 assert(names.length == nameCursor);
544 assert(names[APPENDIX_ARG] != null);
545 if (!skipCallSite)
546 names[CALL_MH] = new Name(getFunction(NF_getCallSiteTarget), names[CSITE_ARG]);
547
548 final int PREPEND_MH = 0, PREPEND_COUNT = 1;
549 Object[] outArgs = Arrays.copyOfRange(names, ARG_BASE, OUTARG_LIMIT + PREPEND_COUNT, Object[].class);
550
551 System.arraycopy(outArgs, 0, outArgs, PREPEND_COUNT, outArgs.length - PREPEND_COUNT);
552 outArgs[PREPEND_MH] = names[CALL_MH];
553 names[LINKER_CALL] = new Name(mtype, outArgs);
554 lform = new LambdaForm(INARG_LIMIT, names,
555 (skipCallSite ? LINK_TO_TARGET_METHOD : LINK_TO_CALL_SITE));
556 lform.compileToBytecode();
557 lform = mtype.form().setCachedLambdaForm(which, lform);
558 return lform;
559 }
560
561
562 static
563 @ForceInline
564 MethodHandle getCallSiteTarget(CallSite site) {
565 return site.getTarget();
566 }
567
568 static
569 @ForceInline
570 void checkCustomized(MethodHandle mh) {
571 if (MethodHandleImpl.isCompileConstant(mh)) return;
572 if (mh.form.customized == null) {
573 maybeCustomize(mh);
574 }
575 }
576
577 static
578 @DontInline
579 void maybeCustomize(MethodHandle mh) {
580 byte count = mh.customizationCount;
581 if (count >= CUSTOMIZE_THRESHOLD) {
582 mh.customize();
583 } else {
584 mh.customizationCount = (byte)(count+1);
585 }
586 }
587
588
589 private static final byte NF_checkExactType = 0,
590 NF_checkGenericType = 1,
591 NF_getCallSiteTarget = 2,
592 NF_checkCustomized = 3,
593 NF_checkVarHandleGenericType = 4,
594 NF_checkVarHandleExactType = 5,
595 NF_LIMIT = 6;
596
597 private static final @Stable NamedFunction[] NFS = new NamedFunction[NF_LIMIT];
598
599 private static NamedFunction getFunction(byte func) {
600 NamedFunction nf = NFS[func];
601 if (nf != null) {
602 return nf;
603 }
604 NFS[func] = nf = createFunction(func);
605
606 assert(InvokerBytecodeGenerator.isStaticallyInvocable(nf));
607 return nf;
608 }
609
610 private static NamedFunction createFunction(byte func) {
611 try {
612 switch (func) {
613 case NF_checkExactType:
614 return getNamedFunction("checkExactType", MethodType.methodType(void.class, MethodHandle.class, MethodType.class));
615 case NF_checkGenericType:
616 return getNamedFunction("checkGenericType", MethodType.methodType(MethodHandle.class, MethodHandle.class, MethodType.class));
617 case NF_getCallSiteTarget:
618 return getNamedFunction("getCallSiteTarget", MethodType.methodType(MethodHandle.class, CallSite.class));
619 case NF_checkCustomized:
620 return getNamedFunction("checkCustomized", MethodType.methodType(void.class, MethodHandle.class));
621 case NF_checkVarHandleGenericType:
622 return getNamedFunction("checkVarHandleGenericType", MethodType.methodType(MethodHandle.class, VarHandle.class, VarHandle.AccessDescriptor.class));
623 case NF_checkVarHandleExactType:
624 return getNamedFunction("checkVarHandleExactType", MethodType.methodType(MethodHandle.class, VarHandle.class, VarHandle.AccessDescriptor.class));
625 default:
626 throw newInternalError("Unknown function: " + func);
627 }
628 } catch (ReflectiveOperationException ex) {
629 throw newInternalError(ex);
630 }
631 }
632
633 private static NamedFunction getNamedFunction(String name, MethodType type)
634 throws ReflectiveOperationException
635 {
636 MemberName member = new MemberName(Invokers.class, name, type, REF_invokeStatic);
637 return new NamedFunction(
638 MemberName.getFactory()
639 .resolveOrFail(REF_invokeStatic, member, Invokers.class, NoSuchMethodException.class));
640 }
641
642 private static class Lazy {
643 private static final MethodHandle MH_asSpreader;
644
645 static {
646 try {
647 MH_asSpreader = IMPL_LOOKUP.findVirtual(MethodHandle.class, "asSpreader",
648 MethodType.methodType(MethodHandle.class, Class.class, int.class));
649 } catch (ReflectiveOperationException ex) {
650 throw newInternalError(ex);
651 }
652 }
653 }
654
655 static {
656
657
658
659
660 UNSAFE.ensureClassInitialized(Holder.class);
661 }
662
663
664 final class Holder {}
665 }
666