< prev index next >

src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java

Print this page




 166                 names.add(callSiteForm.kind.defaultLambdaName);
 167 
 168                 LambdaForm methodHandleForm = Invokers.callSiteForm(callSiteMethodTypes[i], false);
 169                 forms.add(methodHandleForm);
 170                 names.add(methodHandleForm.kind.defaultLambdaName);
 171             }
 172         }
 173 
 174         return generateCodeBytesForLFs(className,
 175                 names.toArray(new String[0]),
 176                 forms.toArray(new LambdaForm[0]));
 177     }
 178 
 179     /*
 180      * Generate customized code for a set of LambdaForms of specified types into
 181      * a class with a specified name.
 182      */
 183     private static byte[] generateCodeBytesForLFs(String className,
 184             String[] names, LambdaForm[] forms) {
 185 

 186         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
 187         cw.visit(Opcodes.V1_8, Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
 188                 className, null, InvokerBytecodeGenerator.INVOKER_SUPER_NAME, null);
 189         cw.visitSource(className.substring(className.lastIndexOf('/') + 1), null);
 190 
 191         for (int i = 0; i < forms.length; i++) {
 192             addMethod(className, names[i], forms[i],
 193                     forms[i].methodType(), cw);


 194         }
 195         return cw.toByteArray();
 196     }
 197 
 198     private static void addMethod(String className, String methodName, LambdaForm form,
 199             MethodType type, ClassWriter cw) {
 200         InvokerBytecodeGenerator g
 201                 = new InvokerBytecodeGenerator(className, methodName, form, type);
 202         g.setClassWriter(cw);
 203         g.addMethod();
 204     }
 205 
 206     private static LambdaForm makeReinvokerFor(MethodType type) {
 207         MethodHandle emptyHandle = MethodHandles.empty(type);
 208         return DelegatingMethodHandle.makeReinvokerForm(emptyHandle,
 209                 MethodTypeForm.LF_REBIND,
 210                 BoundMethodHandle.speciesData_L(),
 211                 BoundMethodHandle.speciesData_L().getterFunction(0));
 212     }
 213 
 214     private static LambdaForm makeDelegateFor(MethodType type) {
 215         MethodHandle handle = MethodHandles.empty(type);
 216         return DelegatingMethodHandle.makeReinvokerForm(
 217                 handle,
 218                 MethodTypeForm.LF_DELEGATE,
 219                 DelegatingMethodHandle.class,
 220                 DelegatingMethodHandle.NF_getTarget);
 221     }
 222 
 223     @SuppressWarnings({"rawtypes", "unchecked"})


 166                 names.add(callSiteForm.kind.defaultLambdaName);
 167 
 168                 LambdaForm methodHandleForm = Invokers.callSiteForm(callSiteMethodTypes[i], false);
 169                 forms.add(methodHandleForm);
 170                 names.add(methodHandleForm.kind.defaultLambdaName);
 171             }
 172         }
 173 
 174         return generateCodeBytesForLFs(className,
 175                 names.toArray(new String[0]),
 176                 forms.toArray(new LambdaForm[0]));
 177     }
 178 
 179     /*
 180      * Generate customized code for a set of LambdaForms of specified types into
 181      * a class with a specified name.
 182      */
 183     private static byte[] generateCodeBytesForLFs(String className,
 184             String[] names, LambdaForm[] forms) {
 185 
 186 
 187         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
 188         cw.visit(Opcodes.V1_8, Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
 189                 className, null, InvokerBytecodeGenerator.INVOKER_SUPER_NAME, null);
 190         cw.visitSource(className.substring(className.lastIndexOf('/') + 1), null);
 191 
 192         for (int i = 0; i < forms.length; i++) {
 193             InvokerBytecodeGenerator g
 194                 = new InvokerBytecodeGenerator(className, names[i], forms[i], forms[i].methodType());
 195             g.setClassWriter(cw);
 196             g.addMethod();
 197         }


 198 
 199         return cw.toByteArray();





 200     }
 201 
 202     private static LambdaForm makeReinvokerFor(MethodType type) {
 203         MethodHandle emptyHandle = MethodHandles.empty(type);
 204         return DelegatingMethodHandle.makeReinvokerForm(emptyHandle,
 205                 MethodTypeForm.LF_REBIND,
 206                 BoundMethodHandle.speciesData_L(),
 207                 BoundMethodHandle.speciesData_L().getterFunction(0));
 208     }
 209 
 210     private static LambdaForm makeDelegateFor(MethodType type) {
 211         MethodHandle handle = MethodHandles.empty(type);
 212         return DelegatingMethodHandle.makeReinvokerForm(
 213                 handle,
 214                 MethodTypeForm.LF_DELEGATE,
 215                 DelegatingMethodHandle.class,
 216                 DelegatingMethodHandle.NF_getTarget);
 217     }
 218 
 219     @SuppressWarnings({"rawtypes", "unchecked"})
< prev index next >