1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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.invoke;
  26 
  27 import java.lang.constant.ConstantDesc;
  28 import java.lang.constant.DynamicCallSiteDesc;
  29 
  30 /**
  31  * Intrinsics
  32  *
  33  * @author Brian Goetz
  34  */
  35 public final class Intrinsics {
  36     /**
  37      * Instructs the compiler to generate an {@code ldc} instruction for the
  38      * constant described by the given {@link ConstantDesc}. A compile-time error
  39      * will be issued if this {@code ConstantRef} is not itself a constant.
  40      *
  41      * @implNote The implementation of this method always throws an
  42      * {@link UnsupportedOperationException} at runtime and therefore cannot be
  43      * called reflectively; invocations of this method should always be
  44      * intrinsified at compile time.
  45      *
  46      * @param constant a nominal descriptor for the constant to be loaded
  47      * @return the constant value
  48      */
  49     public static Object ldc(ConstantDesc constant) {
  50         throw new UnsupportedOperationException("no reflective access");
  51     }
  52 
  53     /**
  54      * Instructs the compiler to generate an {@code invokedynamic} instruction given
  55      * nominal descriptions of a {@link DynamicCallSiteDesc} and a set of boostrap
  56      * arguments. A compile-time error will be issued if the {@link DynamicCallSiteDesc}
  57      * is not itself a constant.
  58      *
  59      * <p>Like {@link MethodHandle.PolymorphicSignature} methods such as
  60      * {@link MethodHandle#invoke(Object...)}, the signature of parameters and
  61      * return value of {@linkplain #invokedynamic(DynamicCallSiteDesc, Object...)}
  62      * is specified as {@linkplain Object}, but the invocation type of the
  63      * {@code invokedynamic} instruction will be derived from the {@code callSiteRef}
  64      * and will not necessarily requiring boxing of arguments and return value.
  65      *
  66      * @implNote The implementation of this method always throws an
  67      * {@link UnsupportedOperationException} at runtime and therefore cannot be
  68      * called reflectively; invocations of this method should always be
  69      * intrinsified at compile time.
  70      *
  71      * @param callSiteRef a nominal descriptor for a dynamic call site
  72      * @param args the dynamic arguments to the {@code invokedynamic} instruction
  73      * @return the result of the invocation
  74      * @throws java.lang.Throwable the targeted method throws any exception
  75      */
  76     public static Object invokedynamic(DynamicCallSiteDesc callSiteRef,
  77                                        Object... args)
  78             throws Throwable {
  79         throw new UnsupportedOperationException("no reflective access");
  80     }
  81 }