25
25
26
26
package java .lang .invoke ;
27
27
28
- import jdk .internal .vm .annotation .Stable ;
29
28
import sun .invoke .util .Wrapper ;
30
29
31
30
import java .lang .ref .SoftReference ;
@@ -52,7 +51,8 @@ final class MethodTypeForm {
52
51
final MethodType basicType ; // the canonical erasure, with primitives simplified
53
52
54
53
// Cached adapter information:
55
- @ Stable final SoftReference <MethodHandle >[] methodHandles ;
54
+ final SoftReference <MethodHandle >[] methodHandles ;
55
+
56
56
// Indexes into methodHandles:
57
57
static final int
58
58
MH_BASIC_INV = 0 , // cached instance of MH.invokeBasic
@@ -61,7 +61,8 @@ final class MethodTypeForm {
61
61
MH_LIMIT = 3 ;
62
62
63
63
// Cached lambda form information, for basic types only:
64
- final @ Stable SoftReference <LambdaForm >[] lambdaForms ;
64
+ final SoftReference <LambdaForm >[] lambdaForms ;
65
+
65
66
// Indexes into lambdaForms:
66
67
static final int
67
68
LF_INVVIRTUAL = 0 , // DMH invokeVirtual
@@ -103,15 +104,7 @@ public MethodType basicType() {
103
104
return basicType ;
104
105
}
105
106
106
- private boolean assertIsBasicType () {
107
- // primitives must be flattened also
108
- assert (erasedType == basicType )
109
- : "erasedType: " + erasedType + " != basicType: " + basicType ;
110
- return true ;
111
- }
112
-
113
107
public MethodHandle cachedMethodHandle (int which ) {
114
- assert (assertIsBasicType ());
115
108
SoftReference <MethodHandle > entry = methodHandles [which ];
116
109
return (entry != null ) ? entry .get () : null ;
117
110
}
@@ -130,7 +123,6 @@ public synchronized MethodHandle setCachedMethodHandle(int which, MethodHandle m
130
123
}
131
124
132
125
public LambdaForm cachedLambdaForm (int which ) {
133
- assert (assertIsBasicType ());
134
126
SoftReference <LambdaForm > entry = lambdaForms [which ];
135
127
return (entry != null ) ? entry .get () : null ;
136
128
}
@@ -162,59 +154,57 @@ protected MethodTypeForm(MethodType erasedType) {
162
154
163
155
// Walk the argument types, looking for primitives.
164
156
short primitiveCount = 0 , longArgCount = 0 ;
165
- Class <?>[] epts = ptypes ;
166
- Class <?>[] bpts = epts ;
167
- for (int i = 0 ; i < epts .length ; i ++) {
168
- Class <?> pt = epts [i ];
169
- if (pt != Object .class ) {
157
+ Class <?>[] erasedPtypes = ptypes ;
158
+ Class <?>[] basicPtypes = erasedPtypes ;
159
+ for (int i = 0 ; i < erasedPtypes .length ; i ++) {
160
+ Class <?> ptype = erasedPtypes [i ];
161
+ if (ptype != Object .class ) {
170
162
++primitiveCount ;
171
- Wrapper w = Wrapper .forPrimitiveType (pt );
163
+ Wrapper w = Wrapper .forPrimitiveType (ptype );
172
164
if (w .isDoubleWord ()) ++longArgCount ;
173
- if (w .isSubwordOrInt () && pt != int .class ) {
174
- if (bpts == epts )
175
- bpts = bpts .clone ();
176
- bpts [i ] = int .class ;
165
+ if (w .isSubwordOrInt () && ptype != int .class ) {
166
+ if (basicPtypes == erasedPtypes )
167
+ basicPtypes = basicPtypes .clone ();
168
+ basicPtypes [i ] = int .class ;
177
169
}
178
170
}
179
171
}
180
172
pslotCount += longArgCount ; // #slots = #args + #longs
181
- Class <?> rt = erasedType .returnType ();
182
- Class <?> bt = rt ;
183
- if (rt != Object .class ) {
173
+ Class <?> returnType = erasedType .returnType ();
174
+ Class <?> basicReturnType = returnType ;
175
+ if (returnType != Object .class ) {
184
176
++primitiveCount ; // even void.class counts as a prim here
185
- Wrapper w = Wrapper .forPrimitiveType (rt );
186
- if (w .isSubwordOrInt () && rt != int .class )
187
- bt = int .class ;
177
+ Wrapper w = Wrapper .forPrimitiveType (returnType );
178
+ if (w .isSubwordOrInt () && returnType != int .class )
179
+ basicReturnType = int .class ;
188
180
}
189
- if (epts == bpts && bt == rt ) {
181
+ if (erasedPtypes == basicPtypes && basicReturnType == returnType ) {
182
+ // Basic type
190
183
this .basicType = erasedType ;
184
+
185
+ if (pslotCount >= 256 ) throw newIllegalArgumentException ("too many arguments" );
186
+
187
+ this .primitiveCount = primitiveCount ;
188
+ this .parameterSlotCount = (short )pslotCount ;
189
+ this .lambdaForms = new SoftReference [LF_LIMIT ];
190
+ this .methodHandles = new SoftReference [MH_LIMIT ];
191
191
} else {
192
- this .basicType = MethodType .makeImpl (bt , bpts , true );
192
+ this .basicType = MethodType .makeImpl (basicReturnType , basicPtypes , true );
193
193
// fill in rest of data from the basic type:
194
194
MethodTypeForm that = this .basicType .form ();
195
195
assert (this != that );
196
+
196
197
this .parameterSlotCount = that .parameterSlotCount ;
197
198
this .primitiveCount = that .primitiveCount ;
198
199
this .methodHandles = null ;
199
200
this .lambdaForms = null ;
200
- return ;
201
201
}
202
-
203
- if (pslotCount >= 256 ) throw newIllegalArgumentException ("too many arguments" );
204
-
205
- this .primitiveCount = primitiveCount ;
206
- this .parameterSlotCount = (short )pslotCount ;
207
-
208
- // Initialize caches, but only for basic types
209
- assert (basicType == erasedType );
210
- this .lambdaForms = new SoftReference [LF_LIMIT ];
211
- this .methodHandles = new SoftReference [MH_LIMIT ];
212
202
}
213
203
214
- public int parameterCount () { // # outgoing values
204
+ public int parameterCount () {
215
205
return erasedType .parameterCount ();
216
206
}
217
- public int parameterSlotCount () { // # outgoing interpreter slots
207
+ public int parameterSlotCount () {
218
208
return parameterSlotCount ;
219
209
}
220
210
public boolean hasPrimitives () {
@@ -250,17 +240,17 @@ static MethodTypeForm findForm(MethodType mt) {
250
240
*/
251
241
public static MethodType canonicalize (MethodType mt , int howRet , int howArgs ) {
252
242
Class <?>[] ptypes = mt .ptypes ();
253
- Class <?>[] ptc = canonicalizeAll (ptypes , howArgs );
243
+ Class <?>[] ptypesCanonical = canonicalizeAll (ptypes , howArgs );
254
244
Class <?> rtype = mt .returnType ();
255
- Class <?> rtc = canonicalize (rtype , howRet );
256
- if (ptc == null && rtc == null ) {
245
+ Class <?> rtypeCanonical = canonicalize (rtype , howRet );
246
+ if (ptypesCanonical == null && rtypeCanonical == null ) {
257
247
// It is already canonical.
258
248
return null ;
259
249
}
260
250
// Find the erased version of the method type:
261
- if (rtc == null ) rtc = rtype ;
262
- if (ptc == null ) ptc = ptypes ;
263
- return MethodType .makeImpl (rtc , ptc , true );
251
+ if (rtypeCanonical == null ) rtypeCanonical = rtype ;
252
+ if (ptypesCanonical == null ) ptypesCanonical = ptypes ;
253
+ return MethodType .makeImpl (rtypeCanonical , ptypesCanonical , true );
264
254
}
265
255
266
256
/** Canonicalize the given return or param type.
0 commit comments