8339168: Optimize ClassFile Util slotSize

Reviewed-by: liach, redestad
This commit is contained in:
Shaojin Wen 2024-09-06 12:01:01 +00:00 committed by Chen Liang
parent a1eebbdf8a
commit febbd998ee
2 changed files with 20 additions and 16 deletions

View File

@ -98,6 +98,9 @@ public final class DirectMethodBuilder
@Override
public int parameterSlot(int paramNo) {
if (paramNo == 0) {
return ((flags & ClassFile.ACC_STATIC) != 0) ? 0 : 1;
}
if (parameterSlots == null)
parameterSlots = Util.parseParameterSlots(methodFlags(), methodTypeSymbol());
return parameterSlots[paramNo];

View File

@ -55,6 +55,10 @@ import java.lang.classfile.attribute.CodeAttribute;
import java.lang.classfile.components.ClassPrinter;
import java.util.function.Consumer;
import static jdk.internal.constant.PrimitiveClassDescImpl.CD_double;
import static jdk.internal.constant.PrimitiveClassDescImpl.CD_long;
import static jdk.internal.constant.PrimitiveClassDescImpl.CD_void;
/**
* Helper to create and manipulate type descriptors, where type descriptors are
* represented as JVM type descriptor strings and symbols are represented as
@ -105,9 +109,11 @@ public class Util {
}
public static int parameterSlots(MethodTypeDesc mDesc) {
int count = 0;
for (int i = 0; i < mDesc.parameterCount(); i++) {
count += slotSize(mDesc.parameterType(i));
int count = mDesc.parameterCount();
for (int i = count - 1; i >= 0; i--) {
if (isDoubleSlot(mDesc.parameterType(i))) {
count++;
}
}
return count;
}
@ -117,17 +123,13 @@ public class Util {
int count = ((flags & ACC_STATIC) != 0) ? 0 : 1;
for (int i = 0; i < result.length; i++) {
result[i] = count;
count += slotSize(mDesc.parameterType(i));
count += paramSlotSize(mDesc.parameterType(i));
}
return result;
}
public static int maxLocals(int flags, MethodTypeDesc mDesc) {
int count = ((flags & ACC_STATIC) != 0) ? 0 : 1;
for (int i = 0; i < mDesc.parameterCount(); i++) {
count += slotSize(mDesc.parameterType(i));
}
return count;
return parameterSlots(mDesc) + ((flags & ACC_STATIC) == 0 ? 1 : 0) ;
}
/**
@ -252,16 +254,15 @@ public class Util {
}
public static int slotSize(ClassDesc desc) {
return switch (desc.descriptorString().charAt(0)) {
case 'V' -> 0;
case 'D','J' -> 2;
default -> 1;
};
return desc == CD_void ? 0 : isDoubleSlot(desc) ? 2 : 1;
}
public static int paramSlotSize(ClassDesc desc) {
return isDoubleSlot(desc) ? 2 : 1;
}
public static boolean isDoubleSlot(ClassDesc desc) {
char ch = desc.descriptorString().charAt(0);
return ch == 'D' || ch == 'J';
return desc == CD_double || desc == CD_long;
}
public static void dumpMethod(SplitConstantPool cp,