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

Print this page
rev 17771 : 8184777: species logic for BoundMethodHandle doesn't scale, needs refactor


 166             }
 167         } else {
 168             DUMP_CLASS_FILES_COUNTERS = null;
 169             DUMP_CLASS_FILES_DIR = null;
 170         }
 171     }
 172 
 173     private void maybeDump(final byte[] classFile) {
 174         if (DUMP_CLASS_FILES) {
 175             maybeDump(CLASS_PREFIX + className, classFile);
 176         }
 177     }
 178 
 179     // Also used from BoundMethodHandle
 180     static void maybeDump(final String className, final byte[] classFile) {
 181         if (DUMP_CLASS_FILES) {
 182             java.security.AccessController.doPrivileged(
 183             new java.security.PrivilegedAction<>() {
 184                 public Void run() {
 185                     try {
 186                         String dumpName = className;
 187                         //dumpName = dumpName.replace('/', '-');
 188                         File dumpFile = new File(DUMP_CLASS_FILES_DIR, dumpName+".class");
 189                         System.out.println("dump: " + dumpFile);
 190                         dumpFile.getParentFile().mkdirs();
 191                         FileOutputStream file = new FileOutputStream(dumpFile);
 192                         file.write(classFile);
 193                         file.close();
 194                         return null;
 195                     } catch (IOException ex) {
 196                         throw newInternalError(ex);
 197                     }
 198                 }
 199             });
 200         }
 201     }
 202 
 203     private static String makeDumpableClassName(String className) {
 204         Integer ctr;
 205         synchronized (DUMP_CLASS_FILES_COUNTERS) {
 206             ctr = DUMP_CLASS_FILES_COUNTERS.get(className);


 613     }
 614 
 615     private static MemberName resolveFrom(String name, MethodType type, Class<?> holder) {
 616         MemberName member = new MemberName(holder, name, type, REF_invokeStatic);
 617         MemberName resolvedMember = MemberName.getFactory().resolveOrNull(REF_invokeStatic, member, holder);
 618         if (TRACE_RESOLVE) {
 619             System.out.println("[LF_RESOLVE] " + holder.getName() + " " + name + " " +
 620                     shortenSignature(basicTypeSignature(type)) + (resolvedMember != null ? " (success)" : " (fail)") );
 621         }
 622         return resolvedMember;
 623     }
 624 
 625     private static MemberName lookupPregenerated(LambdaForm form, MethodType invokerType) {
 626         if (form.customized != null) {
 627             // No pre-generated version for customized LF
 628             return null;
 629         }
 630         String name = form.kind.methodName;
 631         switch (form.kind) {
 632             case BOUND_REINVOKER: {
 633                 name = name + "_" + BoundMethodHandle.speciesData(form).fieldSignature();
 634                 return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
 635             }
 636             case DELEGATE:                  return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
 637             case ZERO:                      // fall-through
 638             case IDENTITY: {
 639                 name = name + "_" + form.returnType().basicTypeChar();
 640                 return resolveFrom(name, invokerType, LambdaForm.Holder.class);
 641             }
 642             case EXACT_INVOKER:             // fall-through
 643             case EXACT_LINKER:              // fall-through
 644             case GENERIC_INVOKER:           // fall-through
 645             case GENERIC_LINKER:            return resolveFrom(name, invokerType.basicType(), Invokers.Holder.class);
 646             case GET_OBJECT:                // fall-through
 647             case GET_BOOLEAN:               // fall-through
 648             case GET_BYTE:                  // fall-through
 649             case GET_CHAR:                  // fall-through
 650             case GET_SHORT:                 // fall-through
 651             case GET_INT:                   // fall-through
 652             case GET_LONG:                  // fall-through
 653             case GET_FLOAT:                 // fall-through




 166             }
 167         } else {
 168             DUMP_CLASS_FILES_COUNTERS = null;
 169             DUMP_CLASS_FILES_DIR = null;
 170         }
 171     }
 172 
 173     private void maybeDump(final byte[] classFile) {
 174         if (DUMP_CLASS_FILES) {
 175             maybeDump(CLASS_PREFIX + className, classFile);
 176         }
 177     }
 178 
 179     // Also used from BoundMethodHandle
 180     static void maybeDump(final String className, final byte[] classFile) {
 181         if (DUMP_CLASS_FILES) {
 182             java.security.AccessController.doPrivileged(
 183             new java.security.PrivilegedAction<>() {
 184                 public Void run() {
 185                     try {
 186                         String dumpName = className.replace('.','/');
 187                         //dumpName = dumpName.replace('/', '-');
 188                         File dumpFile = new File(DUMP_CLASS_FILES_DIR, dumpName+".class");
 189                         System.out.println("dump: " + dumpFile);
 190                         dumpFile.getParentFile().mkdirs();
 191                         FileOutputStream file = new FileOutputStream(dumpFile);
 192                         file.write(classFile);
 193                         file.close();
 194                         return null;
 195                     } catch (IOException ex) {
 196                         throw newInternalError(ex);
 197                     }
 198                 }
 199             });
 200         }
 201     }
 202 
 203     private static String makeDumpableClassName(String className) {
 204         Integer ctr;
 205         synchronized (DUMP_CLASS_FILES_COUNTERS) {
 206             ctr = DUMP_CLASS_FILES_COUNTERS.get(className);


 613     }
 614 
 615     private static MemberName resolveFrom(String name, MethodType type, Class<?> holder) {
 616         MemberName member = new MemberName(holder, name, type, REF_invokeStatic);
 617         MemberName resolvedMember = MemberName.getFactory().resolveOrNull(REF_invokeStatic, member, holder);
 618         if (TRACE_RESOLVE) {
 619             System.out.println("[LF_RESOLVE] " + holder.getName() + " " + name + " " +
 620                     shortenSignature(basicTypeSignature(type)) + (resolvedMember != null ? " (success)" : " (fail)") );
 621         }
 622         return resolvedMember;
 623     }
 624 
 625     private static MemberName lookupPregenerated(LambdaForm form, MethodType invokerType) {
 626         if (form.customized != null) {
 627             // No pre-generated version for customized LF
 628             return null;
 629         }
 630         String name = form.kind.methodName;
 631         switch (form.kind) {
 632             case BOUND_REINVOKER: {
 633                 name = name + "_" + BoundMethodHandle.formSpeciesData(form).key();
 634                 return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
 635             }
 636             case DELEGATE:                  return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
 637             case ZERO:                      // fall-through
 638             case IDENTITY: {
 639                 name = name + "_" + form.returnType().basicTypeChar();
 640                 return resolveFrom(name, invokerType, LambdaForm.Holder.class);
 641             }
 642             case EXACT_INVOKER:             // fall-through
 643             case EXACT_LINKER:              // fall-through
 644             case GENERIC_INVOKER:           // fall-through
 645             case GENERIC_LINKER:            return resolveFrom(name, invokerType.basicType(), Invokers.Holder.class);
 646             case GET_OBJECT:                // fall-through
 647             case GET_BOOLEAN:               // fall-through
 648             case GET_BYTE:                  // fall-through
 649             case GET_CHAR:                  // fall-through
 650             case GET_SHORT:                 // fall-through
 651             case GET_INT:                   // fall-through
 652             case GET_LONG:                  // fall-through
 653             case GET_FLOAT:                 // fall-through