Skip to content

Commit

Permalink
Simplify SimpleVerificationTypeInfo's constant names
Browse files Browse the repository at this point in the history
  • Loading branch information
liach committed Aug 29, 2024
1 parent a940a85 commit 6d8accd
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,31 @@ public static StackMapFrameInfo of(Label target,
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
sealed interface VerificationTypeInfo {

/** The {@link #tag() tag} for verification type info TOP. */
/** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#TOP TOP}. */
int VT_TOP = 0;

/** The {@link #tag() tag} for verification type info INTEGER. */
/** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#INTEGER INTEGER}. */
int VT_INTEGER = 1;

/** The {@link #tag() tag} for verification type info FLOAT. */
/** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#FLOAT FLOAT}. */
int VT_FLOAT = 2;

/** The {@link #tag() tag} for verification type info DOUBLE. */
/** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#DOUBLE DOUBLE}. */
int VT_DOUBLE = 3;

/** The {@link #tag() tag} for verification type info LONG. */
/** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#LONG LONG}. */
int VT_LONG = 4;

/** The {@link #tag() tag} for verification type info NULL. */
/** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#NULL NULL}. */
int VT_NULL = 5;

/** The {@link #tag() tag} for verification type info UNINITIALIZED_THIS. */
/** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#UNINITIALIZED_THIS UNINITIALIZED_THIS}. */
int VT_UNINITIALIZED_THIS = 6;

/** The {@link #tag() tag} for verification type info OBJECT. */
/** The {@link #tag() tag} for verification type info {@link ObjectVerificationTypeInfo OBJECT}. */
int VT_OBJECT = 7;

/** The {@link #tag() tag} for verification type info UNINITIALIZED. */
/** The {@link #tag() tag} for verification type info {@link UninitializedVerificationTypeInfo UNINITIALIZED}. */
int VT_UNINITIALIZED = 8;

/**
Expand All @@ -126,25 +126,25 @@ sealed interface VerificationTypeInfo {
public enum SimpleVerificationTypeInfo implements VerificationTypeInfo {

/** verification type top */
ITEM_TOP(VT_TOP),
TOP(VT_TOP),

/** verification type int */
ITEM_INTEGER(VT_INTEGER),
INTEGER(VT_INTEGER),

/** verification type float */
ITEM_FLOAT(VT_FLOAT),
FLOAT(VT_FLOAT),

/** verification type double */
ITEM_DOUBLE(VT_DOUBLE),
DOUBLE(VT_DOUBLE),

/** verification type long */
ITEM_LONG(VT_LONG),
LONG(VT_LONG),

/** verification type null */
ITEM_NULL(VT_NULL),
NULL(VT_NULL),

/** verification type uninitializedThis */
ITEM_UNINITIALIZED_THIS(VT_UNINITIALIZED_THIS);
UNINITIALIZED_THIS(VT_UNINITIALIZED_THIS);


private final int tag;
Expand All @@ -160,7 +160,7 @@ public int tag() {
}

/**
* A stack value for an object type.
* A stack value for an object type. Its {@link #tag() tag} is {@value #VT_OBJECT}.
*
* @since 22
*/
Expand Down Expand Up @@ -199,7 +199,7 @@ default ClassDesc classSymbol() {
}

/**
* An uninitialized stack value.
* An uninitialized stack value. Its {@link #tag() tag} is {@value #VT_UNINITIALIZED}.
*
* @since 22
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,21 +536,21 @@ private static Stream<ConstantDesc> convertVTIs(CodeAttribute lr, List<Verificat
switch (vti) {
case SimpleVerificationTypeInfo s -> {
switch (s) {
case ITEM_DOUBLE -> {
case DOUBLE -> {
ret.accept("double");
ret.accept("double2");
}
case ITEM_FLOAT ->
case FLOAT ->
ret.accept("float");
case ITEM_INTEGER ->
case INTEGER ->
ret.accept("int");
case ITEM_LONG -> {
case LONG -> {
ret.accept("long");
ret.accept("long2");
}
case ITEM_NULL -> ret.accept("null");
case ITEM_TOP -> ret.accept("?");
case ITEM_UNINITIALIZED_THIS -> ret.accept("THIS");
case NULL -> ret.accept("null");
case TOP -> ret.accept("?");
case UNINITIALIZED_THIS -> ret.accept("THIS");
}
}
case ObjectVerificationTypeInfo o ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public StackCounter(LabelContext labelContext,
for (var smfi : smta.entries()) {
int frameStack = smfi.stack().size();
for (var vti : smfi.stack()) {
if (vti == StackMapFrameInfo.SimpleVerificationTypeInfo.ITEM_LONG
|| vti == StackMapFrameInfo.SimpleVerificationTypeInfo.ITEM_DOUBLE) frameStack++;
if (vti == StackMapFrameInfo.SimpleVerificationTypeInfo.LONG
|| vti == StackMapFrameInfo.SimpleVerificationTypeInfo.DOUBLE) frameStack++;
}
if (maxStack < frameStack) maxStack = frameStack;
targets.add(new Target(labelContext.labelToBci(smfi.target()), frameStack));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static List<VerificationTypeInfo> initFrameLocals(ClassEntry thisClass, S
if (!isStatic) {
vtis = new VerificationTypeInfo[methodType.parameterCount() + 1];
if ("<init>".equals(methodName) && !ConstantDescs.CD_Object.equals(thisClass.asSymbol())) {
vtis[i++] = SimpleVerificationTypeInfo.ITEM_UNINITIALIZED_THIS;
vtis[i++] = SimpleVerificationTypeInfo.UNINITIALIZED_THIS;
} else {
vtis[i++] = new StackMapDecoder.ObjectVerificationTypeInfoImpl(thisClass);
}
Expand All @@ -84,10 +84,10 @@ public static List<VerificationTypeInfo> initFrameLocals(ClassEntry thisClass, S
for (int pi = 0; pi < methodType.parameterCount(); pi++) {
var arg = methodType.parameterType(pi);
vtis[i++] = switch (arg.descriptorString().charAt(0)) {
case 'I', 'S', 'C' ,'B', 'Z' -> SimpleVerificationTypeInfo.ITEM_INTEGER;
case 'J' -> SimpleVerificationTypeInfo.ITEM_LONG;
case 'F' -> SimpleVerificationTypeInfo.ITEM_FLOAT;
case 'D' -> SimpleVerificationTypeInfo.ITEM_DOUBLE;
case 'I', 'S', 'C' ,'B', 'Z' -> SimpleVerificationTypeInfo.INTEGER;
case 'J' -> SimpleVerificationTypeInfo.LONG;
case 'F' -> SimpleVerificationTypeInfo.FLOAT;
case 'D' -> SimpleVerificationTypeInfo.DOUBLE;
case 'V' -> throw new IllegalArgumentException("Illegal method argument type: " + arg);
default -> new StackMapDecoder.ObjectVerificationTypeInfoImpl(TemporaryConstantPool.INSTANCE.classEntry(arg));
};
Expand Down Expand Up @@ -163,7 +163,8 @@ private static boolean equals(List<VerificationTypeInfo> l1, List<VerificationTy
private static void writeTypeInfo(BufWriterImpl bw, VerificationTypeInfo vti) {
bw.writeU1(vti.tag());
switch (vti.tag()) {
case VT_TOP, VT_INTEGER, VT_FLOAT, VT_DOUBLE, VT_LONG, VT_NULL, VT_UNINITIALIZED_THIS ->
case VT_TOP, VT_INTEGER, VT_FLOAT, VT_DOUBLE, VT_LONG, VT_NULL,
VT_UNINITIALIZED_THIS ->
{}
case VT_OBJECT ->
bw.writeIndex(((ObjectVerificationTypeInfo)vti).className());
Expand Down Expand Up @@ -226,13 +227,13 @@ List<StackMapFrameInfo> entries() {
private VerificationTypeInfo readVerificationTypeInfo() {
int tag = classReader.readU1(p++);
return switch (tag) {
case VT_TOP -> SimpleVerificationTypeInfo.ITEM_TOP;
case VT_INTEGER -> SimpleVerificationTypeInfo.ITEM_INTEGER;
case VT_FLOAT -> SimpleVerificationTypeInfo.ITEM_FLOAT;
case VT_DOUBLE -> SimpleVerificationTypeInfo.ITEM_DOUBLE;
case VT_LONG -> SimpleVerificationTypeInfo.ITEM_LONG;
case VT_NULL -> SimpleVerificationTypeInfo.ITEM_NULL;
case VT_UNINITIALIZED_THIS -> SimpleVerificationTypeInfo.ITEM_UNINITIALIZED_THIS;
case VT_TOP -> SimpleVerificationTypeInfo.TOP;
case VT_INTEGER -> SimpleVerificationTypeInfo.INTEGER;
case VT_FLOAT -> SimpleVerificationTypeInfo.FLOAT;
case VT_DOUBLE -> SimpleVerificationTypeInfo.DOUBLE;
case VT_LONG -> SimpleVerificationTypeInfo.LONG;
case VT_NULL -> SimpleVerificationTypeInfo.NULL;
case VT_UNINITIALIZED_THIS -> SimpleVerificationTypeInfo.UNINITIALIZED_THIS;
case VT_OBJECT -> new ObjectVerificationTypeInfoImpl(classReader.entryByIndex(u2(), ClassEntry.class));
case VT_UNINITIALIZED -> new UninitializedVerificationTypeInfoImpl(ctx.getLabel(u2()));
default -> throw new IllegalArgumentException("Invalid verification type tag: " + tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,13 @@ void printMap(String name, List<VerificationTypeInfo> map, CodeAttribute lr) {

String mapTypeName(SimpleVerificationTypeInfo type) {
return switch (type) {
case ITEM_TOP -> "top";
case ITEM_INTEGER -> "int";
case ITEM_FLOAT -> "float";
case ITEM_LONG -> "long";
case ITEM_DOUBLE -> "double";
case ITEM_NULL -> "null";
case ITEM_UNINITIALIZED_THIS -> "this";
case TOP -> "top";
case INTEGER -> "int";
case FLOAT -> "float";
case LONG -> "long";
case DOUBLE -> "double";
case NULL -> "null";
case UNINITIALIZED_THIS -> "this";
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,25 @@ void print(StackMapFrameInfo.VerificationTypeInfo entry, boolean firstThis) {
switch (entry) {
case StackMapFrameInfo.SimpleVerificationTypeInfo s -> {
switch (s) {
case ITEM_TOP ->
case TOP ->
print("top");

case ITEM_INTEGER ->
case INTEGER ->
print("int");

case ITEM_FLOAT ->
case FLOAT ->
print("float");

case ITEM_LONG ->
case LONG ->
print("long");

case ITEM_DOUBLE ->
case DOUBLE ->
print("double");

case ITEM_NULL ->
case NULL ->
print("null");

case ITEM_UNINITIALIZED_THIS ->
case UNINITIALIZED_THIS ->
print("uninit_this");
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/jdk/jdk/classfile/StackMapsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ void testDeadCodeCountersWithCustomSMTA() {
StackMapTableAttribute.of(List.of(
StackMapFrameInfo.of(f2,
List.of(),
List.of(StackMapFrameInfo.SimpleVerificationTypeInfo.ITEM_LONG)),
List.of(StackMapFrameInfo.SimpleVerificationTypeInfo.LONG)),
StackMapFrameInfo.of(f3,
List.of(StackMapFrameInfo.SimpleVerificationTypeInfo.ITEM_LONG),
List.of(StackMapFrameInfo.SimpleVerificationTypeInfo.LONG),
List.of()))));
}
));
Expand Down

0 comments on commit 6d8accd

Please sign in to comment.