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 jdk.internal.lang.annotation;
  26 
  27 import java.lang.annotation.*;
  28 
  29 import java.lang.constant.Constable;
  30 import java.lang.constant.ConstantDesc;
  31 import java.lang.invoke.Intrinsics;
  32 
  33 /**
  34  * Identifies a method that is a candidate for compile-time constant folding.
  35  * Such a method must be a <em>pure function</em> of its inputs, all inputs
  36  * (including the receiver, if applied to an instance method) must be value-based
  37  * types, and the output must be a value-based type that is representable
  38  * in the constant pool ({@link Constable} or {@link ConstantDesc}).
  39  *
  40  * <p>For accesses of fields annotated as {@linkplain Foldable}, and invocations
  41  * of methods annotated as {@linkplain Foldable} whose arguments (and, for instance
  42  * methods, the receiver) are all constant expressions, the compiler may evaluate
  43  * the expression reflectively at compile time and replace it with a constant
  44  * load of the result, or track the result as a constant expression for possible
  45  * intrinsification via methods in {@link Intrinsics}.
  46  *
  47  * @see Constable
  48  * @see ConstantDesc
  49  * @see Intrinsics
  50  */
  51 @Retention(RetentionPolicy.CLASS)
  52 @Target({ ElementType.METHOD, ElementType.FIELD })
  53 public @interface Foldable { }