8301460: Clean up LambdaForm to reference BasicType enums directly

Reviewed-by: jvernee
This commit is contained in:
Mandy Chung 2023-02-15 18:29:26 +00:00
parent 28f5250fa5
commit 50dcc2aec5
4 changed files with 15 additions and 24 deletions

View File

@ -233,7 +233,7 @@ abstract non-sealed class BoundMethodHandle extends MethodHandle {
/*non-public*/ /*non-public*/
final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) { final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
try { try {
return (BoundMethodHandle) BMH_SPECIES.extendWith(L_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg); return (BoundMethodHandle) BMH_SPECIES.extendWith(L_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
} catch (Throwable ex) { } catch (Throwable ex) {
throw uncaughtException(ex); throw uncaughtException(ex);
} }
@ -242,7 +242,7 @@ abstract non-sealed class BoundMethodHandle extends MethodHandle {
/*non-public*/ /*non-public*/
final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) { final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
try { try {
return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg); return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
} catch (Throwable ex) { } catch (Throwable ex) {
throw uncaughtException(ex); throw uncaughtException(ex);
} }
@ -251,7 +251,7 @@ abstract non-sealed class BoundMethodHandle extends MethodHandle {
/*non-public*/ /*non-public*/
final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) { final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
try { try {
return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg); return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
} catch (Throwable ex) { } catch (Throwable ex) {
throw uncaughtException(ex); throw uncaughtException(ex);
} }
@ -260,7 +260,7 @@ abstract non-sealed class BoundMethodHandle extends MethodHandle {
/*non-public*/ /*non-public*/
final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) { final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
try { try {
return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg); return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
} catch (Throwable ex) { } catch (Throwable ex) {
throw uncaughtException(ex); throw uncaughtException(ex);
} }
@ -269,7 +269,7 @@ abstract non-sealed class BoundMethodHandle extends MethodHandle {
/*non-public*/ /*non-public*/
final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) { final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
try { try {
return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg); return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE).factory().invokeBasic(mt, lf, argL0, narg);
} catch (Throwable ex) { } catch (Throwable ex) {
throw uncaughtException(ex); throw uncaughtException(ex);
} }
@ -319,7 +319,7 @@ abstract non-sealed class BoundMethodHandle extends MethodHandle {
if (whichtm == Specializer.TN_COPY_NO_EXTEND) { if (whichtm == Specializer.TN_COPY_NO_EXTEND) {
return factory(); return factory();
} else if (whichtm < ARG_TYPE_LIMIT) { } else if (whichtm < ARG_TYPE_LIMIT) {
return extendWith((byte) whichtm).factory(); return extendWith(BasicType.basicType((byte) whichtm)).factory();
} else { } else {
throw newInternalError("bad transform"); throw newInternalError("bad transform");
} }
@ -353,10 +353,11 @@ abstract non-sealed class BoundMethodHandle extends MethodHandle {
} }
/*non-public*/ /*non-public*/
SpeciesData extendWith(byte typeNum) { SpeciesData extendWith(BasicType basicType) {
int typeNum = basicType.ordinal();
SpeciesData sd = extensions[typeNum]; SpeciesData sd = extensions[typeNum];
if (sd != null) return sd; if (sd != null) return sd;
sd = SPECIALIZER.findSpecies(key() + BasicType.basicType(typeNum).basicTypeChar()); sd = SPECIALIZER.findSpecies(key() + basicType.basicTypeChar());
extensions[typeNum] = sd; extensions[typeNum] = sd;
return sd; return sd;
} }
@ -406,7 +407,7 @@ abstract non-sealed class BoundMethodHandle extends MethodHandle {
} }
static final List<MemberName> BMH_TRANSFORMS; static final List<MemberName> BMH_TRANSFORMS;
static final int TN_COPY_NO_EXTEND = V_TYPE_NUM; static final int TN_COPY_NO_EXTEND = V_TYPE.ordinal();
static { static {
final Class<BoundMethodHandle> BMH = BoundMethodHandle.class; final Class<BoundMethodHandle> BMH = BoundMethodHandle.class;
// copyWithExtendLIJFD + copyWith // copyWithExtendLIJFD + copyWith

View File

@ -150,16 +150,6 @@ class LambdaForm {
static final int ARG_TYPE_LIMIT = ARG_TYPES.length; static final int ARG_TYPE_LIMIT = ARG_TYPES.length;
static final int TYPE_LIMIT = ALL_TYPES.length; static final int TYPE_LIMIT = ALL_TYPES.length;
// Derived int constants, which (unlike the enums) can be constant folded.
// We can remove them when JDK-8161245 is fixed.
static final byte
L_TYPE_NUM = (byte) L_TYPE.ordinal(),
I_TYPE_NUM = (byte) I_TYPE.ordinal(),
J_TYPE_NUM = (byte) J_TYPE.ordinal(),
F_TYPE_NUM = (byte) F_TYPE.ordinal(),
D_TYPE_NUM = (byte) D_TYPE.ordinal(),
V_TYPE_NUM = (byte) V_TYPE.ordinal();
final char btChar; final char btChar;
final Class<?> btClass; final Class<?> btClass;
final Wrapper btWrapper; final Wrapper btWrapper;

View File

@ -513,7 +513,7 @@ class LambdaFormEditor {
} }
private BoundMethodHandle.SpeciesData newSpeciesData(BasicType type) { private BoundMethodHandle.SpeciesData newSpeciesData(BasicType type) {
return oldSpeciesData().extendWith((byte) type.ordinal()); return oldSpeciesData().extendWith(type);
} }
BoundMethodHandle bindArgumentL(BoundMethodHandle mh, int pos, Object value) { BoundMethodHandle bindArgumentL(BoundMethodHandle mh, int pos, Object value) {

View File

@ -74,7 +74,7 @@ final class SimpleMethodHandle extends BoundMethodHandle {
/*non-public*/ /*non-public*/
final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) { final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
try { try {
return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, narg); return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE).factory().invokeBasic(mt, lf, narg);
} catch (Throwable ex) { } catch (Throwable ex) {
throw uncaughtException(ex); throw uncaughtException(ex);
} }
@ -83,7 +83,7 @@ final class SimpleMethodHandle extends BoundMethodHandle {
/*non-public*/ /*non-public*/
final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) { final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
try { try {
return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, narg); return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE).factory().invokeBasic(mt, lf, narg);
} catch (Throwable ex) { } catch (Throwable ex) {
throw uncaughtException(ex); throw uncaughtException(ex);
} }
@ -92,7 +92,7 @@ final class SimpleMethodHandle extends BoundMethodHandle {
/*non-public*/ /*non-public*/
final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) { final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
try { try {
return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, narg); return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE).factory().invokeBasic(mt, lf, narg);
} catch (Throwable ex) { } catch (Throwable ex) {
throw uncaughtException(ex); throw uncaughtException(ex);
} }
@ -101,7 +101,7 @@ final class SimpleMethodHandle extends BoundMethodHandle {
/*non-public*/ /*non-public*/
final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) { final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
try { try {
return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, narg); return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE).factory().invokeBasic(mt, lf, narg);
} catch (Throwable ex) { } catch (Throwable ex) {
throw uncaughtException(ex); throw uncaughtException(ex);
} }