author | shade |
Tue, 17 May 2016 22:28:00 +0300 | |
changeset 38372 | 017d7578731c |
parent 37792 | dd626e6f5967 |
child 40272 | 6af4511ee5a4 |
permissions | -rw-r--r-- |
36934 | 1 |
/* |
2 |
* Copyright (c) 2014, 2015, 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 java.lang.invoke; |
|
26 |
||
37792 | 27 |
import jdk.internal.vm.annotation.ForceInline; |
36973
951bb58383a4
8151706: Update VarHandle implementation to use @Stable arrays
psandoz
parents:
36934
diff
changeset
|
28 |
import jdk.internal.vm.annotation.Stable; |
951bb58383a4
8151706: Update VarHandle implementation to use @Stable arrays
psandoz
parents:
36934
diff
changeset
|
29 |
|
36934 | 30 |
import java.lang.invoke.VarHandle.AccessMode; |
31 |
import java.lang.reflect.Method; |
|
32 |
import java.lang.reflect.Modifier; |
|
37792 | 33 |
import java.util.ArrayList; |
34 |
import java.util.Arrays; |
|
35 |
import java.util.List; |
|
36934 | 36 |
|
37 |
/** |
|
38 |
* A var handle form containing a set of member name, one for each operation. |
|
39 |
* Each member characterizes a static method. |
|
40 |
*/ |
|
37792 | 41 |
final class VarForm { |
42 |
||
43 |
final @Stable MethodType[] methodType_table; |
|
44 |
||
45 |
final @Stable MemberName[] memberName_table; |
|
46 |
||
47 |
VarForm(Class<?> implClass, Class<?> receiver, Class<?> value, Class<?>... intermediate) { |
|
48 |
this.methodType_table = new MethodType[VarHandle.AccessType.values().length]; |
|
49 |
||
50 |
// TODO lazily calculate |
|
51 |
this.memberName_table = linkFromStatic(implClass); |
|
52 |
||
53 |
// (Receiver, <Intermediates>) |
|
54 |
List<Class<?>> l = new ArrayList<>(); |
|
55 |
if (receiver != null) |
|
56 |
l.add(receiver); |
|
57 |
l.addAll(Arrays.asList(intermediate)); |
|
36934 | 58 |
|
37792 | 59 |
// (Receiver, <Intermediates>)Value |
60 |
methodType_table[VarHandle.AccessType.GET.ordinal()] = |
|
61 |
MethodType.methodType(value, l).erase(); |
|
62 |
||
63 |
// (Receiver, <Intermediates>, Value)void |
|
64 |
l.add(value); |
|
65 |
methodType_table[VarHandle.AccessType.SET.ordinal()] = |
|
66 |
MethodType.methodType(void.class, l).erase(); |
|
36934 | 67 |
|
37792 | 68 |
// (Receiver, <Intermediates>, Value)Value |
69 |
methodType_table[VarHandle.AccessType.GET_AND_UPDATE.ordinal()] = |
|
70 |
MethodType.methodType(value, l).erase(); |
|
36934 | 71 |
|
37792 | 72 |
// (Receiver, <Intermediates>, Value, Value)boolean |
73 |
l.add(value); |
|
74 |
methodType_table[VarHandle.AccessType.COMPARE_AND_SWAP.ordinal()] = |
|
75 |
MethodType.methodType(boolean.class, l).erase(); |
|
76 |
||
77 |
// (Receiver, <Intermediates>, Value, Value)Value |
|
78 |
methodType_table[VarHandle.AccessType.COMPARE_AND_EXCHANGE.ordinal()] = |
|
79 |
MethodType.methodType(value, l).erase(); |
|
36934 | 80 |
} |
81 |
||
37792 | 82 |
@ForceInline |
83 |
final MethodType getMethodType(int type) { |
|
84 |
return methodType_table[type]; |
|
85 |
} |
|
86 |
||
87 |
@ForceInline |
|
88 |
final MemberName getMemberName(int mode) { |
|
89 |
// TODO calculate lazily |
|
90 |
MemberName mn = memberName_table[mode]; |
|
91 |
if (mn == null) { |
|
92 |
throw new UnsupportedOperationException(); |
|
93 |
} |
|
94 |
return mn; |
|
36934 | 95 |
} |
96 |
||
37792 | 97 |
|
98 |
@Stable |
|
99 |
MethodType[] methodType_V_table; |
|
100 |
||
101 |
@ForceInline |
|
102 |
final MethodType[] getMethodType_V_init() { |
|
103 |
MethodType[] table = new MethodType[VarHandle.AccessType.values().length]; |
|
104 |
for (int i = 0; i < methodType_table.length; i++) { |
|
105 |
MethodType mt = methodType_table[i]; |
|
106 |
// TODO only adjust for sig-poly methods returning Object |
|
107 |
table[i] = mt.changeReturnType(void.class); |
|
108 |
} |
|
109 |
methodType_V_table = table; |
|
110 |
return table; |
|
111 |
} |
|
112 |
||
113 |
@ForceInline |
|
114 |
final MethodType getMethodType_V(int type) { |
|
115 |
MethodType[] table = methodType_V_table; |
|
116 |
if (table == null) { |
|
117 |
table = getMethodType_V_init(); |
|
118 |
} |
|
119 |
return table[type]; |
|
120 |
} |
|
121 |
||
122 |
||
36934 | 123 |
/** |
124 |
* Link all signature polymorphic methods. |
|
125 |
*/ |
|
36973
951bb58383a4
8151706: Update VarHandle implementation to use @Stable arrays
psandoz
parents:
36934
diff
changeset
|
126 |
private static MemberName[] linkFromStatic(Class<?> implClass) { |
951bb58383a4
8151706: Update VarHandle implementation to use @Stable arrays
psandoz
parents:
36934
diff
changeset
|
127 |
MemberName[] table = new MemberName[AccessMode.values().length]; |
36934 | 128 |
|
129 |
for (Class<?> c = implClass; c != VarHandle.class; c = c.getSuperclass()) { |
|
130 |
for (Method m : c.getDeclaredMethods()) { |
|
131 |
if (Modifier.isStatic(m.getModifiers())) { |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36973
diff
changeset
|
132 |
AccessMode am = AccessMode.methodNameToAccessMode.get(m.getName()); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36973
diff
changeset
|
133 |
if (am != null) { |
36973
951bb58383a4
8151706: Update VarHandle implementation to use @Stable arrays
psandoz
parents:
36934
diff
changeset
|
134 |
assert table[am.ordinal()] == null; |
951bb58383a4
8151706: Update VarHandle implementation to use @Stable arrays
psandoz
parents:
36934
diff
changeset
|
135 |
table[am.ordinal()] = new MemberName(m); |
951bb58383a4
8151706: Update VarHandle implementation to use @Stable arrays
psandoz
parents:
36934
diff
changeset
|
136 |
} |
36934 | 137 |
} |
138 |
} |
|
139 |
} |
|
36973
951bb58383a4
8151706: Update VarHandle implementation to use @Stable arrays
psandoz
parents:
36934
diff
changeset
|
140 |
return table; |
36934 | 141 |
} |
36973
951bb58383a4
8151706: Update VarHandle implementation to use @Stable arrays
psandoz
parents:
36934
diff
changeset
|
142 |
} |