Skip to content

Commit 50dcc2a

Browse files
author
Mandy Chung
committed
8301460: Clean up LambdaForm to reference BasicType enums directly
Reviewed-by: jvernee
1 parent 28f5250 commit 50dcc2a

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ final BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
233233
/*non-public*/
234234
final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
235235
try {
236-
return (BoundMethodHandle) BMH_SPECIES.extendWith(L_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
236+
return (BoundMethodHandle) BMH_SPECIES.extendWith(L_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
237237
} catch (Throwable ex) {
238238
throw uncaughtException(ex);
239239
}
@@ -242,7 +242,7 @@ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object nar
242242
/*non-public*/
243243
final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
244244
try {
245-
return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
245+
return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
246246
} catch (Throwable ex) {
247247
throw uncaughtException(ex);
248248
}
@@ -251,7 +251,7 @@ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg)
251251
/*non-public*/
252252
final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
253253
try {
254-
return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
254+
return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
255255
} catch (Throwable ex) {
256256
throw uncaughtException(ex);
257257
}
@@ -260,7 +260,7 @@ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg)
260260
/*non-public*/
261261
final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
262262
try {
263-
return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
263+
return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
264264
} catch (Throwable ex) {
265265
throw uncaughtException(ex);
266266
}
@@ -269,7 +269,7 @@ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg
269269
/*non-public*/
270270
final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
271271
try {
272-
return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
272+
return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
273273
} catch (Throwable ex) {
274274
throw uncaughtException(ex);
275275
}
@@ -319,7 +319,7 @@ protected MethodHandle deriveTransformHelper(MemberName transform, int whichtm)
319319
if (whichtm == Specializer.TN_COPY_NO_EXTEND) {
320320
return factory();
321321
} else if (whichtm < ARG_TYPE_LIMIT) {
322-
return extendWith((byte) whichtm).factory();
322+
return extendWith(BasicType.basicType((byte) whichtm)).factory();
323323
} else {
324324
throw newInternalError("bad transform");
325325
}
@@ -353,10 +353,11 @@ private boolean verifyTHAargs(MemberName transform, int whichtm, List<?> args, L
353353
}
354354

355355
/*non-public*/
356-
SpeciesData extendWith(byte typeNum) {
356+
SpeciesData extendWith(BasicType basicType) {
357+
int typeNum = basicType.ordinal();
357358
SpeciesData sd = extensions[typeNum];
358359
if (sd != null) return sd;
359-
sd = SPECIALIZER.findSpecies(key() + BasicType.basicType(typeNum).basicTypeChar());
360+
sd = SPECIALIZER.findSpecies(key() + basicType.basicTypeChar());
360361
extensions[typeNum] = sd;
361362
return sd;
362363
}
@@ -406,7 +407,7 @@ protected BoundMethodHandle.SpeciesData newSpeciesData(String key) {
406407
}
407408

408409
static final List<MemberName> BMH_TRANSFORMS;
409-
static final int TN_COPY_NO_EXTEND = V_TYPE_NUM;
410+
static final int TN_COPY_NO_EXTEND = V_TYPE.ordinal();
410411
static {
411412
final Class<BoundMethodHandle> BMH = BoundMethodHandle.class;
412413
// copyWithExtendLIJFD + copyWith

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,6 @@ enum BasicType {
150150
static final int ARG_TYPE_LIMIT = ARG_TYPES.length;
151151
static final int TYPE_LIMIT = ALL_TYPES.length;
152152

153-
// Derived int constants, which (unlike the enums) can be constant folded.
154-
// We can remove them when JDK-8161245 is fixed.
155-
static final byte
156-
L_TYPE_NUM = (byte) L_TYPE.ordinal(),
157-
I_TYPE_NUM = (byte) I_TYPE.ordinal(),
158-
J_TYPE_NUM = (byte) J_TYPE.ordinal(),
159-
F_TYPE_NUM = (byte) F_TYPE.ordinal(),
160-
D_TYPE_NUM = (byte) D_TYPE.ordinal(),
161-
V_TYPE_NUM = (byte) V_TYPE.ordinal();
162-
163153
final char btChar;
164154
final Class<?> btClass;
165155
final Wrapper btWrapper;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ private BoundMethodHandle.SpeciesData oldSpeciesData() {
513513
}
514514

515515
private BoundMethodHandle.SpeciesData newSpeciesData(BasicType type) {
516-
return oldSpeciesData().extendWith((byte) type.ordinal());
516+
return oldSpeciesData().extendWith(type);
517517
}
518518

519519
BoundMethodHandle bindArgumentL(BoundMethodHandle mh, int pos, Object value) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object nar
7474
/*non-public*/
7575
final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
7676
try {
77-
return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
77+
return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE).factory().invokeBasic(mt, lf, narg);
7878
} catch (Throwable ex) {
7979
throw uncaughtException(ex);
8080
}
@@ -83,7 +83,7 @@ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg)
8383
/*non-public*/
8484
final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
8585
try {
86-
return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
86+
return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE).factory().invokeBasic(mt, lf, narg);
8787
} catch (Throwable ex) {
8888
throw uncaughtException(ex);
8989
}
@@ -92,7 +92,7 @@ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg)
9292
/*non-public*/
9393
final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
9494
try {
95-
return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
95+
return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE).factory().invokeBasic(mt, lf, narg);
9696
} catch (Throwable ex) {
9797
throw uncaughtException(ex);
9898
}
@@ -101,7 +101,7 @@ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg
101101
/*non-public*/
102102
final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
103103
try {
104-
return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
104+
return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE).factory().invokeBasic(mt, lf, narg);
105105
} catch (Throwable ex) {
106106
throw uncaughtException(ex);
107107
}

0 commit comments

Comments
 (0)