jdk/src/share/classes/java/lang/invoke/ConstantCallSite.java
author jrose
Wed, 23 Mar 2011 23:02:31 -0700
changeset 8822 8145ab9f5f86
parent 8346 jdk/src/share/classes/java/dyn/ConstantCallSite.java@3b891698c4ec
child 9752 88ab34b6da6d
permissions -rw-r--r--
7012648: move JSR 292 to package java.lang.invoke and adjust names Summary: package and class renaming only; delete unused methods and classes; add @since tags; no code changes Reviewed-by: twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7051
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     1
/*
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
     2
 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
7051
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     4
 *
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    10
 *
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    15
 * accompanied this code).
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    16
 *
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    20
 *
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    23
 * questions.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    24
 */
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    25
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8346
diff changeset
    26
package java.lang.invoke;
7051
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    27
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    28
/**
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    29
 * A {@code ConstantCallSite} is a {@link CallSite} whose target is permanent, and can never be changed.
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7051
diff changeset
    30
 * An {@code invokedynamic} instruction linked to a {@code ConstantCallSite} is permanently
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7051
diff changeset
    31
 * bound to the call site's target.
7051
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    32
 * @author John Rose, JSR 292 EG
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    33
 */
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    34
public class ConstantCallSite extends CallSite {
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    35
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    36
     * Creates a call site with a permanent target.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    37
     * @param target the target to be permanently associated with this call site
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    38
     * @throws NullPointerException if the proposed target is null
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    39
     */
7051
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    40
    public ConstantCallSite(MethodHandle target) {
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    41
        super(target);
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    42
    }
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    43
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7051
diff changeset
    44
    /**
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    45
     * Returns the target method of the call site, which behaves
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    46
     * like a {@code final} field of the {@code ConstantCallSite}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    47
     * That is, the the target is always the original value passed
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    48
     * to the constructor call which created this instance.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    49
     *
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    50
     * @return the immutable linkage state of this call site, a constant method handle
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    51
     * @throws UnsupportedOperationException because this kind of call site cannot change its target
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    52
     */
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    53
    @Override public final MethodHandle getTarget() {
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    54
        return target;
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    55
    }
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    56
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    57
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    58
     * Always throws an {@link UnsupportedOperationException}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    59
     * This kind of call site cannot change its target.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    60
     * @param ignore a new target proposed for the call site, which is ignored
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    61
     * @throws UnsupportedOperationException because this kind of call site cannot change its target
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7051
diff changeset
    62
     */
7051
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    63
    @Override public final void setTarget(MethodHandle ignore) {
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    64
        throw new UnsupportedOperationException("ConstantCallSite");
7051
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    65
    }
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    66
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    67
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    68
     * Returns this call site's permanent target.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    69
     * Since that target will never change, this is a correct implementation
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    70
     * of {@link CallSite#dynamicInvoker CallSite.dynamicInvoker}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    71
     * @return the immutable linkage state of this call site, a constant method handle
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    72
     */
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    73
    @Override
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    74
    public final MethodHandle dynamicInvoker() {
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    75
        return getTarget();
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7562
diff changeset
    76
    }
7051
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    77
}