< prev index next >

src/java.base/share/classes/java/lang/constant/ConstantDescs.java

Print this page
rev 52749 : Bootstrap method consolidation
* clean up and simplify JDK support code for BSM invocation
* simplify JVM bootstrap handshake: use BootstrapCallInfo only
* remove unused JVM paths and data fields
* move bootstrap argument processing from MethodHandleNatives to ConstantPool
* remove ConstantGroup; merge argument access into BootstrapCallInfo
* adjust BSM argument access: remove copyArguments, add argumentRef API
* add metadata-free BSM modes, including symbolic arguments from CP


  41 import static java.lang.constant.DirectMethodHandleDesc.Kind.STATIC;
  42 
  43 /**
  44  * Predefined values of <a href="package-summary.html#nominal">nominal descriptor</a>
  45  * for common constants, including descriptors for primitive class types and
  46  * other common platform types, and descriptors for method handles for standard
  47  * bootstrap methods.
  48  *
  49  * @see ConstantDesc
  50  */
  51 public final class ConstantDescs {
  52     // No instances
  53     private ConstantDescs() { }
  54 
  55     /** Invocation name to use when no name is needed, such as the name of a
  56      * constructor, or the invocation name of a dynamic constant or dynamic
  57      * callsite when the bootstrap is known to ignore the invocation name.
  58      */
  59     public static final String DEFAULT_NAME = "_";
  60 
















  61     // Don't change the order of these declarations!
  62 
  63     /** {@link ClassDesc} representing {@link Object} */
  64     public static final ClassDesc CR_Object = ClassDesc.of("java.lang.Object");
  65 
  66     /** {@link ClassDesc} representing {@link String} */
  67     public static final ClassDesc CR_String = ClassDesc.of("java.lang.String");
  68 
  69     /** {@link ClassDesc} representing {@link Class} */
  70     public static final ClassDesc CR_Class = ClassDesc.of("java.lang.Class");
  71 
  72     /** {@link ClassDesc} representing {@link Number} */
  73     public static final ClassDesc CR_Number = ClassDesc.of("java.lang.Number");
  74 
  75     /** {@link ClassDesc} representing {@link Integer} */
  76     public static final ClassDesc CR_Integer = ClassDesc.of("java.lang.Integer");
  77 
  78     /** {@link ClassDesc} representing {@link Long} */
  79     public static final ClassDesc CR_Long = ClassDesc.of("java.lang.Long");
  80 


 232     public static final ClassDesc CR_short = ClassDesc.ofDescriptor("S");
 233 
 234     /** {@link ClassDesc} representing the primitive type {@code byte} */
 235     public static final ClassDesc CR_byte = ClassDesc.ofDescriptor("B");
 236 
 237     /** {@link ClassDesc} representing the primitive type {@code char} */
 238     public static final ClassDesc CR_char = ClassDesc.ofDescriptor("C");
 239 
 240     /** {@link ClassDesc} representing the primitive type {@code boolean} */
 241     public static final ClassDesc CR_boolean = ClassDesc.ofDescriptor("Z");
 242 
 243     /** {@link ClassDesc} representing the primitive type {@code void} */
 244     public static final ClassDesc CR_void = ClassDesc.ofDescriptor("V");
 245 
 246     /** Nominal descriptor representing the constant {@code null} */
 247     public static final ConstantDesc<?> NULL
 248             = DynamicConstantDesc.ofNamed(ConstantDescs.BSM_NULL_CONSTANT,
 249                                           DEFAULT_NAME, ConstantDescs.CR_Object);
 250 
 251     // Used by XxxDesc classes, but need to be here to avoid bootstrap cycles
 252     static final DirectMethodHandleDesc MHR_METHODTYPEDESC_FACTORY
 253             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_MethodTypeDesc, "ofDescriptor",
 254                                   CR_MethodTypeDesc, CR_String);
 255 
 256     static final DirectMethodHandleDesc MHR_CLASSDESC_FACTORY
 257             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_ClassDesc, "ofDescriptor",
 258                                   CR_ClassDesc, CR_String);
 259 
 260     static final DirectMethodHandleDesc MHR_METHODHANDLEDESC_FACTORY
 261             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_DirectMethodHandleDesc, "ofDescriptor",
 262                                   CR_DirectMethodHandleDesc, CR_String, CR_String, CR_String, CR_String);
 263 
 264     static final DirectMethodHandleDesc MHR_METHODHANDLE_ASTYPE
 265             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.VIRTUAL, CR_MethodHandle, "asType",
 266                                   CR_MethodHandle, CR_MethodType);
 267 
 268     static final DirectMethodHandleDesc MHR_METHODHANDLEDESC_ASTYPE
 269             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.VIRTUAL, CR_MethodHandleDesc, "asType",
 270                                   CR_MethodHandleDesc, CR_MethodTypeDesc);
 271 
 272     static final DirectMethodHandleDesc MHR_DYNAMICCONSTANTDESC_FACTORY
 273             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_DynamicConstantDesc, "of",
 274                                   CR_DynamicConstantDesc, CR_DirectMethodHandleDesc, CR_ConstantDesc.arrayType());
 275 
 276     static final DirectMethodHandleDesc MHR_DYNAMICCONSTANTDESC_NAMED_FACTORY
 277             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_DynamicConstantDesc, "ofNamed",
 278                                   CR_DynamicConstantDesc, CR_DirectMethodHandleDesc, CR_String, CR_String, CR_ConstantDesc.arrayType());
 279 
 280     /** {@link MethodHandleDesc} representing {@link EnumDesc#ofDescriptor(String, String)} */
 281     public static final DirectMethodHandleDesc MHR_ENUMDESC_FACTORY
 282             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_EnumDesc, "ofDescriptor",
 283                                   CR_EnumDesc, CR_String, CR_String);
 284 
 285     /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofField(ClassDesc, String, ClassDesc)} */
 286     public static final DirectMethodHandleDesc MHR_VARHANDLEDESC_OFFIELD
 287             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_VarHandleDesc, "ofField",
 288                                   CR_VarHandleDesc, CR_ClassDesc, CR_String, CR_ClassDesc);
 289     /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofStaticField(ClassDesc, String, ClassDesc)} */
 290     public static final DirectMethodHandleDesc MHR_VARHANDLEDESC_OFSTATIC
 291             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_VarHandleDesc, "ofStaticField",
 292                                   CR_VarHandleDesc, CR_ClassDesc, CR_String, CR_ClassDesc);
 293 
 294     /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofArray(ClassDesc)} */
 295     public static final DirectMethodHandleDesc MHR_VARHANDLEDESC_OFARRAY
 296             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_VarHandleDesc, "ofArray",
 297                                   CR_VarHandleDesc, CR_ClassDesc);
 298 
 299     static final DirectMethodHandleDesc BSM_METHODHANDLEDESC
 300             = ConstantDescs.ofConstantBootstrap(CR_DirectMethodHandleDesc,
 301                                                 "constantBootstrap", CR_DirectMethodHandleDesc,
 302                                                 CR_String, CR_String, CR_String, CR_String);
 303 
 304     static final DirectMethodHandleDesc BSM_DYNAMICCONSTANTDESC
 305             = ConstantDescs.ofConstantBootstrap(CR_DynamicConstantDesc,
 306                                                 "constantBootstrap",
 307                                                 CR_DynamicConstantDesc,
 308                                                 CR_DirectMethodHandleDesc, CR_String, CR_String, CR_ConstantDesc.arrayType());
 309 
 310     /**
 311      * Return a {@link MethodHandleDesc} corresponding to a bootstrap method for
 312      * an {@code invokedynamic} callsite, which is a static method whose leading
 313      * parameter types are {@code Lookup}, {@code String}, and {@code MethodType}.
 314      *
 315      * @param clazz the class declaring the method
 316      * @param name the name of the method, as per JVMS 4.2.2
 317      * @param returnType the return type of the method
 318      * @param paramTypes the types of the static bootstrap arguments, if any
 319      * @return the {@link MethodHandleDesc}
 320      * @throws NullPointerException if any of the arguments are null
 321      * @jvms 4.2.2 Unqualified Names
 322      */
 323     public static DirectMethodHandleDesc ofCallsiteBootstrap(ClassDesc clazz,
 324                                                              String name,
 325                                                              ClassDesc returnType,
 326                                                              ClassDesc... paramTypes) {
 327         return MethodHandleDesc.of(STATIC, clazz, name, MethodTypeDesc.of(returnType, paramTypes)
 328                                                                       .insertParameterTypes(0, INDY_BOOTSTRAP_ARGS));
 329     }




  41 import static java.lang.constant.DirectMethodHandleDesc.Kind.STATIC;
  42 
  43 /**
  44  * Predefined values of <a href="package-summary.html#nominal">nominal descriptor</a>
  45  * for common constants, including descriptors for primitive class types and
  46  * other common platform types, and descriptors for method handles for standard
  47  * bootstrap methods.
  48  *
  49  * @see ConstantDesc
  50  */
  51 public final class ConstantDescs {
  52     // No instances
  53     private ConstantDescs() { }
  54 
  55     /** Invocation name to use when no name is needed, such as the name of a
  56      * constructor, or the invocation name of a dynamic constant or dynamic
  57      * callsite when the bootstrap is known to ignore the invocation name.
  58      */
  59     public static final String DEFAULT_NAME = "_";
  60 
  61     /** Invocation name to use with a no-metadata expression mode bootstrap method.
  62      * The effect of resolving a dynamic constant with this name is to call
  63      * the bootstrap method on the arguments, but not on the lookup, name, or type.
  64      * The arguments are resolved.
  65      */
  66     public static final String INVOKE_NAME = "invoke";
  67 
  68     /** Invocation name to use with a no-metadata expression mode bootstrap method.
  69      * The effect of resolving a dynamic constant with this name is to call
  70      * the bootstrap method on the arguments, but not on the lookup, name, or type.
  71      * In addition, formal parameters which are of a supertype of {@link ConstantDesc}
  72      * are not resolved, but are passed as unresolved {@link ConstantDesc} values
  73      * derived directly from the constant pool.
  74      */
  75     public static final String SYMBOLIC_NAME = "symbolic";
  76 
  77     // Don't change the order of these declarations!
  78 
  79     /** {@link ClassDesc} representing {@link Object} */
  80     public static final ClassDesc CR_Object = ClassDesc.of("java.lang.Object");
  81 
  82     /** {@link ClassDesc} representing {@link String} */
  83     public static final ClassDesc CR_String = ClassDesc.of("java.lang.String");
  84 
  85     /** {@link ClassDesc} representing {@link Class} */
  86     public static final ClassDesc CR_Class = ClassDesc.of("java.lang.Class");
  87 
  88     /** {@link ClassDesc} representing {@link Number} */
  89     public static final ClassDesc CR_Number = ClassDesc.of("java.lang.Number");
  90 
  91     /** {@link ClassDesc} representing {@link Integer} */
  92     public static final ClassDesc CR_Integer = ClassDesc.of("java.lang.Integer");
  93 
  94     /** {@link ClassDesc} representing {@link Long} */
  95     public static final ClassDesc CR_Long = ClassDesc.of("java.lang.Long");
  96 


 248     public static final ClassDesc CR_short = ClassDesc.ofDescriptor("S");
 249 
 250     /** {@link ClassDesc} representing the primitive type {@code byte} */
 251     public static final ClassDesc CR_byte = ClassDesc.ofDescriptor("B");
 252 
 253     /** {@link ClassDesc} representing the primitive type {@code char} */
 254     public static final ClassDesc CR_char = ClassDesc.ofDescriptor("C");
 255 
 256     /** {@link ClassDesc} representing the primitive type {@code boolean} */
 257     public static final ClassDesc CR_boolean = ClassDesc.ofDescriptor("Z");
 258 
 259     /** {@link ClassDesc} representing the primitive type {@code void} */
 260     public static final ClassDesc CR_void = ClassDesc.ofDescriptor("V");
 261 
 262     /** Nominal descriptor representing the constant {@code null} */
 263     public static final ConstantDesc<?> NULL
 264             = DynamicConstantDesc.ofNamed(ConstantDescs.BSM_NULL_CONSTANT,
 265                                           DEFAULT_NAME, ConstantDescs.CR_Object);
 266 
 267     // Used by XxxDesc classes, but need to be here to avoid bootstrap cycles




 268     static final DirectMethodHandleDesc MHR_CLASSDESC_FACTORY
 269             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_ClassDesc, "ofDescriptor",
 270                                   CR_ClassDesc, CR_String);
 271 




 272     static final DirectMethodHandleDesc MHR_METHODHANDLE_ASTYPE
 273             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.VIRTUAL, CR_MethodHandle, "asType",
 274                                   CR_MethodHandle, CR_MethodType);
 275 
 276     static final DirectMethodHandleDesc MHR_METHODHANDLEDESC_ASTYPE
 277             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.VIRTUAL, CR_MethodHandleDesc, "asType",
 278                                   CR_MethodHandleDesc, CR_MethodTypeDesc);
 279 
 280     static final DirectMethodHandleDesc MHR_CONSTANTDESC_IDENTITY
 281             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_ConstantBootstraps, "constantDesc",
 282                                   CR_ConstantDesc, CR_ConstantDesc);




 283 
 284     /** {@link MethodHandleDesc} representing {@link EnumDesc#ofDescriptor(String, String)} */
 285     public static final DirectMethodHandleDesc MHR_ENUMDESC_FACTORY
 286             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_EnumDesc, "ofDescriptor",
 287                                   CR_EnumDesc, CR_String, CR_String);
 288 
 289     /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofField(ClassDesc, String, ClassDesc)} */
 290     public static final DirectMethodHandleDesc MHR_VARHANDLEDESC_OFFIELD
 291             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_VarHandleDesc, "ofField",
 292                                   CR_VarHandleDesc, CR_ClassDesc, CR_String, CR_ClassDesc);
 293     /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofStaticField(ClassDesc, String, ClassDesc)} */
 294     public static final DirectMethodHandleDesc MHR_VARHANDLEDESC_OFSTATIC
 295             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_VarHandleDesc, "ofStaticField",
 296                                   CR_VarHandleDesc, CR_ClassDesc, CR_String, CR_ClassDesc);
 297 
 298     /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofArray(ClassDesc)} */
 299     public static final DirectMethodHandleDesc MHR_VARHANDLEDESC_OFARRAY
 300             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CR_VarHandleDesc, "ofArray",
 301                                   CR_VarHandleDesc, CR_ClassDesc);
 302 











 303     /**
 304      * Return a {@link MethodHandleDesc} corresponding to a bootstrap method for
 305      * an {@code invokedynamic} callsite, which is a static method whose leading
 306      * parameter types are {@code Lookup}, {@code String}, and {@code MethodType}.
 307      *
 308      * @param clazz the class declaring the method
 309      * @param name the name of the method, as per JVMS 4.2.2
 310      * @param returnType the return type of the method
 311      * @param paramTypes the types of the static bootstrap arguments, if any
 312      * @return the {@link MethodHandleDesc}
 313      * @throws NullPointerException if any of the arguments are null
 314      * @jvms 4.2.2 Unqualified Names
 315      */
 316     public static DirectMethodHandleDesc ofCallsiteBootstrap(ClassDesc clazz,
 317                                                              String name,
 318                                                              ClassDesc returnType,
 319                                                              ClassDesc... paramTypes) {
 320         return MethodHandleDesc.of(STATIC, clazz, name, MethodTypeDesc.of(returnType, paramTypes)
 321                                                                       .insertParameterTypes(0, INDY_BOOTSTRAP_ARGS));
 322     }


< prev index next >