730 MethodType type = target.type();
731 MethodType ctype = catcher.type();
732 int nargs = type.parameterCount();
733 if (nargs < GuardWithCatch.INVOKES.length) {
734 MethodType gtype = type.generic();
735 MethodType gcatchType = gtype.insertParameterTypes(0, Throwable.class);
736 // Note: convertArguments(...2) avoids interface casts present in convertArguments(...0)
737 MethodHandle gtarget = makePairwiseConvert(target, gtype, 2);
738 MethodHandle gcatcher = makePairwiseConvert(catcher, gcatchType, 2);
739 GuardWithCatch gguard = new GuardWithCatch(gtarget, exType, gcatcher);
740 if (gtarget == null || gcatcher == null) throw new InternalError();
741 MethodHandle ginvoker = GuardWithCatch.INVOKES[nargs].bindReceiver(gguard);
742 return makePairwiseConvert(ginvoker, type, 2);
743 } else {
744 MethodHandle gtarget = makeSpreadArguments(target, Object[].class, 0, nargs);
745 catcher = catcher.asType(ctype.changeParameterType(0, Throwable.class));
746 MethodHandle gcatcher = makeSpreadArguments(catcher, Object[].class, 1, nargs);
747 GuardWithCatch gguard = new GuardWithCatch(gtarget, exType, gcatcher);
748 if (gtarget == null || gcatcher == null) throw new InternalError();
749 MethodHandle ginvoker = GuardWithCatch.VARARGS_INVOKE.bindReceiver(gguard);
750 return makeCollectArguments(ginvoker, ValueConversions.varargsArray(nargs), 0, false);
751 }
752 }
753
754 static
755 MethodHandle throwException(MethodType type) {
756 assert(Throwable.class.isAssignableFrom(type.parameterType(0)));
757 int arity = type.parameterCount();
758 if (arity > 1) {
759 return throwException(type.dropParameterTypes(1, arity)).dropArguments(type, 1, arity-1);
760 }
761 return makePairwiseConvert(throwException(), type, 2);
762 }
763
764 static MethodHandle THROW_EXCEPTION;
765 static MethodHandle throwException() {
766 MethodHandle mh = THROW_EXCEPTION;
767 if (mh != null) return mh;
768 try {
769 mh
770 = IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "throwException",
|
730 MethodType type = target.type();
731 MethodType ctype = catcher.type();
732 int nargs = type.parameterCount();
733 if (nargs < GuardWithCatch.INVOKES.length) {
734 MethodType gtype = type.generic();
735 MethodType gcatchType = gtype.insertParameterTypes(0, Throwable.class);
736 // Note: convertArguments(...2) avoids interface casts present in convertArguments(...0)
737 MethodHandle gtarget = makePairwiseConvert(target, gtype, 2);
738 MethodHandle gcatcher = makePairwiseConvert(catcher, gcatchType, 2);
739 GuardWithCatch gguard = new GuardWithCatch(gtarget, exType, gcatcher);
740 if (gtarget == null || gcatcher == null) throw new InternalError();
741 MethodHandle ginvoker = GuardWithCatch.INVOKES[nargs].bindReceiver(gguard);
742 return makePairwiseConvert(ginvoker, type, 2);
743 } else {
744 MethodHandle gtarget = makeSpreadArguments(target, Object[].class, 0, nargs);
745 catcher = catcher.asType(ctype.changeParameterType(0, Throwable.class));
746 MethodHandle gcatcher = makeSpreadArguments(catcher, Object[].class, 1, nargs);
747 GuardWithCatch gguard = new GuardWithCatch(gtarget, exType, gcatcher);
748 if (gtarget == null || gcatcher == null) throw new InternalError();
749 MethodHandle ginvoker = GuardWithCatch.VARARGS_INVOKE.bindReceiver(gguard);
750 MethodHandle gcollect = makeCollectArguments(ginvoker, ValueConversions.varargsArray(nargs), 0, false);
751 return makePairwiseConvert(gcollect, type, 2);
752 }
753 }
754
755 static
756 MethodHandle throwException(MethodType type) {
757 assert(Throwable.class.isAssignableFrom(type.parameterType(0)));
758 int arity = type.parameterCount();
759 if (arity > 1) {
760 return throwException(type.dropParameterTypes(1, arity)).dropArguments(type, 1, arity-1);
761 }
762 return makePairwiseConvert(throwException(), type, 2);
763 }
764
765 static MethodHandle THROW_EXCEPTION;
766 static MethodHandle throwException() {
767 MethodHandle mh = THROW_EXCEPTION;
768 if (mh != null) return mh;
769 try {
770 mh
771 = IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "throwException",
|