Skip to content

Commit 52f9024

Browse files
committed
8230768: Arrays of SoftReferences in MethodTypeForm should not be @stable
Reviewed-by: mchung
1 parent 2f67784 commit 52f9024

File tree

1 file changed

+39
-49
lines changed

1 file changed

+39
-49
lines changed

src/java.base/share/classes/java/lang/invoke/MethodTypeForm.java

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
package java.lang.invoke;
2727

28-
import jdk.internal.vm.annotation.Stable;
2928
import sun.invoke.util.Wrapper;
3029

3130
import java.lang.ref.SoftReference;
@@ -52,7 +51,8 @@ final class MethodTypeForm {
5251
final MethodType basicType; // the canonical erasure, with primitives simplified
5352

5453
// Cached adapter information:
55-
@Stable final SoftReference<MethodHandle>[] methodHandles;
54+
final SoftReference<MethodHandle>[] methodHandles;
55+
5656
// Indexes into methodHandles:
5757
static final int
5858
MH_BASIC_INV = 0, // cached instance of MH.invokeBasic
@@ -61,7 +61,8 @@ final class MethodTypeForm {
6161
MH_LIMIT = 3;
6262

6363
// Cached lambda form information, for basic types only:
64-
final @Stable SoftReference<LambdaForm>[] lambdaForms;
64+
final SoftReference<LambdaForm>[] lambdaForms;
65+
6566
// Indexes into lambdaForms:
6667
static final int
6768
LF_INVVIRTUAL = 0, // DMH invokeVirtual
@@ -103,15 +104,7 @@ public MethodType basicType() {
103104
return basicType;
104105
}
105106

106-
private boolean assertIsBasicType() {
107-
// primitives must be flattened also
108-
assert(erasedType == basicType)
109-
: "erasedType: " + erasedType + " != basicType: " + basicType;
110-
return true;
111-
}
112-
113107
public MethodHandle cachedMethodHandle(int which) {
114-
assert(assertIsBasicType());
115108
SoftReference<MethodHandle> entry = methodHandles[which];
116109
return (entry != null) ? entry.get() : null;
117110
}
@@ -130,7 +123,6 @@ public synchronized MethodHandle setCachedMethodHandle(int which, MethodHandle m
130123
}
131124

132125
public LambdaForm cachedLambdaForm(int which) {
133-
assert(assertIsBasicType());
134126
SoftReference<LambdaForm> entry = lambdaForms[which];
135127
return (entry != null) ? entry.get() : null;
136128
}
@@ -162,59 +154,57 @@ protected MethodTypeForm(MethodType erasedType) {
162154

163155
// Walk the argument types, looking for primitives.
164156
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) {
170162
++primitiveCount;
171-
Wrapper w = Wrapper.forPrimitiveType(pt);
163+
Wrapper w = Wrapper.forPrimitiveType(ptype);
172164
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;
177169
}
178170
}
179171
}
180172
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) {
184176
++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;
188180
}
189-
if (epts == bpts && bt == rt) {
181+
if (erasedPtypes == basicPtypes && basicReturnType == returnType) {
182+
// Basic type
190183
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];
191191
} else {
192-
this.basicType = MethodType.makeImpl(bt, bpts, true);
192+
this.basicType = MethodType.makeImpl(basicReturnType, basicPtypes, true);
193193
// fill in rest of data from the basic type:
194194
MethodTypeForm that = this.basicType.form();
195195
assert(this != that);
196+
196197
this.parameterSlotCount = that.parameterSlotCount;
197198
this.primitiveCount = that.primitiveCount;
198199
this.methodHandles = null;
199200
this.lambdaForms = null;
200-
return;
201201
}
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];
212202
}
213203

214-
public int parameterCount() { // # outgoing values
204+
public int parameterCount() {
215205
return erasedType.parameterCount();
216206
}
217-
public int parameterSlotCount() { // # outgoing interpreter slots
207+
public int parameterSlotCount() {
218208
return parameterSlotCount;
219209
}
220210
public boolean hasPrimitives() {
@@ -250,17 +240,17 @@ static MethodTypeForm findForm(MethodType mt) {
250240
*/
251241
public static MethodType canonicalize(MethodType mt, int howRet, int howArgs) {
252242
Class<?>[] ptypes = mt.ptypes();
253-
Class<?>[] ptc = canonicalizeAll(ptypes, howArgs);
243+
Class<?>[] ptypesCanonical = canonicalizeAll(ptypes, howArgs);
254244
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) {
257247
// It is already canonical.
258248
return null;
259249
}
260250
// 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);
264254
}
265255

266256
/** Canonicalize the given return or param type.

0 commit comments

Comments
 (0)