825 return "arg" + types.charAt(index) + index; |
825 return "arg" + types.charAt(index) + index; |
826 } |
826 } |
827 |
827 |
828 private static String makeSignature(String types, boolean ctor) { |
828 private static String makeSignature(String types, boolean ctor) { |
829 StringBuilder buf = new StringBuilder(SIG_INCIPIT); |
829 StringBuilder buf = new StringBuilder(SIG_INCIPIT); |
830 for (char c : types.toCharArray()) { |
830 int len = types.length(); |
831 buf.append(typeSig(c)); |
831 for (int i = 0; i < len; i++) { |
|
832 buf.append(typeSig(types.charAt(i))); |
832 } |
833 } |
833 return buf.append(')').append(ctor ? "V" : BMH_SIG).toString(); |
834 return buf.append(')').append(ctor ? "V" : BMH_SIG).toString(); |
|
835 } |
|
836 |
|
837 private static MethodType makeConstructorType(String types) { |
|
838 int length = types.length(); |
|
839 Class<?> ptypes[] = new Class<?>[length + 2]; |
|
840 ptypes[0] = MethodType.class; |
|
841 ptypes[1] = LambdaForm.class; |
|
842 for (int i = 0; i < length; i++) { |
|
843 ptypes[i + 2] = BasicType.basicType(types.charAt(i)).basicTypeClass(); |
|
844 } |
|
845 return MethodType.makeImpl(BoundMethodHandle.class, ptypes, true); |
834 } |
846 } |
835 |
847 |
836 static MethodHandle makeCbmhCtor(Class<? extends BoundMethodHandle> cbmh, String types) { |
848 static MethodHandle makeCbmhCtor(Class<? extends BoundMethodHandle> cbmh, String types) { |
837 try { |
849 try { |
838 return LOOKUP.findStatic(cbmh, "make", MethodType.fromDescriptor(makeSignature(types, false), null)); |
850 return LOOKUP.findStatic(cbmh, "make", makeConstructorType(types)); |
839 } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) { |
851 } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) { |
840 throw newInternalError(e); |
852 throw newInternalError(e); |
841 } |
853 } |
842 } |
854 } |
843 } |
855 } |