< prev index next >

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

Print this page
rev 49203 : 8199453: Enable link-time generation of constructor forms
Reviewed-by: TBD


 652             case GENERIC_INVOKER:           // fall-through
 653             case GENERIC_LINKER:            return resolveFrom(name, invokerType.basicType(), Invokers.Holder.class);
 654             case GET_OBJECT:                // fall-through
 655             case GET_BOOLEAN:               // fall-through
 656             case GET_BYTE:                  // fall-through
 657             case GET_CHAR:                  // fall-through
 658             case GET_SHORT:                 // fall-through
 659             case GET_INT:                   // fall-through
 660             case GET_LONG:                  // fall-through
 661             case GET_FLOAT:                 // fall-through
 662             case GET_DOUBLE:                // fall-through
 663             case PUT_OBJECT:                // fall-through
 664             case PUT_BOOLEAN:               // fall-through
 665             case PUT_BYTE:                  // fall-through
 666             case PUT_CHAR:                  // fall-through
 667             case PUT_SHORT:                 // fall-through
 668             case PUT_INT:                   // fall-through
 669             case PUT_LONG:                  // fall-through
 670             case PUT_FLOAT:                 // fall-through
 671             case PUT_DOUBLE:                // fall-through

 672             case DIRECT_INVOKE_INTERFACE:   // fall-through
 673             case DIRECT_INVOKE_SPECIAL:     // fall-through
 674             case DIRECT_INVOKE_STATIC:      // fall-through
 675             case DIRECT_INVOKE_STATIC_INIT: // fall-through
 676             case DIRECT_INVOKE_VIRTUAL:     return resolveFrom(name, invokerType, DirectMethodHandle.Holder.class);
 677         }
 678         return null;
 679     }
 680 
 681     /**
 682      * Generate customized bytecode for a given LambdaForm.
 683      */
 684     static MemberName generateCustomizedCode(LambdaForm form, MethodType invokerType) {
 685         MemberName pregenerated = lookupPregenerated(form, invokerType);
 686         if (pregenerated != null)  return pregenerated; // pre-generated bytecode
 687 
 688         InvokerBytecodeGenerator g = new InvokerBytecodeGenerator("MH", form, invokerType);
 689         return g.loadMethod(g.generateCustomizedCodeBytes());
 690     }
 691 


1847         }
1848 
1849         // If the return type is void we return a null reference.
1850         if (rtype == void.class) {
1851             mv.visitInsn(Opcodes.ACONST_NULL);
1852         }
1853         emitReturnInsn(L_TYPE);  // NOTE: NamedFunction invokers always return a reference value.
1854 
1855         methodEpilogue();
1856         bogusMethod(dstType);
1857 
1858         final byte[] classFile = cw.toByteArray();
1859         maybeDump(classFile);
1860         return classFile;
1861     }
1862 
1863     /**
1864      * Emit a bogus method that just loads some string constants. This is to get the constants into the constant pool
1865      * for debugging purposes.
1866      */
1867     private void bogusMethod(Object... os) {
1868         if (DUMP_CLASS_FILES) {
1869             mv = cw.visitMethod(Opcodes.ACC_STATIC, "dummy", "()V", null, null);
1870             for (Object o : os) {
1871                 mv.visitLdcInsn(o.toString());
1872                 mv.visitInsn(Opcodes.POP);
1873             }
1874             mv.visitInsn(Opcodes.RETURN);
1875             mv.visitMaxs(0, 0);
1876             mv.visitEnd();
1877         }
1878     }
1879 }


 652             case GENERIC_INVOKER:           // fall-through
 653             case GENERIC_LINKER:            return resolveFrom(name, invokerType.basicType(), Invokers.Holder.class);
 654             case GET_OBJECT:                // fall-through
 655             case GET_BOOLEAN:               // fall-through
 656             case GET_BYTE:                  // fall-through
 657             case GET_CHAR:                  // fall-through
 658             case GET_SHORT:                 // fall-through
 659             case GET_INT:                   // fall-through
 660             case GET_LONG:                  // fall-through
 661             case GET_FLOAT:                 // fall-through
 662             case GET_DOUBLE:                // fall-through
 663             case PUT_OBJECT:                // fall-through
 664             case PUT_BOOLEAN:               // fall-through
 665             case PUT_BYTE:                  // fall-through
 666             case PUT_CHAR:                  // fall-through
 667             case PUT_SHORT:                 // fall-through
 668             case PUT_INT:                   // fall-through
 669             case PUT_LONG:                  // fall-through
 670             case PUT_FLOAT:                 // fall-through
 671             case PUT_DOUBLE:                // fall-through
 672             case DIRECT_NEW_INVOKE_SPECIAL: // fall-through
 673             case DIRECT_INVOKE_INTERFACE:   // fall-through
 674             case DIRECT_INVOKE_SPECIAL:     // fall-through
 675             case DIRECT_INVOKE_STATIC:      // fall-through
 676             case DIRECT_INVOKE_STATIC_INIT: // fall-through
 677             case DIRECT_INVOKE_VIRTUAL:     return resolveFrom(name, invokerType, DirectMethodHandle.Holder.class);
 678         }
 679         return null;
 680     }
 681 
 682     /**
 683      * Generate customized bytecode for a given LambdaForm.
 684      */
 685     static MemberName generateCustomizedCode(LambdaForm form, MethodType invokerType) {
 686         MemberName pregenerated = lookupPregenerated(form, invokerType);
 687         if (pregenerated != null)  return pregenerated; // pre-generated bytecode
 688 
 689         InvokerBytecodeGenerator g = new InvokerBytecodeGenerator("MH", form, invokerType);
 690         return g.loadMethod(g.generateCustomizedCodeBytes());
 691     }
 692 


1848         }
1849 
1850         // If the return type is void we return a null reference.
1851         if (rtype == void.class) {
1852             mv.visitInsn(Opcodes.ACONST_NULL);
1853         }
1854         emitReturnInsn(L_TYPE);  // NOTE: NamedFunction invokers always return a reference value.
1855 
1856         methodEpilogue();
1857         bogusMethod(dstType);
1858 
1859         final byte[] classFile = cw.toByteArray();
1860         maybeDump(classFile);
1861         return classFile;
1862     }
1863 
1864     /**
1865      * Emit a bogus method that just loads some string constants. This is to get the constants into the constant pool
1866      * for debugging purposes.
1867      */
1868     private void bogusMethod(Object os) {
1869         if (DUMP_CLASS_FILES) {
1870             mv = cw.visitMethod(Opcodes.ACC_STATIC, "dummy", "()V", null, null);
1871             mv.visitLdcInsn(os.toString());

1872             mv.visitInsn(Opcodes.POP);

1873             mv.visitInsn(Opcodes.RETURN);
1874             mv.visitMaxs(0, 0);
1875             mv.visitEnd();
1876         }
1877     }
1878 }
< prev index next >