author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 8822 | jdk/src/share/classes/java/lang/invoke/VolatileCallSite.java@8145ab9f5f86 |
child 44255 | 515cf13d7791 |
permissions | -rw-r--r-- |
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:
8821
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 |
/** |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
29 |
* A {@code VolatileCallSite} is a {@link CallSite} whose target acts like a volatile variable. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
30 |
* An {@code invokedynamic} instruction linked to a {@code VolatileCallSite} sees updates |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
31 |
* to its call site target immediately, even if the update occurs in another thread. |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
32 |
* There may be a performance penalty for such tight coupling between threads. |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
33 |
* <p> |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
34 |
* Unlike {@code MutableCallSite}, there is no |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
35 |
* {@linkplain MutableCallSite#syncAll syncAll operation} on volatile |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
36 |
* call sites, since every write to a volatile variable is implicitly |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
37 |
* synchronized with reader threads. |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
38 |
* <p> |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
39 |
* In other respects, a {@code VolatileCallSite} is interchangeable |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
40 |
* with {@code MutableCallSite}. |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
41 |
* @see MutableCallSite |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff
changeset
|
42 |
* @author John Rose, JSR 292 EG |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff
changeset
|
43 |
*/ |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
44 |
public class VolatileCallSite extends CallSite { |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
45 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
46 |
* Creates a call site with a volatile binding to its target. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
47 |
* The initial target is set to a method handle |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
48 |
* of the given type which will throw an {@code IllegalStateException} if called. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
49 |
* @param type the method type that this call site will have |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
50 |
* @throws NullPointerException if the proposed type is null |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
51 |
*/ |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
52 |
public VolatileCallSite(MethodType type) { |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
53 |
super(type); |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
54 |
} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
55 |
|
8346
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 |
* Creates a call site with a volatile binding to its target. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
58 |
* The target is set to the given value. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
59 |
* @param target the method handle that will be the initial target of the call site |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
60 |
* @throws NullPointerException if the proposed target is null |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
61 |
*/ |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
62 |
public VolatileCallSite(MethodHandle target) { |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff
changeset
|
63 |
super(target); |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
64 |
} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
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 |
* 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
|
68 |
* like a {@code volatile} field of the {@code VolatileCallSite}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
69 |
* <p> |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
70 |
* The interactions of {@code getTarget} with memory are the same |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
71 |
* as of a read from a {@code volatile} field. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
72 |
* <p> |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
73 |
* In particular, the current thread is required to issue a fresh |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
74 |
* read of the target from memory, and must not fail to see |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
75 |
* a recent update to the target by another thread. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
76 |
* |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
77 |
* @return the linkage state of this call site, a method handle which can change over time |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
78 |
* @see #setTarget |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
79 |
*/ |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
80 |
@Override public final MethodHandle getTarget() { |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
81 |
return getTargetVolatile(); |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff
changeset
|
82 |
} |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
83 |
|
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
84 |
/** |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
85 |
* Updates the target method of this call site, as a volatile variable. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
86 |
* The type of the new target must agree with the type of the old target. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
87 |
* <p> |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
88 |
* The interactions with memory are the same as of a write to a volatile field. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
89 |
* In particular, any threads is guaranteed to see the updated target |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
90 |
* the next time it calls {@code getTarget}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
91 |
* @param newTarget the new target |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
92 |
* @throws NullPointerException if the proposed new target is null |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
93 |
* @throws WrongMethodTypeException if the proposed new target |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
94 |
* has a method type that differs from the previous target |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
95 |
* @see #getTarget |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
96 |
*/ |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
97 |
@Override public void setTarget(MethodHandle newTarget) { |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
98 |
checkTargetChange(getTargetVolatile(), newTarget); |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
99 |
setTargetVolatile(newTarget); |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
100 |
} |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
101 |
|
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
102 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
103 |
* {@inheritDoc} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
104 |
*/ |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
105 |
@Override |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
106 |
public final MethodHandle dynamicInvoker() { |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
107 |
return makeDynamicInvoker(); |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7562
diff
changeset
|
108 |
} |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff
changeset
|
109 |
} |