< prev index next >

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

Print this page




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.constant;
  26 


  27 import java.lang.invoke.CallSite;
  28 import java.lang.invoke.MethodHandle;
  29 import java.lang.invoke.MethodHandles;
  30 import java.util.Arrays;
  31 import java.util.Objects;
  32 import java.util.stream.Stream;
  33 
  34 import static java.lang.constant.ConstantDescs.CD_String;
  35 import static java.lang.constant.ConstantUtils.EMPTY_CONSTANTDESC;
  36 import static java.lang.constant.ConstantUtils.validateMemberName;
  37 import static java.util.Objects.requireNonNull;
  38 import static java.util.stream.Collectors.joining;
  39 
  40 /**
  41  * A <a href="package-summary.html#nominal">nominal descriptor</a> for an
  42  * {@code invokedynamic} call site.
  43  *
  44  * <p>Concrete subtypes of {@linkplain DynamicCallSiteDesc} must be
  45  * <a href="../doc-files/ValueBased.html">value-based</a>.
  46  *


  85 
  86     /**
  87      * Creates a nominal descriptor for an {@code invokedynamic} call site.
  88      *
  89      * @param bootstrapMethod a {@link DirectMethodHandleDesc} describing the
  90      *                        bootstrap method for the {@code invokedynamic}
  91      * @param invocationName The unqualified name that would appear in the {@code NameAndType}
  92      *                       operand of the {@code invokedynamic}
  93      * @param invocationType a {@link MethodTypeDesc} describing the invocation
  94      *                       type that would appear in the {@code NameAndType}
  95      *                       operand of the {@code invokedynamic}
  96      * @param bootstrapArgs {@link ConstantDesc}s describing the static arguments
  97      *                      to the bootstrap, that would appear in the
  98      *                      {@code BootstrapMethods} attribute
  99      * @return the nominal descriptor
 100      * @throws NullPointerException if any parameter is null
 101      * @throws IllegalArgumentException if the invocation name has the incorrect
 102      * format
 103      * @jvms 4.2.2 Unqualified Names
 104      */

 105     public static DynamicCallSiteDesc of(DirectMethodHandleDesc bootstrapMethod,
 106                                          String invocationName,
 107                                          MethodTypeDesc invocationType,
 108                                          ConstantDesc... bootstrapArgs) {
 109         return new DynamicCallSiteDesc(bootstrapMethod, invocationName, invocationType, bootstrapArgs);
 110     }
 111 
 112     /**
 113      * Creates a nominal descriptor for an {@code invokedynamic} call site whose
 114      * bootstrap method has no static arguments.
 115      *
 116      * @param bootstrapMethod The bootstrap method for the {@code invokedynamic}
 117      * @param invocationName The invocationName that would appear in the
 118      * {@code NameAndType} operand of the {@code invokedynamic}
 119      * @param invocationType The invocation invocationType that would appear
 120      * in the {@code NameAndType} operand of the {@code invokedynamic}
 121      * @return the nominal descriptor
 122      * @throws NullPointerException if any parameter is null
 123      * @throws IllegalArgumentException if the invocation name has the incorrect
 124      * format
 125      */

 126     public static DynamicCallSiteDesc of(DirectMethodHandleDesc bootstrapMethod,
 127                                          String invocationName,
 128                                          MethodTypeDesc invocationType) {
 129         return new DynamicCallSiteDesc(bootstrapMethod, invocationName, invocationType, EMPTY_CONSTANTDESC);
 130     }
 131 
 132     /**
 133      * Creates a nominal descriptor for an {@code invokedynamic} call site whose
 134      * bootstrap method has no static arguments and for which the name parameter
 135      * is {@link ConstantDescs#DEFAULT_NAME}.
 136      *
 137      * @param bootstrapMethod a {@link DirectMethodHandleDesc} describing the
 138      *                        bootstrap method for the {@code invokedynamic}
 139      * @param invocationType a {@link MethodTypeDesc} describing the invocation
 140      *                       type that would appear in the {@code NameAndType}
 141      *                       operand of the {@code invokedynamic}
 142      * @return the nominal descriptor
 143      * @throws NullPointerException if any parameter is null
 144      */

 145     public static DynamicCallSiteDesc of(DirectMethodHandleDesc bootstrapMethod,
 146                                          MethodTypeDesc invocationType) {
 147         return of(bootstrapMethod, ConstantDescs.DEFAULT_NAME, invocationType);
 148     }
 149 
 150     /**
 151      * Returns a nominal descriptor for an {@code invokedynamic} call site whose
 152      * bootstrap method, name, and invocation type are the same as this one, but
 153      * with the specified bootstrap arguments.
 154      *
 155      * @param bootstrapArgs {@link ConstantDesc}s describing the static arguments
 156      *                      to the bootstrap, that would appear in the
 157      *                      {@code BootstrapMethods} attribute
 158      * @return the nominal descriptor
 159      * @throws NullPointerException if any parameter is null
 160      */

 161     public DynamicCallSiteDesc withArgs(ConstantDesc... bootstrapArgs) {
 162         return new DynamicCallSiteDesc(bootstrapMethod, invocationName, invocationType, bootstrapArgs);
 163     }
 164 
 165     /**
 166      * Returns a nominal descriptor for an {@code invokedynamic} call site whose
 167      * bootstrap and bootstrap arguments are the same as this one, but with the
 168      * specified invocationName and invocation invocationType
 169      *
 170      * @param invocationName The unqualified name that would appear in the {@code NameAndType}
 171      *                       operand of the {@code invokedynamic}
 172      * @param invocationType a {@link MethodTypeDesc} describing the invocation
 173      *                       type that would appear in the {@code NameAndType}
 174      *                       operand of the {@code invokedynamic}
 175      * @return the nominal descriptor
 176      * @throws NullPointerException if any parameter is null
 177      * @throws IllegalArgumentException if the invocation name has the incorrect
 178      * format
 179      * @jvms 4.2.2 Unqualified Names
 180      */

 181     public DynamicCallSiteDesc withNameAndType(String invocationName,
 182                                                MethodTypeDesc invocationType) {
 183         return new DynamicCallSiteDesc(bootstrapMethod, invocationName, invocationType, bootstrapArgs);
 184     }
 185 
 186     /**
 187      * Returns the invocation name that would appear in the {@code NameAndType}
 188      * operand of the {@code invokedynamic}.
 189      *
 190      * @return the invocation name
 191      */

 192     public String invocationName() {
 193         return invocationName;
 194     }
 195 
 196     /**
 197      * Returns a {@link MethodTypeDesc} describing the invocation type that
 198      * would appear in the {@code NameAndType} operand of the {@code invokedynamic}.
 199      *
 200      * @return the invocation type
 201      */

 202     public MethodTypeDesc invocationType() {
 203         return invocationType;
 204     }
 205 
 206     /**
 207      * Returns a {@link MethodHandleDesc} describing the bootstrap method for
 208      * the {@code invokedynamic}.
 209      *
 210      * @return the bootstrap method for the {@code invokedynamic}
 211      */

 212     public MethodHandleDesc bootstrapMethod() { return bootstrapMethod; }
 213 
 214     /**
 215      * Returns {@link ConstantDesc}s describing the bootstrap arguments for the
 216      * {@code invokedynamic}. The returned array is always non-null. A zero
 217      * length array is returned if this {@linkplain DynamicCallSiteDesc} has no
 218      * bootstrap arguments.
 219      *
 220      * @return the bootstrap arguments for the {@code invokedynamic}
 221      */
 222     public ConstantDesc[] bootstrapArgs() { return bootstrapArgs.clone(); }
 223 
 224     /**
 225      * Reflectively invokes the bootstrap method with the specified arguments,
 226      * and return the resulting {@link CallSite}
 227      *
 228      * @param lookup The {@link MethodHandles.Lookup} used to resolve class names
 229      * @return the {@link CallSite}
 230      * @throws Throwable if any exception is thrown by the bootstrap method
 231      */




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.constant;
  26 
  27 import jdk.internal.lang.annotation.Foldable;
  28 
  29 import java.lang.invoke.CallSite;
  30 import java.lang.invoke.MethodHandle;
  31 import java.lang.invoke.MethodHandles;
  32 import java.util.Arrays;
  33 import java.util.Objects;
  34 import java.util.stream.Stream;
  35 
  36 import static java.lang.constant.ConstantDescs.CD_String;
  37 import static java.lang.constant.ConstantUtils.EMPTY_CONSTANTDESC;
  38 import static java.lang.constant.ConstantUtils.validateMemberName;
  39 import static java.util.Objects.requireNonNull;
  40 import static java.util.stream.Collectors.joining;
  41 
  42 /**
  43  * A <a href="package-summary.html#nominal">nominal descriptor</a> for an
  44  * {@code invokedynamic} call site.
  45  *
  46  * <p>Concrete subtypes of {@linkplain DynamicCallSiteDesc} must be
  47  * <a href="../doc-files/ValueBased.html">value-based</a>.
  48  *


  87 
  88     /**
  89      * Creates a nominal descriptor for an {@code invokedynamic} call site.
  90      *
  91      * @param bootstrapMethod a {@link DirectMethodHandleDesc} describing the
  92      *                        bootstrap method for the {@code invokedynamic}
  93      * @param invocationName The unqualified name that would appear in the {@code NameAndType}
  94      *                       operand of the {@code invokedynamic}
  95      * @param invocationType a {@link MethodTypeDesc} describing the invocation
  96      *                       type that would appear in the {@code NameAndType}
  97      *                       operand of the {@code invokedynamic}
  98      * @param bootstrapArgs {@link ConstantDesc}s describing the static arguments
  99      *                      to the bootstrap, that would appear in the
 100      *                      {@code BootstrapMethods} attribute
 101      * @return the nominal descriptor
 102      * @throws NullPointerException if any parameter is null
 103      * @throws IllegalArgumentException if the invocation name has the incorrect
 104      * format
 105      * @jvms 4.2.2 Unqualified Names
 106      */
 107     @Foldable
 108     public static DynamicCallSiteDesc of(DirectMethodHandleDesc bootstrapMethod,
 109                                          String invocationName,
 110                                          MethodTypeDesc invocationType,
 111                                          ConstantDesc... bootstrapArgs) {
 112         return new DynamicCallSiteDesc(bootstrapMethod, invocationName, invocationType, bootstrapArgs);
 113     }
 114 
 115     /**
 116      * Creates a nominal descriptor for an {@code invokedynamic} call site whose
 117      * bootstrap method has no static arguments.
 118      *
 119      * @param bootstrapMethod The bootstrap method for the {@code invokedynamic}
 120      * @param invocationName The invocationName that would appear in the
 121      * {@code NameAndType} operand of the {@code invokedynamic}
 122      * @param invocationType The invocation invocationType that would appear
 123      * in the {@code NameAndType} operand of the {@code invokedynamic}
 124      * @return the nominal descriptor
 125      * @throws NullPointerException if any parameter is null
 126      * @throws IllegalArgumentException if the invocation name has the incorrect
 127      * format
 128      */
 129     @Foldable
 130     public static DynamicCallSiteDesc of(DirectMethodHandleDesc bootstrapMethod,
 131                                          String invocationName,
 132                                          MethodTypeDesc invocationType) {
 133         return new DynamicCallSiteDesc(bootstrapMethod, invocationName, invocationType, EMPTY_CONSTANTDESC);
 134     }
 135 
 136     /**
 137      * Creates a nominal descriptor for an {@code invokedynamic} call site whose
 138      * bootstrap method has no static arguments and for which the name parameter
 139      * is {@link ConstantDescs#DEFAULT_NAME}.
 140      *
 141      * @param bootstrapMethod a {@link DirectMethodHandleDesc} describing the
 142      *                        bootstrap method for the {@code invokedynamic}
 143      * @param invocationType a {@link MethodTypeDesc} describing the invocation
 144      *                       type that would appear in the {@code NameAndType}
 145      *                       operand of the {@code invokedynamic}
 146      * @return the nominal descriptor
 147      * @throws NullPointerException if any parameter is null
 148      */
 149     @Foldable
 150     public static DynamicCallSiteDesc of(DirectMethodHandleDesc bootstrapMethod,
 151                                          MethodTypeDesc invocationType) {
 152         return of(bootstrapMethod, ConstantDescs.DEFAULT_NAME, invocationType);
 153     }
 154 
 155     /**
 156      * Returns a nominal descriptor for an {@code invokedynamic} call site whose
 157      * bootstrap method, name, and invocation type are the same as this one, but
 158      * with the specified bootstrap arguments.
 159      *
 160      * @param bootstrapArgs {@link ConstantDesc}s describing the static arguments
 161      *                      to the bootstrap, that would appear in the
 162      *                      {@code BootstrapMethods} attribute
 163      * @return the nominal descriptor
 164      * @throws NullPointerException if any parameter is null
 165      */
 166     @Foldable
 167     public DynamicCallSiteDesc withArgs(ConstantDesc... bootstrapArgs) {
 168         return new DynamicCallSiteDesc(bootstrapMethod, invocationName, invocationType, bootstrapArgs);
 169     }
 170 
 171     /**
 172      * Returns a nominal descriptor for an {@code invokedynamic} call site whose
 173      * bootstrap and bootstrap arguments are the same as this one, but with the
 174      * specified invocationName and invocation invocationType
 175      *
 176      * @param invocationName The unqualified name that would appear in the {@code NameAndType}
 177      *                       operand of the {@code invokedynamic}
 178      * @param invocationType a {@link MethodTypeDesc} describing the invocation
 179      *                       type that would appear in the {@code NameAndType}
 180      *                       operand of the {@code invokedynamic}
 181      * @return the nominal descriptor
 182      * @throws NullPointerException if any parameter is null
 183      * @throws IllegalArgumentException if the invocation name has the incorrect
 184      * format
 185      * @jvms 4.2.2 Unqualified Names
 186      */
 187     @Foldable
 188     public DynamicCallSiteDesc withNameAndType(String invocationName,
 189                                                MethodTypeDesc invocationType) {
 190         return new DynamicCallSiteDesc(bootstrapMethod, invocationName, invocationType, bootstrapArgs);
 191     }
 192 
 193     /**
 194      * Returns the invocation name that would appear in the {@code NameAndType}
 195      * operand of the {@code invokedynamic}.
 196      *
 197      * @return the invocation name
 198      */
 199     @Foldable
 200     public String invocationName() {
 201         return invocationName;
 202     }
 203 
 204     /**
 205      * Returns a {@link MethodTypeDesc} describing the invocation type that
 206      * would appear in the {@code NameAndType} operand of the {@code invokedynamic}.
 207      *
 208      * @return the invocation type
 209      */
 210     @Foldable
 211     public MethodTypeDesc invocationType() {
 212         return invocationType;
 213     }
 214 
 215     /**
 216      * Returns a {@link MethodHandleDesc} describing the bootstrap method for
 217      * the {@code invokedynamic}.
 218      *
 219      * @return the bootstrap method for the {@code invokedynamic}
 220      */
 221     @Foldable
 222     public MethodHandleDesc bootstrapMethod() { return bootstrapMethod; }
 223 
 224     /**
 225      * Returns {@link ConstantDesc}s describing the bootstrap arguments for the
 226      * {@code invokedynamic}. The returned array is always non-null. A zero
 227      * length array is returned if this {@linkplain DynamicCallSiteDesc} has no
 228      * bootstrap arguments.
 229      *
 230      * @return the bootstrap arguments for the {@code invokedynamic}
 231      */
 232     public ConstantDesc[] bootstrapArgs() { return bootstrapArgs.clone(); }
 233 
 234     /**
 235      * Reflectively invokes the bootstrap method with the specified arguments,
 236      * and return the resulting {@link CallSite}
 237      *
 238      * @param lookup The {@link MethodHandles.Lookup} used to resolve class names
 239      * @return the {@link CallSite}
 240      * @throws Throwable if any exception is thrown by the bootstrap method
 241      */


< prev index next >