Skip to content

Commit

Permalink
8301460: Clean up LambdaForm to reference BasicType enums directly
Browse files Browse the repository at this point in the history
Reviewed-by: jvernee
  • Loading branch information
Mandy Chung committed Feb 15, 2023
1 parent 28f5250 commit 50dcc2a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
Expand Up @@ -233,7 +233,7 @@ final BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
/*non-public*/
final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
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) {
throw uncaughtException(ex);
}
Expand All @@ -242,7 +242,7 @@ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object nar
/*non-public*/
final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
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) {
throw uncaughtException(ex);
}
Expand All @@ -251,7 +251,7 @@ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg)
/*non-public*/
final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
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) {
throw uncaughtException(ex);
}
Expand All @@ -260,7 +260,7 @@ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg)
/*non-public*/
final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
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) {
throw uncaughtException(ex);
}
Expand All @@ -269,7 +269,7 @@ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg
/*non-public*/
final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
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) {
throw uncaughtException(ex);
}
Expand Down Expand Up @@ -319,7 +319,7 @@ protected MethodHandle deriveTransformHelper(MemberName transform, int whichtm)
if (whichtm == Specializer.TN_COPY_NO_EXTEND) {
return factory();
} else if (whichtm < ARG_TYPE_LIMIT) {
return extendWith((byte) whichtm).factory();
return extendWith(BasicType.basicType((byte) whichtm)).factory();
} else {
throw newInternalError("bad transform");
}
Expand Down Expand Up @@ -353,10 +353,11 @@ private boolean verifyTHAargs(MemberName transform, int whichtm, List<?> args, L
}

/*non-public*/
SpeciesData extendWith(byte typeNum) {
SpeciesData extendWith(BasicType basicType) {
int typeNum = basicType.ordinal();
SpeciesData sd = extensions[typeNum];
if (sd != null) return sd;
sd = SPECIALIZER.findSpecies(key() + BasicType.basicType(typeNum).basicTypeChar());
sd = SPECIALIZER.findSpecies(key() + basicType.basicTypeChar());
extensions[typeNum] = sd;
return sd;
}
Expand Down Expand Up @@ -406,7 +407,7 @@ protected BoundMethodHandle.SpeciesData newSpeciesData(String key) {
}

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 {
final Class<BoundMethodHandle> BMH = BoundMethodHandle.class;
// copyWithExtendLIJFD + copyWith
Expand Down
10 changes: 0 additions & 10 deletions src/java.base/share/classes/java/lang/invoke/LambdaForm.java
Expand Up @@ -150,16 +150,6 @@ enum BasicType {
static final int ARG_TYPE_LIMIT = ARG_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 Class<?> btClass;
final Wrapper btWrapper;
Expand Down
Expand Up @@ -513,7 +513,7 @@ private BoundMethodHandle.SpeciesData oldSpeciesData() {
}

private BoundMethodHandle.SpeciesData newSpeciesData(BasicType type) {
return oldSpeciesData().extendWith((byte) type.ordinal());
return oldSpeciesData().extendWith(type);
}

BoundMethodHandle bindArgumentL(BoundMethodHandle mh, int pos, Object value) {
Expand Down
Expand Up @@ -74,7 +74,7 @@ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object nar
/*non-public*/
final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
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) {
throw uncaughtException(ex);
}
Expand All @@ -83,7 +83,7 @@ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg)
/*non-public*/
final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
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) {
throw uncaughtException(ex);
}
Expand All @@ -92,7 +92,7 @@ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg)
/*non-public*/
final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
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) {
throw uncaughtException(ex);
}
Expand All @@ -101,7 +101,7 @@ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg
/*non-public*/
final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
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) {
throw uncaughtException(ex);
}
Expand Down

1 comment on commit 50dcc2a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.