1149 int arity = LambdaForm.signatureArity(sig); |
1149 int arity = LambdaForm.signatureArity(sig); |
1150 MethodType srcType = MethodType.genericMethodType(arity); |
1150 MethodType srcType = MethodType.genericMethodType(arity); |
1151 if (LambdaForm.signatureReturn(sig) == V_TYPE) |
1151 if (LambdaForm.signatureReturn(sig) == V_TYPE) |
1152 srcType = srcType.changeReturnType(void.class); |
1152 srcType = srcType.changeReturnType(void.class); |
1153 MethodTypeForm typeForm = srcType.form(); |
1153 MethodTypeForm typeForm = srcType.form(); |
1154 typeForm.namedFunctionInvoker = DirectMethodHandle.make(m); |
1154 typeForm.setCachedMethodHandle(MethodTypeForm.MH_NF_INV, DirectMethodHandle.make(m)); |
1155 } |
1155 } |
1156 } |
1156 } |
1157 } |
1157 } |
1158 |
1158 |
1159 // The following are predefined NamedFunction invokers. The system must build |
1159 // The following are predefined NamedFunction invokers. The system must build |
1247 |
1247 |
1248 static final MethodType INVOKER_METHOD_TYPE = |
1248 static final MethodType INVOKER_METHOD_TYPE = |
1249 MethodType.methodType(Object.class, MethodHandle.class, Object[].class); |
1249 MethodType.methodType(Object.class, MethodHandle.class, Object[].class); |
1250 |
1250 |
1251 private static MethodHandle computeInvoker(MethodTypeForm typeForm) { |
1251 private static MethodHandle computeInvoker(MethodTypeForm typeForm) { |
1252 MethodHandle mh = typeForm.namedFunctionInvoker; |
1252 typeForm = typeForm.basicType().form(); // normalize to basic type |
|
1253 MethodHandle mh = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV); |
1253 if (mh != null) return mh; |
1254 if (mh != null) return mh; |
1254 MemberName invoker = InvokerBytecodeGenerator.generateNamedFunctionInvoker(typeForm); // this could take a while |
1255 MemberName invoker = InvokerBytecodeGenerator.generateNamedFunctionInvoker(typeForm); // this could take a while |
1255 mh = DirectMethodHandle.make(invoker); |
1256 mh = DirectMethodHandle.make(invoker); |
1256 MethodHandle mh2 = typeForm.namedFunctionInvoker; |
1257 MethodHandle mh2 = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV); |
1257 if (mh2 != null) return mh2; // benign race |
1258 if (mh2 != null) return mh2; // benign race |
1258 if (!mh.type().equals(INVOKER_METHOD_TYPE)) |
1259 if (!mh.type().equals(INVOKER_METHOD_TYPE)) |
1259 throw newInternalError(mh.debugString()); |
1260 throw newInternalError(mh.debugString()); |
1260 return typeForm.namedFunctionInvoker = mh; |
1261 return typeForm.setCachedMethodHandle(MethodTypeForm.MH_NF_INV, mh); |
1261 } |
1262 } |
1262 |
1263 |
1263 @Hidden |
1264 @Hidden |
1264 Object invokeWithArguments(Object... arguments) throws Throwable { |
1265 Object invokeWithArguments(Object... arguments) throws Throwable { |
1265 // If we have a cached invoker, call it right away. |
1266 // If we have a cached invoker, call it right away. |