< prev index next >

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

Print this page

        

*** 39,73 **** * * @since 11 */ public final class ConstantBootstraps { // implements the upcall from the JVM, MethodHandleNatives.linkDynamicConstant: ! /*non-public*/ ! static Object makeConstant(MethodHandle bootstrapMethod, ! // Callee information: ! String name, Class<?> type, ! // Extra arguments for BSM, if any: ! Object info, ! // Caller information: ! Class<?> callerClass) { ! // Restrict bootstrap methods to those whose first parameter is Lookup ! // The motivation here is, in the future, to possibly support BSMs ! // that do not accept the meta-data of lookup/name/type, thereby ! // allowing the co-opting of existing methods to be used as BSMs as ! // long as the static arguments can be passed as method arguments ! MethodType mt = bootstrapMethod.type(); ! if (mt.parameterCount() < 2 || ! !MethodHandles.Lookup.class.isAssignableFrom(mt.parameterType(0))) { ! throw new BootstrapMethodError( ! "Invalid bootstrap method declared for resolving a dynamic constant: " + bootstrapMethod); ! } // BSMI.invoke handles all type checking and exception translation. // If type is not a reference type, the JVM is expecting a boxed // version, and will manage unboxing on the other side. return BootstrapMethodInvoker.invoke( ! type, bootstrapMethod, name, type, info, callerClass); } /** * Returns a {@code null} object reference for the reference type specified * by {@code type}. --- 39,78 ---- * * @since 11 */ public final class ConstantBootstraps { // implements the upcall from the JVM, MethodHandleNatives.linkDynamicConstant: ! /** ! * makeConstant ! * ! * @param bootstrapMethod doc ! * @param name doc ! * @param type doc ! * @param info doc ! * @param callerClass doc ! * @return doc ! */ ! /*non-public*/ static Object makeConstant(MethodHandle bootstrapMethod, ! // Callee information: ! String name, Class<?> type, ! // Extra arguments for BSM, if any: ! Object info, ! // Caller information: ! Class<?> callerClass) { ! // Lookup, name and type argument metadata should be included when ! // invoking the BSM if there are one or more parameters and the first ! // parameter type is MethodHandles.Lookup ! MethodType bsmType = bootstrapMethod.type(); ! boolean includeMetadata = (bsmType.parameterCount() > 0 && ! MethodHandles.Lookup.class.isAssignableFrom(bsmType.parameterType(0))); // BSMI.invoke handles all type checking and exception translation. // If type is not a reference type, the JVM is expecting a boxed // version, and will manage unboxing on the other side. return BootstrapMethodInvoker.invoke( ! type, bootstrapMethod, name, type, info, callerClass, ! includeMetadata); } /** * Returns a {@code null} object reference for the reference type specified * by {@code type}.
< prev index next >