jdk/src/share/classes/java/dyn/ConstantCallSite.java
changeset 8823 7cd28219a1e4
parent 8717 f75a1efb1412
parent 8822 8145ab9f5f86
child 8824 0762fa26f813
child 9033 a88f5656f05d
equal deleted inserted replaced
8717:f75a1efb1412 8823:7cd28219a1e4
     1 /*
       
     2  * Copyright (c) 2010, 2011, 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 
       
    26 package java.dyn;
       
    27 
       
    28 /**
       
    29  * A {@code ConstantCallSite} is a {@link CallSite} whose target is permanent, and can never be changed.
       
    30  * An {@code invokedynamic} instruction linked to a {@code ConstantCallSite} is permanently
       
    31  * bound to the call site's target.
       
    32  * @author John Rose, JSR 292 EG
       
    33  */
       
    34 public class ConstantCallSite extends CallSite {
       
    35     /**
       
    36      * Creates a call site with a permanent target.
       
    37      * @param target the target to be permanently associated with this call site
       
    38      * @throws NullPointerException if the proposed target is null
       
    39      */
       
    40     public ConstantCallSite(MethodHandle target) {
       
    41         super(target);
       
    42     }
       
    43 
       
    44     /**
       
    45      * Returns the target method of the call site, which behaves
       
    46      * like a {@code final} field of the {@code ConstantCallSite}.
       
    47      * That is, the the target is always the original value passed
       
    48      * to the constructor call which created this instance.
       
    49      *
       
    50      * @return the immutable linkage state of this call site, a constant method handle
       
    51      * @throws UnsupportedOperationException because this kind of call site cannot change its target
       
    52      */
       
    53     @Override public final MethodHandle getTarget() {
       
    54         return target;
       
    55     }
       
    56 
       
    57     /**
       
    58      * Always throws an {@link UnsupportedOperationException}.
       
    59      * This kind of call site cannot change its target.
       
    60      * @param ignore a new target proposed for the call site, which is ignored
       
    61      * @throws UnsupportedOperationException because this kind of call site cannot change its target
       
    62      */
       
    63     @Override public final void setTarget(MethodHandle ignore) {
       
    64         throw new UnsupportedOperationException("ConstantCallSite");
       
    65     }
       
    66 
       
    67     /**
       
    68      * Returns this call site's permanent target.
       
    69      * Since that target will never change, this is a correct implementation
       
    70      * of {@link CallSite#dynamicInvoker CallSite.dynamicInvoker}.
       
    71      * @return the immutable linkage state of this call site, a constant method handle
       
    72      */
       
    73     @Override
       
    74     public final MethodHandle dynamicInvoker() {
       
    75         return getTarget();
       
    76     }
       
    77 }