1.1 --- a/rt/emul/compact/src/main/java/java/lang/invoke/VolatileCallSite.java Sun Aug 17 20:09:05 2014 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,109 +0,0 @@
1.4 -/*
1.5 - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 - *
1.8 - * This code is free software; you can redistribute it and/or modify it
1.9 - * under the terms of the GNU General Public License version 2 only, as
1.10 - * published by the Free Software Foundation. Oracle designates this
1.11 - * particular file as subject to the "Classpath" exception as provided
1.12 - * by Oracle in the LICENSE file that accompanied this code.
1.13 - *
1.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 - * version 2 for more details (a copy is included in the LICENSE file that
1.18 - * accompanied this code).
1.19 - *
1.20 - * You should have received a copy of the GNU General Public License version
1.21 - * 2 along with this work; if not, write to the Free Software Foundation,
1.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 - *
1.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 - * or visit www.oracle.com if you need additional information or have any
1.26 - * questions.
1.27 - */
1.28 -
1.29 -package java.lang.invoke;
1.30 -
1.31 -/**
1.32 - * A {@code VolatileCallSite} is a {@link CallSite} whose target acts like a volatile variable.
1.33 - * An {@code invokedynamic} instruction linked to a {@code VolatileCallSite} sees updates
1.34 - * to its call site target immediately, even if the update occurs in another thread.
1.35 - * There may be a performance penalty for such tight coupling between threads.
1.36 - * <p>
1.37 - * Unlike {@code MutableCallSite}, there is no
1.38 - * {@linkplain MutableCallSite#syncAll syncAll operation} on volatile
1.39 - * call sites, since every write to a volatile variable is implicitly
1.40 - * synchronized with reader threads.
1.41 - * <p>
1.42 - * In other respects, a {@code VolatileCallSite} is interchangeable
1.43 - * with {@code MutableCallSite}.
1.44 - * @see MutableCallSite
1.45 - * @author John Rose, JSR 292 EG
1.46 - */
1.47 -public class VolatileCallSite extends CallSite {
1.48 - /**
1.49 - * Creates a call site with a volatile binding to its target.
1.50 - * The initial target is set to a method handle
1.51 - * of the given type which will throw an {@code IllegalStateException} if called.
1.52 - * @param type the method type that this call site will have
1.53 - * @throws NullPointerException if the proposed type is null
1.54 - */
1.55 - public VolatileCallSite(MethodType type) {
1.56 - super(type);
1.57 - }
1.58 -
1.59 - /**
1.60 - * Creates a call site with a volatile binding to its target.
1.61 - * The target is set to the given value.
1.62 - * @param target the method handle that will be the initial target of the call site
1.63 - * @throws NullPointerException if the proposed target is null
1.64 - */
1.65 - public VolatileCallSite(MethodHandle target) {
1.66 - super(target);
1.67 - }
1.68 -
1.69 - /**
1.70 - * Returns the target method of the call site, which behaves
1.71 - * like a {@code volatile} field of the {@code VolatileCallSite}.
1.72 - * <p>
1.73 - * The interactions of {@code getTarget} with memory are the same
1.74 - * as of a read from a {@code volatile} field.
1.75 - * <p>
1.76 - * In particular, the current thread is required to issue a fresh
1.77 - * read of the target from memory, and must not fail to see
1.78 - * a recent update to the target by another thread.
1.79 - *
1.80 - * @return the linkage state of this call site, a method handle which can change over time
1.81 - * @see #setTarget
1.82 - */
1.83 - @Override public final MethodHandle getTarget() {
1.84 - return getTargetVolatile();
1.85 - }
1.86 -
1.87 - /**
1.88 - * Updates the target method of this call site, as a volatile variable.
1.89 - * The type of the new target must agree with the type of the old target.
1.90 - * <p>
1.91 - * The interactions with memory are the same as of a write to a volatile field.
1.92 - * In particular, any threads is guaranteed to see the updated target
1.93 - * the next time it calls {@code getTarget}.
1.94 - * @param newTarget the new target
1.95 - * @throws NullPointerException if the proposed new target is null
1.96 - * @throws WrongMethodTypeException if the proposed new target
1.97 - * has a method type that differs from the previous target
1.98 - * @see #getTarget
1.99 - */
1.100 - @Override public void setTarget(MethodHandle newTarget) {
1.101 - checkTargetChange(getTargetVolatile(), newTarget);
1.102 - setTargetVolatile(newTarget);
1.103 - }
1.104 -
1.105 - /**
1.106 - * {@inheritDoc}
1.107 - */
1.108 - @Override
1.109 - public final MethodHandle dynamicInvoker() {
1.110 - return makeDynamicInvoker();
1.111 - }
1.112 -}