179 names.add(callSiteForm.kind.defaultLambdaName);
180
181 LambdaForm methodHandleForm = Invokers.callSiteForm(callSiteMethodTypes[i], false);
182 forms.add(methodHandleForm);
183 names.add(methodHandleForm.kind.defaultLambdaName);
184 }
185 }
186
187 return generateCodeBytesForLFs(className,
188 names.toArray(new String[0]),
189 forms.toArray(new LambdaForm[0]));
190 }
191
192 /*
193 * Generate customized code for a set of LambdaForms of specified types into
194 * a class with a specified name.
195 */
196 private static byte[] generateCodeBytesForLFs(String className,
197 String[] names, LambdaForm[] forms) {
198
199 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
200 cw.visit(Opcodes.V1_8, Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
201 className, null, InvokerBytecodeGenerator.INVOKER_SUPER_NAME, null);
202 cw.visitSource(className.substring(className.lastIndexOf('/') + 1), null);
203
204 for (int i = 0; i < forms.length; i++) {
205 addMethod(className, names[i], forms[i],
206 forms[i].methodType(), cw);
207 }
208 return cw.toByteArray();
209 }
210
211 private static void addMethod(String className, String methodName, LambdaForm form,
212 MethodType type, ClassWriter cw) {
213 InvokerBytecodeGenerator g
214 = new InvokerBytecodeGenerator(className, methodName, form, type);
215 g.setClassWriter(cw);
216 g.addMethod();
217 }
218
219 private static LambdaForm makeReinvokerFor(MethodType type) {
220 MethodHandle emptyHandle = MethodHandles.empty(type);
221 return DelegatingMethodHandle.makeReinvokerForm(emptyHandle,
222 MethodTypeForm.LF_REBIND,
223 BoundMethodHandle.speciesData_L(),
224 BoundMethodHandle.speciesData_L().getterFunction(0));
225 }
226
227 private static LambdaForm makeDelegateFor(MethodType type) {
228 MethodHandle handle = MethodHandles.empty(type);
229 return DelegatingMethodHandle.makeReinvokerForm(
230 handle,
231 MethodTypeForm.LF_DELEGATE,
232 DelegatingMethodHandle.class,
233 DelegatingMethodHandle.NF_getTarget);
234 }
235
236 @SuppressWarnings({"rawtypes", "unchecked"})
237 static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(final String types) {
238 for (char c : types.toCharArray()) {
|
179 names.add(callSiteForm.kind.defaultLambdaName);
180
181 LambdaForm methodHandleForm = Invokers.callSiteForm(callSiteMethodTypes[i], false);
182 forms.add(methodHandleForm);
183 names.add(methodHandleForm.kind.defaultLambdaName);
184 }
185 }
186
187 return generateCodeBytesForLFs(className,
188 names.toArray(new String[0]),
189 forms.toArray(new LambdaForm[0]));
190 }
191
192 /*
193 * Generate customized code for a set of LambdaForms of specified types into
194 * a class with a specified name.
195 */
196 private static byte[] generateCodeBytesForLFs(String className,
197 String[] names, LambdaForm[] forms) {
198
199
200 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
201 cw.visit(Opcodes.V1_8, Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
202 className, null, InvokerBytecodeGenerator.INVOKER_SUPER_NAME, null);
203 cw.visitSource(className.substring(className.lastIndexOf('/') + 1), null);
204
205 for (int i = 0; i < forms.length; i++) {
206 InvokerBytecodeGenerator g
207 = new InvokerBytecodeGenerator(className, names[i], forms[i], forms[i].methodType());
208 g.setClassWriter(cw);
209 g.addMethod();
210 }
211
212 return cw.toByteArray();
213 }
214
215 private static LambdaForm makeReinvokerFor(MethodType type) {
216 MethodHandle emptyHandle = MethodHandles.empty(type);
217 return DelegatingMethodHandle.makeReinvokerForm(emptyHandle,
218 MethodTypeForm.LF_REBIND,
219 BoundMethodHandle.speciesData_L(),
220 BoundMethodHandle.speciesData_L().getterFunction(0));
221 }
222
223 private static LambdaForm makeDelegateFor(MethodType type) {
224 MethodHandle handle = MethodHandles.empty(type);
225 return DelegatingMethodHandle.makeReinvokerForm(
226 handle,
227 MethodTypeForm.LF_DELEGATE,
228 DelegatingMethodHandle.class,
229 DelegatingMethodHandle.NF_getTarget);
230 }
231
232 @SuppressWarnings({"rawtypes", "unchecked"})
233 static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(final String types) {
234 for (char c : types.toCharArray()) {
|